@page "/Box/BoxBindings"
@* 选择套餐 *@
@* *@
@code { @inject IChannelListDao channelListDao; @inject IDrugInfoDao drugInfoDao; @inject DialogService dialogService; @inject NotificationService _message @inject IPlanDao planDao; RadzenDataList grid; bool isLoading; int count; private IEnumerable? _forecasts; List drugInfos; List drugManuNos; DrugInfo drugInfo; DrugManuNo drugManuNo; List plans; int firstFlag = 0; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var resultPlan = await planDao.GetAllPlanInfo(); plans = resultPlan.Desserts.Where(p => p._PlanDetails.Count > 0).ToList(); firstFlag = 0; } async Task LoadData(LoadDataArgs args) { isLoading = true; var result = await channelListDao.GetAllChannelListWithPlan(args.Top, args.Skip); // Update the Data property _forecasts = result.Desserts; // Update the count count = result.TotalDesserts; isLoading = false; plans = result.Other; } async Task reloadGrid() { await grid.Reload(); } // 默认选中的项 private Plan selectedPlan = new(); // 处理选择变更(可选) private void OnPlanSelected(Plan plan) { selectedPlan = plan; } //绑定 async Task EditChannel() { List bindList = _forecasts.Where(b => b.IsChecked).ToList(); if (bindList == null || bindList.Count <= 0) { _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请先选择药箱号再点击按钮", Duration = 4000 } ); return; } if (!string.IsNullOrEmpty(bindList[0].DrugId)) { //之前有绑定,在进行解绑 foreach (var item in bindList) { var b = await channelListDao.UnBindBox(item); if (b) { _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Success, Summary = "提示", Detail = $"解除绑定成功", Duration = 4000 } ); } await grid.Reload(); } } else {// 否则是进行解绑 if (selectedPlan != null && selectedPlan.Id > 0) { foreach (var item in bindList) { var b = await channelListDao.BindBox(item, selectedPlan); if (b) { _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Success, Summary = "提示", Detail = $"绑定成功", Duration = 4000 } ); } } await grid.Reload(); } else { _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"请选择套餐", Duration = 4000 } ); } } } async Task CardClick(ChannelList list) { if (firstFlag == 0 && !(list.BoxDisabled)) { firstFlag = 1; if (!string.IsNullOrEmpty(list.DrugId)) { list.IsChecked = !list.IsChecked; //已绑药品需要解绑,未绑定的不可选 if (list.IsChecked) { _forecasts.Where(it => it.DrugId != list.DrugId || it.TotalQuantity > 0).ToList().ForEach(it => it.BoxDisabled = true); selectedPlan = await planDao.GetPlanById(Convert.ToInt32(list.DrugId)); } else { _forecasts.Where(it => it.TotalQuantity <= 0).ToList().ForEach(it => it.BoxDisabled = false); firstFlag = 0; } } else { list.IsChecked = !list.IsChecked; //未绑定药品则已绑定的不可选 if (list.IsChecked) { _forecasts.Where(it => !string.IsNullOrEmpty(it.DrugId) || it.TotalQuantity > 0).ToList().ForEach(it => it.BoxDisabled = true); } else { _forecasts.ToList().Where(it => it.TotalQuantity <= 0).ToList().ForEach(it => it.BoxDisabled = false); firstFlag = 0; } } } else { if (!list.BoxDisabled) { list.IsChecked = !list.IsChecked; } //isChecked==false 1)是否全部是false,是则将所有isChecked==true,不是则不做改变 if (!_forecasts.Any(b => b.IsChecked == true)) { _forecasts.Where(it => it.TotalQuantity <= 0).ToList().ForEach(it => it.BoxDisabled = false); firstFlag = 0; } } await InvokeAsync(StateHasChanged); } }