/// <summary> /// 提交单据 /// </summary> /// <param name="data"></param> /// <param name="billId"></param> /// <returns></returns> public async Task <APIResult <ExchangeBillUpdateModel> > CreateOrUpdateAsync(ExchangeBillUpdateModel data, int billId = 0, CancellationToken calToken = default) { try { int storeId = Settings.StoreId; int userId = Settings.UserId; var api = RefitServiceBuilder.Build <IExchangeBillApi>(URL); var results = await _makeRequest.Start(api.CreateOrUpdateAsync(data, storeId, userId, billId, calToken), calToken); return(results); } catch (Exception e) { e.HandleException(); return(null); } }
public ExchangeBillPageViewModel(INavigationService navigationService, IExchangeBillService exchangeBillService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IMicrophoneService microphoneService, ISaleBillService saleBillService, //IMapper mapper, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "换货单"; _saleBillService = saleBillService; _exchangeBillService = exchangeBillService; _microphoneService = microphoneService; //_mapper = mapper; InitBill(); #region //配送日期指定 var weekDays = new List <WeekDay>(); var startTime = DateTime.Now; var endTime = DateTime.Now.AddDays(7); while (endTime.Subtract(startTime).Days > 0) { var wd = new WeekDay { Wname = $"{startTime:MM-dd} - {GlobalSettings.GetWeek(startTime.DayOfWeek.ToString())}", Date = startTime, AMTimeRange = $"09:00-12:00", PMTimeRange = $"15:00-21:00", SelectedCommand = ReactiveCommand.Create <WeekDay>(r => { this.WeekDays.ForEach(s => { s.Selected = false; }); r.Selected = !r.Selected; this.DeliverDate = r; this.AMTimeRange = r.AMTimeRange; this.PMTimeRange = r.PMTimeRange; }) }; weekDays.Add(wd); startTime = startTime.AddDays(1); } var defaultWd = weekDays.FirstOrDefault(); if (defaultWd != null) { defaultWd.Selected = true; this.AMTimeRange = defaultWd.AMTimeRange; this.PMTimeRange = defaultWd.PMTimeRange; } this.WeekDays = new ObservableCollection <WeekDay>(weekDays); #endregion //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_TerminalId = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定"); var valid_BusinessUserId = this.ValidationRule(x => x.Bill.DeliveryUserId, _isZero, "配送员未指定"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (this.Bill.AuditedStatus && !this.ReferencePage.Equals("UnDeliveryPage")) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert(valid_TerminalId.Message[0]); ((ICommand)CustomSelected)?.Execute(null); return; } if (!valid_WareHouseId.IsValid) { _dialogService.ShortAlert(valid_WareHouseId.Message[0]); ((ICommand)StockSelected)?.Execute(null); return; } if (!valid_BusinessUserId.IsValid) { _dialogService.ShortAlert(valid_BusinessUserId.Message[0]); ((ICommand)DeliverSelected)?.Execute(null); return; } //转向商品选择 await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("TerminalId", Bill.TerminalId), ("Terminaler", this.Terminal), ("SerchKey", Filter.SerchKey)); }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = item.UnitId; product.Quantity = item.Quantity; product.Price = item.Price; product.Amount = item.Amount; product.Remark = item.Remark; product.Subtotal = item.Subtotal; product.UnitName = item.UnitName; if (item.BigUnitId > 0) { product.bigOption.Name = item.UnitName; product.BigPriceUnit.Quantity = item.Quantity; product.BigPriceUnit.UnitId = item.BigUnitId; product.BigPriceUnit.Amount = item.Amount; product.BigPriceUnit.Remark = item.Remark; } if (item.SmallUnitId > 0) { product.bigOption.Name = item.UnitName; product.SmallPriceUnit.Quantity = item.Quantity; product.SmallPriceUnit.UnitId = item.SmallUnitId; product.SmallPriceUnit.Amount = item.Amount; product.SmallPriceUnit.Remark = item.Remark; } await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse)); } } this.Selecter = null; }) .DisposeWith(DeactivateWith); //提交表单 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.ExchangeBillsSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus || DispatchItem != null) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } //结算方式 Bill.PayTypeId = 0; Bill.PayTypeName = ""; if (Bill.BusinessUserId == 0) { Bill.BusinessUserId = Settings.UserId; } var postMData = new ExchangeBillUpdateModel() { BillNumber = this.Bill.BillNumber, //客户 TerminalId = Bill.TerminalId, //业务员 BusinessUserId = Bill.BusinessUserId, //送货员 DeliveryUserId = Bill.DeliveryUserId, //仓库 WareHouseId = Bill.WareHouseId, //交易日期 TransactionDate = DateTime.Now, //默认售价方式 DefaultAmountId = Settings.DefaultPricePlan, //备注 Remark = Bill.Remark, //优惠金额 PreferentialAmount = 0, //优惠后金额 PreferentialEndAmount = 0, //欠款金额 OweCash = 0, //商品项目 Items = Bill.Items, //收款账户 //预收款 AdvanceAmount = 0, //预收款余额 AdvanceAmountBalance = 0, //配送时间 DeliverDate = this.DeliverDate?.Date ?? DateTime.Now, AMTimeRange = this.DeliverDate?.AMTimeRange, PMTimeRange = this.DeliverDate?.PMTimeRange }; return await SubmitAsync(postMData, Bill.Id, _exchangeBillService.CreateOrUpdateAsync, async(result) => { BillId = result.Code; //清空单据 Bill = new ExchangeBillModel(); if (IsVisit) //拜访时开单 { //转向拜访界面 await this.NavigateAsync("VisitStorePage", ("BillTypeId", BillTypeEnum.ExchangeBill), ("BillId", BillId), ("Amount", Bill.SumAmount)); } }, !IsVisit, token: new System.Threading.CancellationToken()); })); },