Exemplo n.º 1
0
        public override void OnNavigatedTo(INavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);
            try
            {
                if (parameters.ContainsKey("InventoryReportItemModel"))
                {
                    parameters.TryGetValue <InventoryReportItemModel>("InventoryReportItemModel", out InventoryReportItemModel storeReporting);
                    if (storeReporting != null)
                    {
                        StoreReporting        = storeReporting;
                        ReportStoreQuantities = storeReporting.InventoryReportStoreQuantities;
                    }
                }

                if (parameters.ContainsKey("Products"))
                {
                    parameters.TryGetValue <List <ProductModel> >("Products", out List <ProductModel> products);
                    if (products != null)
                    {
                        ProductSeries = new ObservableCollection <ProductModel>(products);
                    }
                }

                var product = ProductSeries.FirstOrDefault();
                if (product != null)
                {
                    StoreReporting = new InventoryReportItemModel()
                    {
                        ProductId     = product.Id,
                        ProductName   = product.Name,
                        BigUnitId     = product.BigPriceUnit.UnitId,
                        BigUnitName   = product.BigPriceUnit.UnitName,
                        SmallUnitId   = product.SmallPriceUnit.UnitId,
                        SmallUnitName = product.SmallPriceUnit.UnitName
                    };
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Exemplo n.º 2
0
        public InventoryReportPageViewModel(INavigationService navigationService,
                                            IProductService productService,
                                            ITerminalService terminalService,
                                            IUserService userService,
                                            IWareHousesService wareHousesService,
                                            IAccountingService accountingService,
                                            IDialogService dialogService
                                            ) : base(navigationService,
                                                     productService,
                                                     terminalService,
                                                     userService,
                                                     wareHousesService,
                                                     accountingService,
                                                     dialogService)
        {
            Title = "库存上报";

            this.Bill = new InventoryReportBillModel()
            {
                BusinessUserId = Settings.UserId,
                BillNumber     = CommonHelper.GetBillNumber("KCSB", Settings.StoreId),
                CreatedOnUtc   = DateTime.Now
            };

            //编辑项目
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                await this.NavigateAsync("AddReportProductPage", ("InventoryReportItemModel", item));
                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (Bill.TerminalId == 0)
                {
                    _dialogService.ShortAlert("请选择客户!");
                    return;
                }
                await this.NavigateAsync("SelectProductPage", ("Reference", $"{nameof(InventoryReportPage)}"), ("SerchKey", Filter.SerchKey));
            });

            //验证
            var valid_TerminalId     = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定");
            var valid_BusinessUserId = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "商品未指定");


            //提交
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ =>
            {
                //await this.Access(AccessGranularityEnum.StockReportSave);
                return(await this.Access(AccessGranularityEnum.StockReportSave, async() =>
                {
                    Bill.StoreId = Settings.StoreId;
                    Bill.BusinessUserId = Settings.UserId;
                    Bill.ReversedUserId = 0;
                    Bill.ReversedStatus = false;

                    return await SubmitAsync(Bill, 0, _wareHousesService.CreateOrUpdateAsync, (result) =>
                    {
                        Bill = new InventoryReportBillModel();
                    }, token: new System.Threading.CancellationToken());
                }));
            },
                                                                                   this.IsValid());

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                { MenuEnum.CLEAR, (m, vm) => {
                      ClearForm(() =>
                        {
                            Bill.Items?.Clear();
                        });
                  } },
            });
        }