@page "/return/record2"


<div class="container-fluid">
    <div class="row">
        <div class="col-12 mb-4">
            
            <form onsubmit="@(() => grid.Reload())">
                <RadzenFieldset Text="查询">
                    <RadzenStack Orientation="Orientation.Horizontal" Gap="1rem">
                        <RadzenRow AlignItems="AlignItems.Center">
                            <RadzenColumn Size="4">
                                <RadzenLabel Text="开始时间" Component="Start" />
                            </RadzenColumn>
                            <RadzenColumn Size="8">
                                <RadzenDatePicker DateFormat="yyyy-MM-dd"  @bind-Value="start" Style="width: 100%;" Name="Start" />
                            </RadzenColumn>
                        </RadzenRow>
                        <RadzenRow AlignItems="AlignItems.Center">
                            <RadzenColumn Size="4">
                                <RadzenLabel Text="结束时间" Component="End" />
                            </RadzenColumn>
                            <RadzenColumn Size="8">
                                <RadzenDatePicker DateFormat="yyyy-MM-dd"  @bind-Value="end" Style="width: 100%;" Name="End" />
                            </RadzenColumn>
                        </RadzenRow>
                    
                        <RadzenRow AlignItems="AlignItems.Center">
                            <RadzenColumn Size="12">
                                <RadzenButton Size="ButtonSize.Large" ButtonType="ButtonType.Submit" IsBusy="isLoading" Icon="search" Text="查询" />
                                <RadzenButton Size="ButtonSize.Large" Click="reloadGrid" IsBusy="isLoading" Icon="refresh" Text="重置" ButtonStyle="ButtonStyle.Warning" />
                            </RadzenColumn>
                        </RadzenRow>
                    </RadzenStack>
                </RadzenFieldset>
            </form>
        </div>
        <div class="col-12 mb-4">

                <RadzenDataGrid @ref="grid"
                    LoadData="@LoadData"
                    IsLoading="@isLoading"
                    Count="@count"
                    EmptyText="无数据"
                    Data="@_forecasts"
                    AllowColumnResize="true" AllowAlternatingRows="false"
                    SelectionMode="DataGridSelectionMode.Single"
                    AllowPaging="true" PageSize="10" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true" PagingSummaryFormat="{0}/{1} 共{2}条数据">
                    <Columns>
                        <RadzenDataGridColumn Frozen="true" Title="操作人" Property="OperatorUser.NickName"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Width="170px" Title="操作时间" Property="OperationTime"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Width="200px" Title="药品名称" Property="Drug.DrugName"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Title="规格" Property="Drug.DrugSpec"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Title="数量" Property="Quantity"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Title="批次" Property="ManuNo"></RadzenDataGridColumn>
                        <RadzenDataGridColumn Title="效期" Property="EffDate">
                            <Template Context="mr">
                                @mr.EffDate?.ToString("yyyy-MM-dd")
                            </Template>
                        </RadzenDataGridColumn>
                    </Columns>
                </RadzenDataGrid>
        </div>
    </div>
</div>

@code {
    @inject IMachineRecordDao machineRecordDao;
    @inject DialogService dialogService;
    RadzenDataGrid<MachineRecord> grid;
    bool isLoading;
    int count;
    private IEnumerable<MachineRecord>? _forecasts;
    DateTime start;
    DateTime end;

    async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;

        var result = await machineRecordDao.GetMachineRecordAsync(start, end, 0, "", 32, args.Top, args.Skip);
        // Update the Data property
        _forecasts = result.Desserts;
        // Update the count
        count = result.TotalDesserts;

        isLoading = false;
    }

    async Task reloadGrid()
    {
        start = DateTime.MinValue;
        end = DateTime.MinValue;
        await grid.Reload();
    }

    



}
