public async void CalcSmallPrice(int porductId) { try { var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); var _dialogView = new PopRadioButtonPage("选择价格", "", () => { var popDatas = new List <PopData>(); if (product != null) { var tierprices = product.ProductTierPrices; if (tierprices != null) { #region //默认条件 int pId = 0; int pTId = 0; var pArry = Settings.DefaultPricePlan.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList(); if (pArry.Count > 0) { pId = pArry[0]; pTId = pArry[1]; } switch (pTId) { case (int)PriceType.ProductCost: { var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 0); popDatas.Add(new PopData() { Id = (int)PriceType.ProductCost, Column = "进价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.CostPrice: { //成本价 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 5); popDatas.Add(new PopData() { Id = (int)PriceType.CostPrice, Column = "成本价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.WholesalePrice: { //批发价格 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 1); popDatas.Add(new PopData() { Id = (int)PriceType.WholesalePrice, Column = "批发价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.RetailPrice: { //零售价格 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 2); popDatas.Add(new PopData() { Id = (int)PriceType.RetailPrice, Column = "零售价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.LowestPrice: { //最低售价 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 3); popDatas.Add(new PopData() { Id = (int)PriceType.LowestPrice, Column = "最低售价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.CustomPlan: { //方案价格 int i = 0; foreach (var price in tierprices.Where(s => new int[] { (int)PriceType.CustomPlan }.Contains(s.PriceTypeId)).ToList()) { popDatas.Add(new PopData() { Id = (int)PriceType.CustomPlan + i, Column = price?.PriceTypeName, Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); i++; } } break; case (int)PriceType.LastedPrice: { //上次价格 var price = product.ProductTierPrices.Where(s => s.PriceTypeId == (int)PriceType.LastedPrice).FirstOrDefault(); if (price != null) { popDatas.Add(new PopData() { Id = (int)PriceType.CustomPlan, Column = "上次价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } } break; } #endregion } } return(Task.FromResult(popDatas)); }); _dialogView.Completed += (sender, result) => { if (result != null) { product.SmallPriceUnit.Price = (decimal)(result?.Data ?? decimal.Zero); product.SmallPriceUnit.Amount = (decimal)(result?.Data ?? decimal.Zero) * product?.SmallPriceUnit?.Quantity ?? 0; } }; await PopupNavigation.Instance.PushAsync(_dialogView); } catch (Exception ex) { Crashes.TrackError(ex); } }
public AddProductPageViewModel( INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "添加商品"; CompanySetting = JsonConvert.DeserializeObject <CompanySettingModel>(Settings.CompanySetting); //更改重算 this.BigEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 0); }); this.SmallEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 1); }); //选择价格 this.SmallPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcSmallPrice(pid); }); this.BigPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcBigPrice(pid); }); //保存 this.SaveCommand = ReactiveCommand.Create(async() => { try { bool vaildQuantity = false; bool vaildBigPrice = false; bool vaildSmallPrice = false; bool vaildBigQuantity = false; bool vaildSmallQuantity = false; bool vaildGiftQuantity = false; if (!string.IsNullOrEmpty(ReferencePage)) { //数量 ProductSeries.ToList().ForEach(p => { vaildQuantity = (p.BigPriceUnit.Quantity == 0 || p.SmallPriceUnit.Quantity == 0); if (vaildQuantity) { return; } }); //赠送 ProductSeries.ToList().ForEach(p => { vaildGiftQuantity = (p.GiveProduct.BigUnitQuantity == 0 && p.GiveProduct.SmallUnitQuantity == 0); if (vaildGiftQuantity) { return; } }); //大单位 ProductSeries.ToList().ForEach(p => { vaildBigPrice = (p.BigPriceUnit.Quantity > 0 && (p.BigPriceUnit?.Price == null || p.BigPriceUnit?.Price < 0)); if (vaildBigPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildBigQuantity = (p.BigPriceUnit.Quantity <= 0); if (vaildBigQuantity) { return; } }); //小单位 ProductSeries.ToList().ForEach(p => { vaildSmallPrice = (p.SmallPriceUnit.Quantity > 0 && (p.SmallPriceUnit?.Price == null || p.SmallPriceUnit?.Price < 0)); if (vaildSmallPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildSmallQuantity = (p.SmallPriceUnit.Quantity <= 0); if (vaildSmallQuantity) { return; } }); if (vaildGiftQuantity) { if (vaildBigQuantity && vaildSmallQuantity) { this.Alert("商品数量不能为空"); return; } } if (vaildBigQuantity && !vaildBigPrice && !vaildQuantity) { this.Alert("商品大单位数量不能为空"); return; } if (vaildBigPrice && !vaildBigQuantity && !vaildQuantity) { this.Alert("商品大单位价格不能为空"); return; } if (vaildSmallQuantity && !vaildSmallPrice && !vaildQuantity) { this.Alert("商品小单位数量不能为空"); return; } if (vaildSmallPrice && !vaildSmallQuantity && !vaildQuantity) { this.Alert("商品小单位价格不能为空"); return; } var products = ProductSeries.Where(s => s.BigPriceUnit.Quantity > 0 && s.BigPriceUnit.Price >= 0 || s.SmallPriceUnit.Quantity > 0 && s.SmallPriceUnit.Price >= 0 || s.GiveProduct.BigUnitQuantity > 0 || s.GiveProduct.SmallUnitQuantity >= 0).ToList(); //转向引用页 var redirectPage = $"../../"; await this.NavigateAsync(redirectPage, ("ProductSeries", products)); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //移除商品 this.RemoveCommend = ReactiveCommand.Create <int>(async(pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { products.Remove(product); } ProductSeries = new ObservableCollection <ProductModel>(products); if (products.Count == 0) { await _navigationService.GoBackAsync(); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //拷贝商品 this.CopyCommend = ReactiveCommand.Create <int>((pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { var newModel = new ProductModel { Id = product.Id, ProductId = product.Id, ProductName = product.ProductName, Name = product.Name, UnitId = product.UnitId, Quantity = product.Quantity, Price = product.Price, Amount = product.Amount, Remark = product.Remark, Subtotal = product.Subtotal, StockQty = product.StockQty, UnitConversion = product.UnitConversion, UnitName = product.UnitName, Units = product.Units, BigPriceUnit = new PriceUnit() { Amount = product.BigPriceUnit.Amount, Price = product.BigPriceUnit.Price, Quantity = product.BigPriceUnit.Quantity, Remark = product.BigPriceUnit.Remark, UnitId = product.BigPriceUnit.UnitId, UnitName = product.BigPriceUnit.UnitName }, SmallPriceUnit = new PriceUnit() { Amount = product.SmallPriceUnit.Amount, Price = product.SmallPriceUnit.Price, Quantity = product.SmallPriceUnit.Quantity, Remark = product.SmallPriceUnit.Remark, UnitId = product.SmallPriceUnit.UnitId, UnitName = product.SmallPriceUnit.UnitName } }; newModel.BigPriceUnit.UnitId = product.BigUnitId ?? 0; newModel.SmallPriceUnit.UnitId = product.SmallUnitId ?? 0; products.Add(newModel); } ProductSeries = new ObservableCollection <ProductModel>(products); } catch (Exception ex) { Crashes.TrackError(ex); } }); }
public SelectProductPageViewModel(INavigationService navigationService, IProductService productService, IDialogService dialogService) : base(navigationService, dialogService) { Title = "选择商品"; _navigationService = navigationService; _dialogService = dialogService; _productService = productService; //只显库存商品 this.WhenAnyValue(x => x.UsableQuantity) .Skip(1) .Subscribe(s => { ((ICommand)Load)?.Execute(null); this.ForceRefresh = true; }).DisposeWith(DeactivateWith); //我的收藏 this.WhenAnyValue(x => x.UsableFavorite) .Skip(1) .Subscribe(s => { ((ICommand)Load)?.Execute(null); this.ForceRefresh = true; }).DisposeWith(DeactivateWith); //搜索 this.WhenAnyValue(x => x.Filter.SerchKey) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s) .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler) .Subscribe(s => { ((ICommand)SerchCommand)?.Execute(s); }).DisposeWith(DeactivateWith); this.SerchCommand = ReactiveCommand.Create <string>(e => { if (string.IsNullOrEmpty(Filter.SerchKey)) { this.Alert("请输入关键字!"); return; } ((ICommand)Load)?.Execute(null); }); //Load this.Load = ReactiveCommand.Create(async() => { try { ItemTreshold = 1; DataVewEnable = false; NullViewEnable = true; var items = await GetProductsPage(0, 50); if (items != null && items.Any()) { //清除列表 ProductSeries?.Clear(); foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } } } catch (Exception ex) { Crashes.TrackError(ex); } finally { DataVewEnable = true; NullViewEnable = false; } }); //以增量方式加载数据 this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() => { using (var dig = UserDialogs.Instance.Loading("加载中...")) { try { int pageIdex = ProductSeries.Count / 50; var items = await GetProductsPage(pageIdex, PageSize); var previousLastItem = ProductSeries.Last(); if (items != null) { foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } if (items.Count() == 0 || items.Count() == ProductSeries.Count) { ItemTreshold = -1; } } } catch (Exception ex) { Crashes.TrackError(ex); ItemTreshold = -1; } } }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0)); //初始类别 this.InitCatagory = ReactiveCommand.CreateFromTask(async() => { try { var result = await _productService.GetAllCategoriesAsync(true, new System.Threading.CancellationToken()); if (result != null && result.Any()) { var categories = result.ToList(); if (categories != null && categories.Any()) { foreach (var op in categories) { op.SelectedCommand = ReactiveCommand.Create <int>(r => { op.Selected = !op.Selected; }); } this.BindCategories = new ObservableCollection <CategoryModel>(categories); } } } catch (Exception ex) { Crashes.TrackError(ex); } }); //选择类别 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(x => { if (x != null) { Filter.CatagoryIds = new int[] { x.Id }; this.ForceRefresh = true; foreach (var op in this.BindCategories) { op.Selected = false; } x.Selected = !x.Selected; ((ICommand)Load)?.Execute(null); } Selecter = null; }) .DisposeWith(DeactivateWith); this.WhenAnyValue(x => x.ReferencePage) .Where(x => !string.IsNullOrEmpty(x)) .Subscribe(x => { this.ShowStockQty = !(x.Equals("InventoryOPBillPage") || x.Equals("InventoryBillPage")); }).DisposeWith(DeactivateWith); //选择礼品 this.SelectGiftsCommand = ReactiveCommand.Create(async() => { await this.NavigateAsync("SelectGiftsPage", ("WareHouse", WareHouse), ("Terminaler", this.Terminal)); }); //保存选择商品 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (string.IsNullOrEmpty(ReferencePage)) { await _navigationService.GoBackAsync(); return; } var products = ProductSeries.Select(p => p).Where(p => p.Selected == true).ToList(); if (products.Count == 0) { this.Alert("请选择商品项目"); return; } if (ReferencePage == nameof(InventoryReportPage)) { //添加上报商品 await this.NavigateAsync(nameof(AddReportProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(AllocationBillPage)) { if (this.Bill == null) { this.Alert("单据不能关联,请确保参数"); return; } //添加调拨商品 await this.NavigateAsync(nameof(AddAllocationProductPage), ("Bill", Bill), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(BackStockBillPage)) { //添加回库调拨单商品 await this.NavigateAsync(nameof(AddBackStockBillPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(TrackAllocationBillPage)) { //添加回库调拨单商品 await this.NavigateAsync(nameof(AddAllocationProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(CostContractBillPage)) { //添加合同商品 await this.NavigateAsync(nameof(AddCostContractProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(InventoryOPBillPage) || ReferencePage == nameof(InventoryBillPage)) { //追加商品 if (TempProductSeries.Any()) { var temps = TempProductSeries.ToList(); foreach (var tp in temps) { if (products.Where(s => s.ProductId == tp.ProductId).Count() == 0) { products.Add(tp); } } } //添加盘点商品 await this.NavigateAsync(nameof(AddInventoryProductPage), ("Reference", ReferencePage), ("WareHouse", WareHouse), ("Products", products)); } else if (ReferencePage == nameof(FilterPage)) { //过滤 await _navigationService.GoBackAsync( ("Filter", Filter), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(PurchaseOrderBillPage)) { //添加采购商品 await this.NavigateAsync(nameof(AddPurchaseProductPage), ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } else if (ReferencePage == nameof(ExchangeBillPage)) { //添加换货商品 await this.NavigateAsync(nameof(AddExchangeProductPage), ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } else { //添加单据商品 await this.NavigateAsync($"{nameof(AddProductPage)}", ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } }); //收藏 this.FavoriteCommand = ReactiveCommand.Create <ProductModel>(p => { try { var ps = Settings.FavoriteProducts; this.Filter.SerchKey = ""; if (!p.Favorited) { if (!ps.Select(s => s.ProductId).Contains(p.ProductId)) { p.Favorited = true; ps.Add(p); Settings.FavoriteProducts = ps; _dialogService.ShortAlert("收藏成功!"); } } else { var cur = ps.Where(s => s.ProductId == p.ProductId).FirstOrDefault(); if (cur != null) { cur.Favorited = false; p.Favorited = false; ps.Remove(cur); Settings.FavoriteProducts = ps; _dialogService.ShortAlert("收藏已移除!"); } } if (UsableFavorite) { if (ProductSeries != null && ProductSeries.Any()) { var reload = ProductSeries.Where(s => s.Favorited == true).ToList(); if (reload != null && reload.Any()) { this.ProductSeries = new ObservableCollection <ProductModel>(reload); } else { this.UsableFavorite = false; } } } } catch (Exception ex) { Crashes.TrackError(ex); } }); this.BindBusyCommand(Load); this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.InitCatagory.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.SelectGiftsCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.SubmitDataCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.FavoriteCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); }