@page "/Box/CheckAAA"
@using MasaBlazorApp3.Pojo.Config
@using MasaBlazorApp3.Report
@using Microsoft.Extensions.Options
@using Radzen.Blazor.Rendering
@using log4net;

<style>
    .my-popup {
    display: none;
    position: absolute;
    overflow: auto;
    /* height: 360px; */
    width: 900px;
    border: var(--rz-panel-border);
    background-color: var(--rz-panel-background-color);
    box-shadow: var(--rz-panel-shadow);
    border-radius: var(--rz-border-radius);
    }

    .rz-grid-table {
    position: relative;
    border-collapse: separate;
    border-spacing: 0;
    }
</style>

<RadzenStack Orientation="Orientation.Horizontal">
    @*   <div class="col-4 row justify-content-center align-items-center text-center" style="background: url('/images/box-16.jpg')  no-repeat; background-size: 100% 100%; width: 380px; height:650px">
        <div class="row justify-content-around align-items-center" style="margin-top: 220px; height: 430px;overflow:auto">
            @foreach (int i in DrawerNos)
            {
                <RadzenButton class="col-5" Style="margin-bottom:5px" Click="@(() => SelectDrawer(i))" Text="@i.ToString()" Disabled="@(status > 0)" Shade="Shade.Light" Variant="@(drawerNo != i ? Variant.Outlined : Variant.Flat)" />

            }
        </div>
    </div> *@
    @*     <div class="col-2 row justify-content-center align-items-center text-center">
        <div class="row justify-content-around align-items-center" style="height:600px;overflow:auto">
            @foreach (int i in DrawerNos)
            {
                <RadzenButton class="col-12" Style="margin-bottom:5px" Click="@(() => SelectDrawer(i))" Text="@i.ToString()" Disabled="@(status > 0)" Shade="Shade.Light" Variant="@(drawerNo != i ? Variant.Outlined : Variant.Flat)" />

            }
        </div>
    </div> *@
    <div class="col-12">
        <form onsubmit="@(() => {firstLod=0;grid.Reload();})">
            <RadzenFieldset Text="查询">
                @* <RadzenStack Orientation="Orientation.Horizontal" Gap="1rem"> *@
                <RadzenRow AlignItems="AlignItems.Center">
                    <RadzenColumn Size="6">
                        <RadzenLabel Text="麻醉医师" Component="NamesList" Style="width: 20%;" />
                        <RadzenDropDownDataGrid AllowVirtualization="true" Name="NamesList" TValue="Anaesthetist" Data="@NamesList" @bind-Value="NameInfo"
                        Style="width:100%; display: block;" AllowFilteringByAllStringColumns="true" TextProperty="Name">
                            <Columns>
                                <RadzenDropDownDataGridColumn Property="Name" Title="麻醉医师" Sortable="false" />
                            </Columns>
                        </RadzenDropDownDataGrid>
                    </RadzenColumn>

                    <RadzenColumn Size="6">
                        <RadzenLabel Text="核对药箱" Component="BoxList" />
                          @*  <RadzenDropDownDataGrid AllowVirtualization="true" Name="BoxColorList" TValue="Anaesthetist" Data="@BoxColorList" @bind-Value="BoxColor" Style="width: 100%;"
                        AllowFilteringByAllStringColumns="true" TextProperty="Name">
                            <Columns>
                                <RadzenDropDownDataGridColumn Property="Name" Title="药盒颜色" Sortable="false" />
                            </Columns>
                        </RadzenDropDownDataGrid> *@
                        <RadzenDropDownDataGrid AllowVirtualization="true" Name="BoxList" TValue="BoxModel" Data="@BoxList" @bind-Value="BoxNum" Style="width: 100%;"
                        AllowFilteringByAllStringColumns="true" TextProperty="药箱号">
                            <Template>

                                @((context as BoxModel).BoxName == 99 ? "急诊药盒" : (context as BoxModel).BoxName == 111 ? "恢复室药盒" : (context as BoxModel).BoxName + "-" + ((context as BoxModel).BoxNo == 1 ? "白" : "绿"))

                                @* @((context as BoxModel).BoxName + "-" + (context as BoxModel).BoxNo) *@

                            </Template>
                            <Columns>
                                <RadzenDropDownDataGridColumn Property="BoxName" Title="药箱号" Sortable="false" />
                            </Columns>
                        </RadzenDropDownDataGrid>
                    </RadzenColumn>
                </RadzenRow>
                <RadzenRow AlignItems="AlignItems.Center">
                    <RadzenColumn Size="6">

                        <RadzenLabel Text="处方号" Component="OrderNo" />
                        <RadzenTextBox @bind-Value="OrderNo" Style="width: 100%;" Name="OrderNo"></RadzenTextBox>

                    </RadzenColumn>
                    <RadzenColumn Size="6" Style="margin-top:0.5rem">
                        <RadzenLabel Text="处方时间" Component="OrderDate" />
                        <RadzenDatePicker DateFormat="yyyy-MM-dd" CurrentDateChanged="@OnCurrentDateChanged" AllowClear @bind-Value="OrderDate" Style="width: 100%;" Name="OrderDate" />
                    </RadzenColumn>
                </RadzenRow>
                <RadzenRow AlignItems="AlignItems.Center">
                    <RadzenColumn Size="6">

                        <RadzenLabel Text="患者姓名" Component="PatientName" />
                        <RadzenTextBox @bind-Value="PatientName" Style="width: 100%;" Name="PatientName"></RadzenTextBox>

                    </RadzenColumn>
                    <RadzenColumn Size="6" Style="margin-top:2px">
                        <RadzenButton Size="ButtonSize.Medium" ButtonType="ButtonType.Submit" IsBusy="isLoading" Icon="search" Text="查询" />
                        <RadzenButton Size="ButtonSize.Medium" Click="reloadGrid" IsBusy="isLoading" Icon="refresh" Text="重置" ButtonStyle="ButtonStyle.Warning" />
                        <RadzenButton Size="ButtonSize.Medium" Click="Confirm" ButtonType="ButtonType.Button" IsBusy="isLoading" Icon="check_circle" Text="确认" />
                        <RadzenButton Style="margin-top:2px" Icon="download" @ref=button Text="麻醉药品使用登记本导出" Variant="Variant.Outlined" Click="@(args => popup.ToggleAsync(button.Element))" />
                        <Popup @ref=popup Lazy=true class="my-popup">
                            <RadzenStack Orientation="Orientation.Vertical" Gap="1rem" class="rz-h-100 rz-p-4">
                                <RadzenFieldset Text="条件选择">
                                    <RadzenStack Orientation="Orientation.Horizontal" Gap="1rem">
                                        <RadzenRow AlignItems="AlignItems.Center">
                                            <RadzenColumn Size="6">
                                                <RadzenLabel Text="处方时间" Component="PortOrderDate" />
                                            </RadzenColumn>
                                            <RadzenColumn Size="6">
                                                <RadzenDatePicker DateFormat="yyyy-MM-dd" CurrentDateChanged="@OnCurrentPortDateChanged" @bind-Value="PortOrderDate" Style="width: 100%;" Name="PortOrderDate" />
                                            </RadzenColumn>
                                        </RadzenRow>

                                        <RadzenRow JustifyContent="JustifyContent.End" AlignItems="AlignItems.Center">
                                            <RadzenButton Icon="download" Text="导出" Variant="Variant.Outlined" Click="StockExport" />
                                        </RadzenRow>
                                    </RadzenStack>
                                </RadzenFieldset>
                            </RadzenStack>
                        </Popup>
                    </RadzenColumn>
                </RadzenRow>
                @* </RadzenStack> *@
            </RadzenFieldset>
            <RadzenStack Orientation="Orientation.Horizontal" Gap="1rem" Style="margin:0.5rem">
                @*   <RadzenLabel Text="核对药箱" Component="BoxList" Style="margin:0.5rem" />
                <RadzenDropDownDataGrid AllowVirtualization="true" Name="BoxList" TValue="BoxModel" Data="@BoxList" @bind-Value="BoxNum"
                                        AllowFilteringByAllStringColumns="true" TextProperty="药箱号">
                    <Template>
                        @((context as BoxModel).BoxName + "-" + (context as BoxModel).BoxNo)
                    </Template>
                    <Columns>
                        <RadzenDropDownDataGridColumn Property="BoxName" Title="药箱号" Sortable="false" />
                    </Columns>
                </RadzenDropDownDataGrid> *@
                @*  <RadzenButton Size="ButtonSize.Medium" Click="Confirm" ButtonType="ButtonType.Button" IsBusy="isLoading" Icon="check_circle" Text="确认" />
                <RadzenButton Icon="download" @ref=button Text="麻醉药品使用登记本导出" Variant="Variant.Outlined" Click="@(args => popup.ToggleAsync(button.Element))" />
                <Popup @ref=popup Lazy=true class="my-popup">
                    <RadzenStack Orientation="Orientation.Vertical" Gap="1rem" class="rz-h-100 rz-p-4">
                        <RadzenFieldset Text="条件选择">
                            <RadzenStack Orientation="Orientation.Horizontal" Gap="1rem">
                                <RadzenRow AlignItems="AlignItems.Center">
                                    <RadzenColumn Size="6">
                                        <RadzenLabel Text="处方时间" Component="PortOrderDate" />
                                    </RadzenColumn>
                                    <RadzenColumn Size="6">
                                        <RadzenDatePicker DateFormat="yyyy-MM-dd" CurrentDateChanged="@OnCurrentPortDateChanged" @bind-Value="PortOrderDate" Style="width: 100%;" Name="PortOrderDate" />
                                    </RadzenColumn>
                                </RadzenRow>

                                <RadzenRow JustifyContent="JustifyContent.End" AlignItems="AlignItems.Center">
                                    <RadzenButton Icon="download" Text="导出" Variant="Variant.Outlined" Click="StockExport" />
                                </RadzenRow>
                            </RadzenStack>
                        </RadzenFieldset>
                    </RadzenStack>
                </Popup> *@
            </RadzenStack>
        </form>
        <div Style="width:936px;height:50vh;overflow:auto">
            <RadzenDataGrid @ref="grid" AllowRowSelectOnRowClick="@allowRowSelectOnRowClick" AllowFiltering="true" LoadData="@LoadData" Style="width:955px;overflow:auto" Groupable="true" 
            FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
            Data="@orderInfos" IsLoading="@isLoading" Count="@count" EmptyText="无数据"
            SelectionMode="DataGridSelectionMode.Multiple" @bind-Value=@selectedOrderInfos
            CellClick="@((DataGridCellMouseEventArgs<OrderInfo> args) => OnCellClick(args))"
            AllowPaging="false">
                <Columns>
                    <RadzenDataGridColumn Sortable="false" Filterable="false" Width="2rem">
                        @*  <HeaderTemplate>
                            <RadzenCheckBox TabIndex="-1" TriState="false" TValue="bool?" InputAttributes="@(new Dictionary<string, object>() { { "aria-label", "Select all items" } })"
                            Value="@(selectedOrderInfos == null || selectedOrderInfos?.Any() != true ? false : !orderInfos.All(i => selectedOrderInfos.Contains(i)) ? null : orderInfos.Any(i => selectedOrderInfos.Contains(i)))"
                            Change="@(args => OnCheckSeleced(args))" />
                        </HeaderTemplate> *@
                        <Template Context="data">
                            <RadzenCheckBox TabIndex="-1" TriState="false" Value="@data.ItemIsChecked" InputAttributes="@(new Dictionary<string, object>() { { "aria-label", "Select item" } })"
                            TValue="bool" Change="@(args => { if (!allowRowSelectOnRowClick) { grid.SelectRow(data); } })" />
                        </Template>
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Property="anaesthetistName" Title="麻醉医师" Sortable="false" Filterable="false" Width="50px" />
                    <RadzenDataGridColumn Property="PatientName" Title="姓名" Sortable="false" Filterable="false" Width="50px" />
                    <RadzenDataGridColumn Property="Sex" Title="性别" Sortable="false" Filterable="false" Width="30px" />
                    <RadzenDataGridColumn Property="OrderNo" Title="单号" Sortable="false" Filterable="false" Width="70px" />
                    <RadzenDataGridColumn Property="ChargeDate" Title="处方时间" Sortable="false" Filterable="false" Width="80px" />
                    <RadzenDataGridColumn Property="DetailInfo.Drug.DrugName" Title="药品名称" FormatString="{0:d}" Sortable="false" Filterable="false" Width="80px" />
                    @* <Template Context="DetailInfo">
                       @for (int i = 0; i < DetailList.DetailList.Count; i++)
                        {
                            OrderDetail orderDetail = DetailList.DetailList[i]; *@
                    @*     <RadzenText TextStyle="TextStyle.Subtitle2" class="rz-mb-0">@DetailInfo.Drug.DrugName</RadzenText>
                    }
                    </Template> 
                </RadzenDataGridColumn>*@
                    @*  <RadzenDataGridColumn Property="Detail.SetManuNo" Title="药品批次" Sortable="false" Filterable="false" Width="8rem">
                    <Template Context="DetailList">
                        @for (int i = 0; i < DetailList.DetailList.Count; i++)
                        {
                            OrderDetail orderDetail = DetailList.DetailList[i];
                            <RadzenText TextStyle="TextStyle.Subtitle2" class="rz-mb-0">@orderDetail.SetManuNo</RadzenText>
                        }
                    </Template>
                </RadzenDataGridColumn> *@
                    <RadzenDataGridColumn Title="批次" Property="DetailInfo.SetManuNo" Filterable="false" Width="100px">
                        @*            <Template Context="DetailInfo">
                        <RadzenText TextStyle="TextStyle.Subtitle2" class="mb-0">@DetailInfo.DetailInfo.SetManuNo</RadzenText>

                        @if (DetailInfo.DetailInfo.SetManuNo != null )
                        {
                            <RadzenText TextStyle="TextStyle.Caption">
                                @DetailInfo.DetailInfo.SetManuNo
                            </RadzenText>
                        }
                    </Template> *@
                        <EditTemplate Context="DetailInfo">
                            <RadzenDropDown TValue="DrugManuNo" Name="ManuNo" @bind-Value="DetailInfo.DetailInfo.drugManuNo" Data="DetailInfo.DetailInfo.Drug.Manus" Style="width:100%; display: block;">
                                <Template>
                                    <RadzenText TextStyle="TextStyle.Subtitle2" class="mb-0">@((context as DrugManuNo)?.ManuNo)</RadzenText>
                                    @if ((context as DrugManuNo).EffDate != null && (context as DrugManuNo).EffDate.ToString().Length > 10)
                                    {

                                        <RadzenText TextStyle="TextStyle.Caption">@((context as DrugManuNo).EffDate.ToString().Substring(0, 10))</RadzenText>
                                    }
                                    else
                                    {

                                        <RadzenText TextStyle="TextStyle.Caption">@((context as DrugManuNo)?.EffDate)</RadzenText>
                                    }
                                </Template>
                                <ValueTemplate>
                                    <RadzenStack Orientation="Orientation.Horizontal">
                                        <RadzenText TextStyle="TextStyle.Subtitle2" class="mb-0">@((context as DrugManuNo)?.ManuNo)</RadzenText>
                                        @if ((context as DrugManuNo).EffDate != null && (context as DrugManuNo).EffDate.ToString().Length > 10)
                                        {

                                            <RadzenText TextStyle="TextStyle.Caption">@((context as DrugManuNo).EffDate.ToString().Substring(0, 10))</RadzenText>
                                        }
                                        else
                                        {

                                            <RadzenText TextStyle="TextStyle.Caption">@((context as DrugManuNo)?.EffDate)</RadzenText>
                                        }
                                    </RadzenStack>
                                </ValueTemplate>
                            </RadzenDropDown>
                            <RadzenRequiredValidator Text="请选择批次" Component="ManuNo" Popup="true" />
                        </EditTemplate>
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Property="DetailInfo.Quantity" Title="数量" Filterable="false" Width="50px">
                        <EditTemplate Context="DetailInfo">
                            <RadzenNumeric Min="0" Style="display: block" Name="Quantity" @bind-Value=@DetailInfo.DetailInfo.Quantity />
                            <RadzenNumericRangeValidator Style="position: absolute;z-index: 9999;" Min="0" Text="请填写正确的添加数量" Component="Quantity" Popup="true" />
                        </EditTemplate>
                    </RadzenDataGridColumn>
                    <RadzenDataGridColumn Property="DetailInfo.TotalQuantity" Title="合计" Filterable="false" Width="50px" />
                </Columns>
            </RadzenDataGrid>
        </div>
    </div>
</RadzenStack>
@code {

    private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrder));
    @inject IOrderInfoDao orderInfoDao;
    @inject DialogService dialogService;
    @inject Microsoft.Extensions.Options.IOptions<Pojo.Config.SettingConfig> setting;
    @inject NotificationService _message;
    @inject IReportDataDao reportDataDao;
    @inject IOptions<SettingConfig> setting;
    bool allowRowSelectOnRowClick = true;
    IEnumerable<OrderInfo> orderInfos;
    IList<OrderInfo> selectedOrderInfos;
    RadzenDataGrid<OrderInfo> grid;
    //麻醉师集合
    List<Anaesthetist> NamesList = new List<Anaesthetist>();
    Anaesthetist NameInfo;
    Anaesthetist BoxColor;
    //药盒集合
    List<BoxModel> BoxList = new List<BoxModel>();
    //药盒颜色集合
    List<Anaesthetist> BoxColorList = new List<Anaesthetist>();
    BoxModel BoxNum;
    bool isLoading;
    int count;
    int[] DrawerNos = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    int status = 0;
    string OrderNo;
    string PatientName;
    DateTime? OrderDate = null;
    DateTime PortOrderDate = DateTime.Now;
    Popup popup;
    RadzenButton button;
    //第一次加载不执行LoadData方法
    int firstLod = 1;
    void OnCheckSeleced(object dete)
    {
        if (orderInfos != null)
        {
            orderInfos.ToList().ForEach(it => it.ItemIsChecked = true);
        }
    }
    void OnCurrentDateChanged(DateTime args)
    {
        OrderDate = new DateTime(args.Year, args.Month, args.Day);
    }
    void OnCurrentPortDateChanged(DateTime args)
    {
        PortOrderDate = new DateTime(args.Year, args.Month, args.Day);
    }
    // async Task OnColorChange(object value)
    // {
    //     Anaesthetist v = value as Anaesthetist;
    //     if (v.Id != BoxColor.Id)
    //     {
    //         BoxList = await orderInfoDao.GetOperationNum(BoxColor.Id);// await orderInfoDao.GetDrawerNumByOperationNum(setting.Value.boxMachineId, roomNameList); //roomNameList.Select(it => new BoxModel { BoxName = it, BoxNo = Convert.ToInt32(it.Substring(it.Length - 2, 2)) }).ToList();

    //         BoxNum = BoxList.FirstOrDefault();
    //     }
    // }
    //重置
    async Task reloadGrid()
    {
        OrderNo = "";
        OrderDate = DateTime.MinValue;
        firstLod = 1;
        await grid.Reload();
    }
    void OnCellClick(DataGridCellMouseEventArgs<OrderInfo> args)
    {
        if (args.Data.DetailInfo.SetManuNo != null)
        {
            args.Data.DetailInfo.drugManuNo = args.Data.DetailInfo.Drug.Manus.Where(m => m.ManuNo == args.Data.DetailInfo.SetManuNo).FirstOrDefault();
        }
        if (args.Data.DetailInfo.drugManuNo == null)
        {
            args.Data.DetailInfo.drugManuNo = args.Data.DetailInfo.Drug.Manus.FirstOrDefault();
        }
        args.Data.ItemIsChecked = !args.Data.ItemIsChecked;
        grid.EditRow(args.Data);
    }
    //确认
    async Task Confirm()
    {
        if (selectedOrderInfos == null)
        {
            _message.Notify(
                   new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请选择处方", Duration = 4000 }
               );
            return;
        }
        if (BoxNum == null)
        {
            _message.Notify(
                  new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请选择药箱", Duration = 4000 }
              );
            return;
        }
        if (selectedOrderInfos.Any(it => it.DetailInfo.drugManuNo == null && (string.IsNullOrEmpty(it.DetailInfo.SetManuNo))))
        {
            _message.Notify(
                         new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请选择批次信息", Duration = 4000 }
                     );
            return;
        }
        selectedOrderInfos.Where(oi => oi.DetailInfo.drugManuNo != null && !string.IsNullOrEmpty(oi.DetailInfo.drugManuNo.ManuNo)).ToList().ForEach(oi => oi.DetailInfo.SetManuNo = oi.DetailInfo.drugManuNo.ManuNo);
        selectedOrderInfos.Where(oi => !string.IsNullOrEmpty(oi.DetailInfo.SetManuNo)).ToList().ForEach(oi => oi.DetailInfo.drugManuNo = new() { ManuNo = oi.DetailInfo.SetManuNo });
        //弹出药品合计信息，确认无误后进行核对，取消则不核对
        //弹出确认提示框
        // var b = await dialogService.OpenAsync<CheckOrderConfirmDialog>(
        //    $"核对确认",
        //  new Dictionary<string, object>() { { "selectedOrderInfos", selectedOrderInfos } },
        //  new DialogOptions() { Width = "80vw", Resizable = true, Draggable = true, ShowClose = false });
        // if (b)
        // {
        bool bResult = await orderInfoDao.CheckOrderInfo(selectedOrderInfos, BoxNum);
        if (bResult)
        {
            _message.Notify(
                            new NotificationMessage { Severity = NotificationSeverity.Success, Summary = "提示", Detail = $"处方已核对完成", Duration = 4000 }
                        );
            //await GetInitialDate();
            await grid.Reload();
        }
        else
        {
            _message.Notify(
                          new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"处方已核对失败", Duration = 4000 }
                   );
        }
        // }
    }
    PageData<OrderInfo> result;
    protected override async Task OnInitializedAsync()
    {
        BoxColorList = setting.Value.boxColor.Split(',').Select(it => new Anaesthetist { Name = it,Id=it=="白"?1:2 }).ToList();
        BoxColor = BoxColorList.FirstOrDefault();
        NamesList = setting.Value.anaesthetist_name.Split(',').Select(it => new Anaesthetist { Name = it }).ToList();
        NameInfo = NamesList.FirstOrDefault();
        BoxList = await orderInfoDao.GetOperationNum(0);// await orderInfoDao.GetDrawerNumByOperationNum(setting.Value.boxMachineId, roomNameList); //roomNameList.Select(it => new BoxModel { BoxName = it, BoxNo = Convert.ToInt32(it.Substring(it.Length - 2, 2)) }).ToList();

        BoxNum = BoxList.FirstOrDefault();

        //await GetInitialDate();
        await base.OnInitializedAsync();
    }
    async Task LoadData(LoadDataArgs args)
    {
        if (firstLod == 1)
        {

            return;
        }
        // BoxList=BoxList.Where(bl => bl.BoxNo == BoxColor.Id).ToList();
        // BoxNum = BoxList.FirstOrDefault();
        string? anaesthetistName = NameInfo.Name == "未选择" ? null : NameInfo.Name;
        string? roomName = BoxNum == null ? "" : setting.Value.roomName + BoxNum.BoxName.ToString().PadLeft(2, '0');
        result = await orderInfoDao.GetAllOrderInfo(anaesthetistName, roomName, PatientName, OrderNo, OrderDate, args.Top, args.Skip);
        isLoading = true;
        orderInfos = result.Desserts;
        count = result.TotalDesserts;
        // if (result != null)
        // {
        //     isLoading = true;
        //     orderInfos = result.Desserts;
        //     // Update the count
        //     count = result.TotalDesserts;
        //     logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}");
        //     // Update the Data property
        //     if (Name != null)
        //     {
        //         orderInfos = orderInfos.Where(it => it.anaesthetistName == Name.Name);
        //         logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}，Name{Name.Name}");
        //         count = orderInfos.Count();
        //     }
        //     if (OrderDate != null && OrderDate != DateTime.MinValue)
        //     {
        //         orderInfos = orderInfos.Where(it => it.ChargeDate.Date >= OrderDate.Value.Date);

        //         logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}");
        //         // Update the count
        //         count = orderInfos.Count();
        //     }
        //     if (!string.IsNullOrEmpty(OrderNo))
        //     {
        //         orderInfos = orderInfos.Where(it => it.OrderNo.Contains(OrderNo));

        //         logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}-OrderNo{OrderNo}");
        //         // Update the count
        //         count = orderInfos.Count();
        //     }
        //     if (Name != null && OrderDate != null && OrderDate != DateTime.MinValue && !string.IsNullOrEmpty(OrderNo))
        //     {
        //         orderInfos = orderInfos.Where(it => it.anaesthetistName == Name.Name && it.ChargeDate.Date == OrderDate.Value.Date && it.OrderNo.Contains(OrderNo));

        //         logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}");
        //         // Update the count
        //         count = orderInfos.Count();
        //     }
        //     if (BoxNum != null&&BoxNum.BoxName!=99&&BoxNum.BoxName!=111)
        //     {
        //         string roomName = setting.Value.roomName + BoxNum.BoxName.ToString().PadLeft(2, '0');

        //         orderInfos = orderInfos.Where(it => it.RoomName == roomName);

        //         logger.Info($"LoadData:{DateTime.Now},{orderInfos.Count()}；roomName{roomName}");
        //         count = orderInfos.Count();
        //     }

        //     logger.Info($"LoadData结束:{DateTime.Now},{orderInfos.Count()}");

        //     orderInfos = orderInfos.Skip(args.Skip.Value).Take(args.Top.Value).ToList();

        //     logger.Info($"LoadData结束:{DateTime.Now},{orderInfos.Count()} -{args.Skip.Value}-{args.Top.Value}");

        //     await InvokeAsync(StateHasChanged);
        //     //查找该麻醉师对应的手术室
        //     //List<string> roomNameList = orderInfos.Select(it => it.RoomName).Distinct().ToList();
        //     // List<int> roomNameList = orderInfos.Select(it => Convert.ToInt32(it.RoomName.Substring(6, it.RoomName.Length - 6))).Distinct().ToList();
        //     // BoxList = await orderInfoDao.GetDrawerNumByOperationNum(setting.Value.boxMachineId, roomNameList); //roomNameList.Select(it => new BoxModel { BoxName = it, BoxNo = Convert.ToInt32(it.Substring(it.Length - 2, 2)) }).ToList();

        //     // BoxNum = BoxList.FirstOrDefault();

        isLoading = false;

        // }
    }
    //麻醉药品使用登记本导出
    async Task StockExport()
    {
        if (PortOrderDate == DateTime.MinValue)
        {
            _message.Notify(
                           new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请选择处方时间再导出", Duration = 4000 }
                    );
            return;
        }
        List<ReportUsageDateInfo> pageData = await reportDataDao.GetOrderInfoData(PortOrderDate);
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("PortOrderDate", pageData);
        GridReportUtil.PrintReport("Usage_Temp.grf", parameters);
    }
    // protected override async Task OnInitializedAsync()
    // {
    //     await base.OnInitializedAsync();

    //     // orderInfos = dbContext.Employees;

    //     var result = await orderInfoDao.GetAllOrderInfo(OrderNo, OrderDate, args.Top, args.Skip);
    //     // Update the Data property
    //     orderInfos = result.Desserts;
    //     // Update the count
    //     count = result.TotalDesserts;

    //     isLoading = false;
    // }
}