public ReturnOrderBillPageViewModel(INavigationService navigationService, IReturnReservationBillService returnReservationBillService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IMicrophoneService microphoneService, IDialogService dialogService) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "退货订单"; _returnReservationBillService = returnReservationBillService; //_saleBillService = saleBillService; _microphoneService = microphoneService; InitBill(); //验证 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, "请添加商品项目"); var valid_SelectesCount = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式"); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var whs = await _wareHousesService.GetWareHousesAsync(this.BillType, force: true); if (whs != null && whs.FirstOrDefault() != null) { var wh = whs.FirstOrDefault(); if (Bill.WareHouseId == 0) { WareHouse = wh; Bill.WareHouseId = wh.Id; } if (string.IsNullOrEmpty(Bill.WareHouseName)) { Bill.WareHouseName = wh.Name; } if (Bill.Id == 0 && Bill.DeliveryUserId == 0) { Bill.DeliveryUserId = Settings.UserId; Bill.DeliveryUserName = Settings.UserRealName; } } InitPayment(); })); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert(valid_TerminalId.Message[0]); ((ICommand)CustomSelected)?.Execute(null); return; } if (!valid_WareHouseId.IsValid || WareHouse == null) { _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 && !this.ReferencePage.Equals("UnDeliveryPage")) { _dialogService.ShortAlert("已审核单据不能操作"); return; } //已提交未审核的可以编辑 if (this.Bill.IsSubmitBill && !this.Bill.AuditedStatus) { _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.ReturnOrderSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } if (IsNeedShowPrompt) { var ok = await _dialogService.ShowConfirmAsync("是否保存并提交吗?", "", "确定", "取消"); if (!ok) { return Unit.Default; } } IsNeedShowPrompt = true; if (Bill.BusinessUserId == 0) { Bill.BusinessUserId = Settings.UserId; } var postMData = new ReturnReservationBillUpdateModel() { BillNumber = this.Bill.BillNumber, //客户 TerminalId = Bill.TerminalId, //业务员 BusinessUserId = Bill.BusinessUserId, //仓库 WareHouseId = Bill.WareHouseId, //交易日期 TransactionDate = DateTime.Now, //默认售价方式 DefaultAmountId = Settings.DefaultPricePlan, //备注 Remark = Bill.Remark, //优惠金额 PreferentialAmount = Bill.PreferentialAmount, //优惠后金额 PreferentialEndAmount = Bill.SumAmount - Bill.PreferentialAmount, //欠款金额 OweCash = Bill.OweCash, //商品项目 Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(), //收款账户 Accounting = PaymentMethods.Selectes.Select(a => { return new AccountMaping() { AccountingOptionId = a.AccountingOptionId, CollectionAmount = a.CollectionAmount, Name = a.Name, BillId = 0, }; }).ToList() }; return await SubmitAsync(postMData, Bill.Id, _returnReservationBillService.CreateOrUpdateAsync, async(result) => { if (IsNeedPrint) { Bill.BillType = BillTypeEnum.SaleBill; await SelectPrint((ReturnReservationBillModel)Bill.Clone()); } IsNeedPrint = false; BillId = result.Code; ClearBillCache(); PaymentMethods.Selectes.Clear(); InitPayment(); if (IsVisit) { //转向拜访界面 //await this.NavigateAsync("VisitStorePage", ("BillTypeId",BillTypeEnum.ReturnReservationBill),("BillId", BillId),("Amount", Bill.SumAmount)); await _navigationService.GoBackAsync(("BillTypeId", BillTypeEnum.ReturnReservationBill), ("BillId", BillId), ("Amount", Bill.SumAmount)); } }, token: new System.Threading.CancellationToken()); })); },
/// <summary> /// 提交单据 /// </summary> /// <param name="data"></param> /// <param name="billId"></param> /// <returns></returns> public async Task <APIResult <ReturnReservationBillUpdateModel> > CreateOrUpdateAsync(ReturnReservationBillUpdateModel data, int billId = 0, CancellationToken calToken = default) { try { int storeId = Settings.StoreId; int userId = Settings.UserId; var api = RefitServiceBuilder.Build <IReturnReservationBillApi>(URL); var results = await _makeRequest.Start(api.CreateOrUpdateAsync(data, storeId, userId, billId, calToken), calToken); return(results); } catch (Exception e) { e.HandleException(); return(null); } }