예제 #1
0
        public VisitStorePageViewModel(INavigationService navigationService,
                                       IProductService productService,
                                       ITerminalService terminalService,
                                       IUserService userService,
                                       IWareHousesService wareHousesService,
                                       IAccountingService accountingService,
                                       IMediaPickerService mediaPickerService,
                                       ILiteDbService <TrackingModel> conn,
                                       ILiteDbService <VisitStore> vsdb,
                                       IPermissionsService permissionsService,
                                       IDialogService dialogService) : base(navigationService,
                                                                            productService,
                                                                            terminalService,
                                                                            userService,
                                                                            wareHousesService,
                                                                            accountingService,
                                                                            dialogService)
        {
            _permissionsService = permissionsService;
            _mediaPickerService = mediaPickerService;

            _conn = conn;
            _vsdb = vsdb;

            Title = "拜访门店";

            httpClientHelper = new HttpClientHelper();

            this.SubmitText = "\uf017";

            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    var check          = await CheckSignIn();
                    this.SignInEnabled = !check;

                    if (!string.IsNullOrWhiteSpace(Settings.DisplayPhotos))
                    {
                        var displayPhotos = JsonConvert.DeserializeObject <List <DisplayPhoto> >(Settings.DisplayPhotos);
                        if (displayPhotos != null)
                        {
                            this.Bill.DisplayPhotos = new ObservableCollection <DisplayPhoto>(displayPhotos);
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(Settings.DoorheadPhotos))
                    {
                        var doorheadPhotos = JsonConvert.DeserializeObject <List <DoorheadPhoto> >(Settings.DoorheadPhotos);
                        if (doorheadPhotos != null)
                        {
                            this.Bill.DoorheadPhotos = new ObservableCollection <DoorheadPhoto>(doorheadPhotos);
                        }
                    }

                    //重新获取客户信息
                    if (Settings.LastSigninCoustmerId > 0)
                    {
                        var tt = await _terminalService.GetTerminalAsync(Settings.LastSigninCoustmerId);
                        if (tt != null)
                        {
                            this.Terminal     = tt;
                            Bill.TerminalId   = tt.Id;
                            Bill.TerminalName = tt.Name;
                        }
                    }


                    //有没签退信息时
                    if (this.OutVisitStore != null)
                    {
                        //刷新状态
                        Refresh(this.OutVisitStore);
                    }

                    //如果上次签到客户存在时
                    var terminalId = Settings.LastSigninCoustmerId > 0 ? Settings.LastSigninCoustmerId : Bill.TerminalId;
                    if (terminalId > 0)
                    {
                        //获取终端余额
                        _terminalService.Rx_GetTerminalBalance(terminalId, new CancellationToken())?.Subscribe((balance) =>
                        {
                            if (balance != null)
                            {
                                this.TBalance = balance;
                            }
                        }).DisposeWith(DeactivateWith);


                        //获取上次拜访信息
                        _terminalService.Rx_GetLastVisitStoreAsync(terminalId, Settings.UserId, new CancellationToken())?.Subscribe((result) =>
                        {
                            if (result != null && result.Id > 0)
                            {
                                try
                                {
                                    //上次签到时间
                                    if (result.SigninDateTime != null)
                                    {
                                        var seconds = (int)DateTime.Now.Subtract(result.SigninDateTime).TotalSeconds;
                                        var coms    = CommonHelper.ConvetToSeconds(seconds);

                                        if (!string.IsNullOrEmpty(coms))
                                        {
                                            this.Bill.LastSigninDateTimeName = coms;
                                        }
                                    }

                                    //上次采购时间
                                    if (result.LastPurchaseDate != null)
                                    {
                                        var seconds = (int)DateTime.Now.Subtract(result.LastPurchaseDate).TotalSeconds;
                                        var coms    = CommonHelper.ConvetToSeconds(seconds);
                                        if (!string.IsNullOrEmpty(coms))
                                        {
                                            this.Bill.LastPurchaseDateTimeName = coms;
                                        }
                                    }

                                    if (this.OutVisitStore == null && result.SigninDateTime != null)
                                    {
                                        this.Bill.SigninDateTime = result.SigninDateTime;
                                    }
                                }
                                catch (Exception) { }
                            }
                        }).DisposeWith(DeactivateWith);
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            //历史记录选择
            this.HistoryCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync($"{nameof(VisitRecordsPage)}", null));

            //到店签到
            this.OpenSignInCommend = ReactiveCommand.CreateFromTask(async() =>
            {
                if (Bill.TerminalId == 0)
                {
                    await this.NavigateAsync("CurrentCustomerPage");
                    return(Unit.Default);
                }

                var loc = await _permissionsService.GetLocationConsent();
                if (loc != PermissionStatus.Granted)
                {
                    await _dialogService.ShowAlertAsync("你的位置服务没有开启,请打开GPS", "定位", "确定");
                    return(Unit.Default);
                }

                if (Bill.TerminalId == 0 || string.IsNullOrEmpty(Bill.TerminalName))
                {
                    this.Alert("未选择客户...");
                    return(Unit.Default);
                }

                if (IsFooterVisible)
                {
                    IsVisible  = true;
                    IsExpanded = true;
                    //载入位置
                    ReloadLocation();
                    IsFooterVisible = false;
                }
                else
                {
                    IsVisible       = false;
                    IsExpanded      = false;
                    IsFooterVisible = true;
                }

                return(Unit.Default);
            });

            //取消签到
            this.CancelSignIn = ReactiveCommand.Create(() =>
            {
                IsVisible       = false;
                IsExpanded      = false;
                IsFooterVisible = true;
            });

            //签到
            this.SignInCommend = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    if (!IsFastClick())
                    {
                        return(Unit.Default);
                    }

                    bool continueTodo = true;
                    if (Terminal.CalcDistance() > 50)
                    {
                        continueTodo  = await UserDialogs.Instance.ConfirmAsync($"你确定要在{Terminal.Distance:#.00}米外签到吗?", "警告", cancelText: "不签到", okText: "继续签到");
                        Bill.Abnormal = true;
                        Bill.Distance = Math.Round(Terminal.Distance, 2);
                    }


                    var lat = GlobalSettings.Latitude ?? 0;
                    var lan = GlobalSettings.Longitude ?? 0;


                    if (!continueTodo)
                    {
                        return(Unit.Default);
                    }

                    //签到
                    Bill.Id                   = 0;
                    Bill.StoreId              = Settings.StoreId;
                    Bill.BusinessUserId       = Settings.UserId;
                    Bill.BusinessUserName     = Settings.UserRealName;
                    Bill.ChannelId            = Terminal.ChannelId;
                    Bill.DistrictId           = Terminal.DistrictId;
                    Bill.SigninDateTimeEnable = true;
                    Bill.SigninDateTime       = DateTime.Now;
                    Bill.SignOutDateTime      = DateTime.Now;
                    Bill.VisitTypeId          = 2;//计划内
                    Bill.SignTypeId           = 1;
                    Bill.SignType             = Enums.SignEnum.CheckIn;
                    Bill.Remark               = LocationAddress;

                    //获取坐标
                    Bill.Latitude  = lat;
                    Bill.Longitude = lan;

                    return(await SubmitAsync(Bill, _terminalService.SignInVisitStoreAsync, async(result) =>
                    {
                        if (!result.Success)
                        {
                            this.IsVisible = false;
                            this.IsExpanded = false;
                            this.IsFooterVisible = true;
                        }
                        else
                        {
                            if (result.Data is VisitStore data)
                            {
                                this.SignInEnabled = false;
                                this.SignOutEnabled = true;
                                this.OutVisitStore = null;

                                //drawer
                                this.IsVisible = false;
                                this.IsExpanded = false;
                                this.IsFooterVisible = true;

                                //记录下签到ID
                                Settings.LastSigninId = data.Id;
                                Settings.LastSigninCoustmerId = Bill.TerminalId;
                                Settings.LastSigninCoustmerName = Bill.TerminalName;

                                this.Bill.LastSigninDateTime = data.LastSigninDateTime;
                                this.Bill.LastPurchaseDateTime = data.LastPurchaseDateTime;

                                //添加签到记录
                                try
                                {
                                    Terminal.Id = Bill.TerminalId;
                                    Terminal.LastSigninDateTimeName = data.SigninDateTime.ToString();
                                    Terminal.SigninDateTime = data.SigninDateTime;
                                    await _terminalService.AddTerminal(Terminal);
                                }
                                catch (Exception) { }
                            }
                        }
                    }, goBack: false));
                }
                catch (Exception)
                {
                    this.IsVisible       = false;
                    this.IsExpanded      = false;
                    this.IsFooterVisible = true;

                    await ShowAlert(false, $"出错啦,内部异常!");
                    return(Unit.Default);
                }
            });

            //校准位置
            this.CorrectPositionCommend = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var lat = GlobalSettings.Latitude ?? 0;
                    var lan = GlobalSettings.Longitude ?? 0;

                    if (Terminal == null || Terminal.Id == 0)
                    {
                        await ShowAlert(false, $"无效操作!");
                        return;
                    }

                    if (lat != 0 && lan != 0)
                    {
                        var distance          = MapHelper.CalculateDistance(GlobalSettings.Latitude ?? 0, GlobalSettings.Longitude ?? 0, this.Terminal?.Location_Lat ?? 0, this.Terminal?.Location_Lng ?? 0);
                        Terminal.Location_Lat = GlobalSettings.Latitude;
                        Terminal.Location_Lng = GlobalSettings.Longitude;
                        Terminal.Distance     = distance;
                        await _terminalService.UpdateterminalAsync(Terminal.Id, GlobalSettings.Latitude ?? 0, GlobalSettings.Longitude ?? 0);
                    }

                    await ShowAlert(true, $"校准成功!");
                }
                catch (Exception)
                {
                    await ShowAlert(false, $"出错啦,内部异常!");
                }
            });

            //离店签退
            this.SignOutCommend = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    int onStoreStopSeconds = 0;
                    double subtract        = DateTime.Now.Subtract(Bill?.SigninDateTime ?? DateTime.Now).TotalMinutes;
                    if (!string.IsNullOrEmpty(Settings.CompanySetting))
                    {
                        var companySetting = JsonConvert.DeserializeObject <CompanySettingModel>(Settings.CompanySetting);
                        if (companySetting != null)
                        {
                            onStoreStopSeconds = companySetting.OnStoreStopSeconds;
                        }
                    }

                    if (!SignOutEnabled)
                    {
                        this.Alert("还没签到哦!");
                        return(Unit.Default);
                    }

                    if (onStoreStopSeconds > 0 && subtract < onStoreStopSeconds)
                    {
                        this.Alert($"签退无效,拜访在店时间必须大于{onStoreStopSeconds}分钟");
                        return(Unit.Default);
                    }

                    if (Settings.LastSigninId == 0)
                    {
                        this.Alert("签退无效,无法确定记录");
                        return(Unit.Default);
                    }

                    if (Bill.TerminalId == 0 || string.IsNullOrEmpty(Bill.TerminalName))
                    {
                        this.Alert("选择客户");
                        return(Unit.Default);
                    }

                    if (Bill.DoorheadPhotos == null || Bill.DoorheadPhotos.Count == 0)
                    {
                        this.Alert("请拍摄门头照片");
                        return(Unit.Default);
                    }

                    if (Bill.DisplayPhotos == null || Bill.DisplayPhotos.Count == 0)
                    {
                        this.Alert("请拍摄陈列照片");
                        return(Unit.Default);
                    }

                    if (BillId > 0)
                    {
                        switch (BillType)
                        {
                        case BillTypeEnum.SaleReservationBill:
                            this.Bill.SaleReservationBillId = BillId;
                            this.Bill.SaleOrderAmount       = Amount;
                            break;

                        case BillTypeEnum.SaleBill:
                            this.Bill.SaleBillId = BillId;
                            this.Bill.SaleAmount = Amount;
                            break;

                        case BillTypeEnum.ReturnReservationBill:
                            this.Bill.ReturnReservationBillId = BillId;
                            this.Bill.ReturnOrderAmount       = Amount;
                            break;

                        case BillTypeEnum.ReturnBill:
                            this.Bill.ReturnBillId = BillId;
                            this.Bill.ReturnAmount = Amount;
                            break;
                        }
                    }

                    //签退
                    Bill.Id = Settings.LastSigninId;
                    Bill.SignOutDateTime = DateTime.Now;
                    Bill.SignTypeId      = 2;

                    await SubmitAsync(Bill, _terminalService.SignOutVisitStoreAsync, async(result) =>
                    {
                        if (result.Success)
                        {
                            this.SignOutEnabled            = false;
                            this.Bill.SigninDateTimeEnable = false;
                            this.OutVisitStore             = null;

                            Settings.LastSigninId           = 0;
                            Settings.LastSigninCoustmerId   = 0;
                            Settings.LastSigninCoustmerName = "";

                            Settings.DisplayPhotos  = "";
                            Settings.DoorheadPhotos = "";

                            //更新签到记录
                            try
                            {
                                Terminal.Id = Bill.TerminalId;
                                Terminal.SignOutDateTime = Bill.SignOutDateTime;
                                await _terminalService.UpdateTerminal(Terminal);
                            }catch (Exception) { }
                        }
                    });

                    await _navigationService.GoBackAsync();

                    return(Unit.Default);
                }
                catch (Exception)
                {
                    await ShowAlert(false, $"出错啦,内部异常!");
                    return(Unit.Default);
                }
            });

            //应用选择执行
            this.InvokeAppCommand = ReactiveCommand.CreateFromTask <string>(async(r) =>
            {
                try
                {
                    if (Settings.LastSigninId != 0 && Settings.LastSigninCoustmerId != 0)
                    {
                        await this.NavigateAsync(r.ToString(),
                                                 ("TerminalId", Bill.TerminalId),
                                                 ("TerminalName", Bill.TerminalName),
                                                 ("Reference", this.PageName));
                    }
                    else
                    {
                        await ShowAlert(false, "需要先签到后操作");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            //拍照选择
            this.CameraPhotoCmd = ReactiveCommand.CreateFromTask <string>(async(r) =>
            {
                if (!IsFastClick())
                {
                    return;
                }

                if (this.SignInEnabled)
                {
                    this.Alert("还没有签到哦!");
                }
                else
                {
                    await this.NavigateAsync("CameraViewPage", ("TakeType", r));
                }
            });

            //删除门头照片
            this.RemoveStoragePathCommand = ReactiveCommand.Create <string>(async x =>
            {
                var ok = await _dialogService.ShowConfirmAsync("是否要删除该图片?", okText: "确定", cancelText: "取消");
                if (ok)
                {
                    var temp = this.Bill.DoorheadPhotos.FirstOrDefault(s => s.StoragePath == x);
                    if (temp != null)
                    {
                        this.Bill.DoorheadPhotos.Remove(temp);
                        Settings.DoorheadPhotos = JsonConvert.SerializeObject(this.Bill.DoorheadPhotos);
                    }
                }
            });

            //删除陈列照片
            this.RemoveDisplayPathCommand = ReactiveCommand.Create <string>(async x =>
            {
                var ok = await _dialogService.ShowConfirmAsync("是否要删除该图片?", okText: "确定", cancelText: "取消");
                if (ok)
                {
                    var temp = this.Bill.DisplayPhotos.FirstOrDefault(s => s.DisplayPath == x);
                    if (temp != null)
                    {
                        this.Bill.DisplayPhotos.Remove(temp);
                        Settings.DisplayPhotos = JsonConvert.SerializeObject(this.Bill.DisplayPhotos);
                    }
                }
            });

            //定位
            this.OrientationCmd = ReactiveCommand.Create(() =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    ReloadLocation();
                });
            });

            //预览照片
            this.WhenAnyValue(x => x.DoorheadPhotoSelecter)
            .Throttle(TimeSpan.FromMilliseconds(200))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                var images = new List <string> {
                    item.StoragePath
                };
                await this.NavigateAsync("ImageViewerPage", ("ImageInfos", images));
                DoorheadPhotoSelecter = null;
            }).DisposeWith(DeactivateWith);

            this.WhenAnyValue(x => x.DisplayPhotoSelecter)
            .Throttle(TimeSpan.FromMilliseconds(200))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                var images = new List <string> {
                    item.DisplayPath
                };
                await this.NavigateAsync("ImageViewerPage", ("ImageInfos", images));
                DisplayPhotoSelecter = null;
            }).DisposeWith(DeactivateWith);

            this.BindBusyCommand(Load);


            //拍照上传
            MessageBus
            .Current
            .Listen <byte[]?>(string.Format(Constants.CAMERA_KEY, "DoorheadPhotos"))
            .Subscribe(bit =>
            {
                if (bit != null && bit.Length > 0)
                {
                    UploadPhotograph((u) =>
                    {
                        var photo = new DoorheadPhoto
                        {
                            StoragePath = $"{GlobalSettings.FileCenterEndpoint}HRXHJS/document/image/" + u.Id + ""
                        };
                        this.Bill.DoorheadPhotos.Add(photo);
                        Settings.DoorheadPhotos = JsonConvert.SerializeObject(this.Bill.DoorheadPhotos);
                    }, new MemoryStream(bit));
                }
            }).DisposeWith(DeactivateWith);


            MessageBus
            .Current
            .Listen <byte[]?>(string.Format(Constants.CAMERA_KEY, "DisplayPhotos"))
            .Subscribe(bit =>
            {
                if (bit != null && bit.Length > 0)
                {
                    UploadPhotograph((u) =>
                    {
                        var photo = new DisplayPhoto
                        {
                            DisplayPath = $"{GlobalSettings.FileCenterEndpoint}HRXHJS/document/image/" + u.Id + ""
                        };
                        this.Bill.DisplayPhotos.Add(photo);
                        Settings.DisplayPhotos = JsonConvert.SerializeObject(this.Bill.DisplayPhotos);
                    }, new MemoryStream(bit));
                }
            }).DisposeWith(DeactivateWith);

            this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.HistoryCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.OpenSignInCommend.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.CancelSignIn.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SignInCommend.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.CorrectPositionCommend.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SignOutCommend.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.InvokeAppCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.CameraPhotoCmd.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.RemoveStoragePathCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.RemoveDisplayPathCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.OrientationCmd.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
        }
예제 #2
0
        public CostExpenditureBillPageViewModel(INavigationService navigationService,
                                                IProductService productService,
                                                IUserService userService,
                                                ITerminalService terminalService,
                                                IWareHousesService wareHousesService,
                                                IAccountingService accountingService,
                                                ICostExpenditureService costExpenditureService,
                                                ISaleBillService saleBillService,
                                                IDialogService dialogService
                                                ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "费用支出";

            _costExpenditureService = costExpenditureService;
            _saleBillService        = saleBillService;

            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_ItemCount     = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加费用项目");
            var valid_SelectesCount = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式");

            //提交单据
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ =>
            {
                //await this.Access(AccessGranularityEnum.ExpenseExpenditureSave);
                return(await this.Access(AccessGranularityEnum.ExpenseExpenditureSave, async() =>
                {
                    if (this.Bill.ReversedStatus)
                    {
                        _dialogService.ShortAlert("已红冲单据不能操作");
                        return Unit.Default;
                    }

                    var postData = new CostExpenditureUpdateModel()
                    {
                        CustomerId = this.Bill.TerminalId,
                        BillNumber = this.Bill.BillNumber,
                        EmployeeId = Settings.UserId,
                        OweCash = Bill.OweCash,
                        Remark = Bill.Remark,
                        Items = Bill.Items,
                        Accounting = PaymentMethods.Selectes.Select(a =>
                        {
                            return new AccountMaping()
                            {
                                AccountingOptionId = a.AccountingOptionId,
                                CollectionAmount = a.CollectionAmount,
                                Name = a.Name,
                                BillId = 0,
                            };
                        }).ToList(),
                    };
                    return await SubmitAsync(postData, 0, _costExpenditureService.CreateOrUpdateAsync, (result) =>
                    {
                        Bill = new CostExpenditureBillModel();
                    }, token: new System.Threading.CancellationToken());
                }));
            },
                                                                                   this.IsValid());

            //存储记录
            this.SaveCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!this.Bill.AuditedStatus && this.Bill.TerminalId != 0 && this.Bill.TerminalId != Settings.CostExpenditureBill?.TerminalId)
                {
                    var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消");
                    if (ok)
                    {
                        if (!this.Bill.AuditedStatus)
                        {
                            Settings.CostExpenditureBill = this.Bill;
                        }
                    }
                }
                await _navigationService.GoBackAsync();
            });

            //编辑费用
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async x =>
            {
                if (this.Bill.ReversedStatus)
                {
                    _dialogService.ShortAlert("已红冲单据不能操作");
                    return;
                }

                if (this.Bill.AuditedStatus)
                {
                    _dialogService.ShortAlert("已审核单据不能操作");
                    return;
                }

                await this.NavigateAsync("AddCostPage", ("Terminaler", this.Terminal), ("Selecter", x));
                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);

            //添加费用
            this.AddCostCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!valid_TerminalId.IsValid)
                {
                    _dialogService.ShortAlert(valid_TerminalId.Message[0]); return;
                }
                if (this.Bill.AuditedStatus)
                {
                    _dialogService.ShortAlert("已审核单据不能操作!"); return;
                }

                await this.NavigateAsync("AddCostPage", ("Terminaler", this.Terminal));
            });

            //更多支付方式
            this.MorePaymentCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!valid_TerminalId.IsValid)
                {
                    _dialogService.ShortAlert("客户未指定!"); return;
                }
                this.PaymentMethods.PreferentialAmountShowFiled = false;
                await this.NavigateAsync("PaymentMethodPage", ("PaymentMethods", this.PaymentMethods), ("BillType", this.BillType));
            });

            //审核
            this.AuditingDataCommand = ReactiveCommand.Create <object>(async _ =>
            {
                //是否具有审核权限
                await this.Access(AccessGranularityEnum.ExpenseExpenditureApproved);
                await SubmitAsync(Bill.Id, _costExpenditureService.AuditingAsync, async(result) =>
                {
                    //红冲审核水印
                    this.Bill.AuditedStatus = true;

                    var _conn = App.Resolve <ILiteDbService <MessageInfo> >();
                    var ms    = await _conn.Table.FindByIdAsync(SelecterMessage.Id);
                    if (ms != null)
                    {
                        ms.IsRead = true;
                        await _conn.UpsertAsync(ms);
                    }
                });
            }, this.WhenAny(x => x.Bill.Id, (x) => x.GetValue() > 0));


            //拒签
            this.RefusedCommand = ReactiveCommand.CreateFromTask <object>(async _ =>
            {
                try
                {
                    var ok = await _dialogService.ShowConfirmAsync("你确定要放弃签收吗?", "", "确定", "取消");
                    if (ok)
                    {
                        var postMData = new DeliverySignUpdateModel()
                        {
                            //不关联调拨单
                            DispatchItemId = 0,
                            DispatchBillId = 0,
                            StoreId        = Settings.StoreId,
                            BillId         = Bill.Id,
                            BillTypeId     = (int)BillTypeEnum.CostExpenditureBill,
                            //
                            Latitude  = GlobalSettings.Latitude,
                            Longitude = GlobalSettings.Longitude,
                            Signature = ""
                        };
                        await SubmitAsync(postMData, postMData.Id, _saleBillService.RefusedConfirmAsync, async(result) =>
                        {
                            await _navigationService.GoBackAsync();
                        });
                    }
                }
                catch (Exception)
                {
                    await _dialogService.ShowAlertAsync("拒签失败,服务器请求错误!", "", "取消");
                }
            });

            //签收
            this.ConfirmCommand = ReactiveCommand.CreateFromTask <object>(async _ =>
            {
                try
                {
                    //如果签收距离>50 则计数
                    if (Terminal.CalcDistance() > 50)
                    {
                        var tmp = Settings.Abnormal;
                        if (tmp != null)
                        {
                            tmp.Id            = Terminal.Id;
                            tmp.Counter      += 1;
                            Settings.Abnormal = tmp;
                        }
                        else
                        {
                            Settings.Abnormal = new AbnormalNum {
                                Id = Terminal.Id, Counter = 1
                            };
                        }
                    }

                    var signature = await CrossDiaglogKit.Current.GetSignaturePadAsync("手写签名", "", Keyboard.Default, defaultValue: "", placeHolder: "请手写签名...");
                    if (!string.IsNullOrEmpty(signature))
                    {
                        var postMData = new DeliverySignUpdateModel()
                        {
                            //不关联调拨单
                            DispatchItemId = 0,
                            DispatchBillId = 0,
                            StoreId        = Settings.StoreId,
                            BillId         = Bill.Id,
                            BillTypeId     = (int)BillTypeEnum.CostExpenditureBill,
                            //
                            Latitude  = GlobalSettings.Latitude,
                            Longitude = GlobalSettings.Longitude,
                            Signature = signature
                        };

                        //如果终端异常签收大于5次,则拍照
                        //if (Settings.Abnormal.Counter > 5)
                        //{
                        //    await TakePhotograph((u, m) =>
                        //    {
                        //        var photo = new RetainPhoto
                        //        {
                        //            DisplayPath = $"{GlobalSettings.FileCenterEndpoint}HRXHJS/document/image/" + u.Id + ""
                        //        };
                        //        postMData.RetainPhotos.Add(photo);
                        //    });
                        //}

                        if (Settings.Abnormal.Counter > 5 && postMData.RetainPhotos.Count == 0)
                        {
                            await _dialogService.ShowAlertAsync("拒绝操作,请留存拍照!", "", "取消");
                            return;
                        }

                        await SubmitAsync(postMData, postMData.Id, _saleBillService.DeliverySignConfirmAsync, async(result) =>
                        {
                            await _navigationService.GoBackAsync();
                        });
                    }
                }
                catch (Exception)
                {
                    await _dialogService.ShowAlertAsync("签收失败,服务器请求错误!", "", "取消");
                }
            });


            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.REMARK, (m, vm) => {
                      AllRemak((result) => { Bill.Remark = result; }, Bill.Remark);
                  } },
                //清空单据
                { MenuEnum.CLEAR, (m, vm) => {
                      ClearBill <CostContractBillModel, CostContractItemModel>(null, DoClear);
                  } },
                //销售备注
                { MenuEnum.SALEREMARK, (m, vm) => {
                      AllRemak((result) => { Bill.Remark = result; }, Bill.Remark);
                  } }
            });
        }