コード例 #1
0
        void Update_Terminals()
        {
            Terminals.Clear();
            List <BOL.Terminal.objTerminal> List = DAL.Terminal.Terminal_Repository.GetActiveTerminals();

            List.ForEach(x => Terminals.Add(x));
        }
コード例 #2
0
        void Update_Terminal_Collections()
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += (s, arg) =>
            {
                arg.Result = DAL.Terminal.Terminal_Repository.GetSortedAllTerminals();
            };

            bw.RunWorkerCompleted += (s, arg) =>
            {
                if (arg.Error == null)
                {
                    if (arg.Result != null)
                    {
                        Terminals.Clear();
                        ((List <BOL.Terminal.objTerminal>)arg.Result).ForEach(x => Terminals.Add(x));
                    }
                }
            };
            bw.RunWorkerAsync();
        }
コード例 #3
0
        public SelectCustomerPageViewModel(INavigationService navigationService,
                                           IProductService productService,
                                           ITerminalService terminalService,
                                           IUserService userService,
                                           IWareHousesService wareHousesService,
                                           IAccountingService accountingService,
                                           IDialogService dialogService,
                                           ILiteDbService <VisitStore> conn) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "选择客户";

            _conn = conn;

            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Select(s => s)
            .Skip(1)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
            })
            .DisposeWith(DeactivateWith);

            //片区选择
            this.WhenAnyValue(x => x.Filter.DistrictId)
            .Where(s => s > 0)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
            })
            .DisposeWith(DeactivateWith);

            //加载数据
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    //重载时排它
                    ItemTreshold = 1;

                    try
                    {
                        if (Terminals != null && Terminals.Any())
                        {
                            Terminals?.Clear();
                        }
                    }
                    catch (Exception) { }

                    DataVewEnable  = false;
                    NullViewEnable = true;
                    using (var dig = UserDialogs.Instance.Loading("加载中..."))
                    {
                        this.Longitude = GlobalSettings.Longitude ?? 0;
                        this.Latitude  = GlobalSettings.Latitude ?? 0;

                        string searchStr    = Filter?.SerchKey;
                        int?districtId      = Filter?.DistrictId;
                        int?channelId       = Filter?.ChannelId;
                        int?businessUserId  = Filter?.BusinessUserId;
                        int?rankId          = Filter?.RankId;
                        int pageNumber      = 0;
                        int pageSize        = PageSize;
                        int?lineTierId      = Filter?.LineId;
                        int distanceOrderBy = Filter.DistanceOrderBy;

                        var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                           districtId,
                                                                           channelId,
                                                                           rankId,
                                                                           lineTierId,
                                                                           businessUserId,
                                                                           true,
                                                                           distanceOrderBy,
                                                                           GlobalSettings.Latitude ?? 0,
                                                                           GlobalSettings.Longitude ?? 0,
                                                                           0.5,
                                                                           pageNumber,
                                                                           pageSize);

                        var series = tuple.Item2;
                        if (series != null && series.Any())
                        {
                            this.Terminals = new AsyncObservableCollection <TerminalModel>(series);
                        }
                        else
                        {
                            ItemTreshold = -1;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    NullViewEnable = false;
                    DataVewEnable  = true;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1)
                {
                    return;
                }
                try
                {
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            string searchStr    = Filter?.SerchKey;
                            int?districtId      = Filter?.DistrictId;
                            int?channelId       = Filter?.ChannelId;
                            int?businessUserId  = Filter?.BusinessUserId;
                            int?rankId          = Filter?.RankId;
                            int pageNumber      = pageIdex;
                            int pageSize        = PageSize;
                            int?lineTierId      = Filter?.LineId;
                            int distanceOrderBy = Filter.DistanceOrderBy;

                            var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                               districtId,
                                                                               channelId,
                                                                               rankId,
                                                                               lineTierId,
                                                                               businessUserId,
                                                                               true,
                                                                               distanceOrderBy,
                                                                               GlobalSettings.Latitude ?? 0,
                                                                               GlobalSettings.Longitude ?? 0,
                                                                               0.5,
                                                                               pageNumber,
                                                                               pageSize);

                            var series = tuple.Item2;
                            if (series != null && series.Any())
                            {
                                try
                                {
                                    foreach (var s in series)
                                    {
                                        if (!(this.Terminals?.Select(s => s.Id).Contains(s.Id) ?? false))
                                        {
                                            this.Terminals?.Add(s);
                                        }
                                    }
                                }
                                catch (Exception) { }
                            }
                            else
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });

            //选择
            this.WhenAnyValue(x => x.Selecter)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                Filter.SerchKey = "";
                await _navigationService.GoBackAsync(("Filter", Filter), ("Terminaler", item));
            })
            .DisposeWith(DeactivateWith);


            this.BindBusyCommand(Load);
        }
コード例 #4
0
        public CurrentCustomerPageViewModel(INavigationService navigationService,
                                            IProductService productService,
                                            IUserService userService,
                                            ITerminalService terminalService,
                                            IWareHousesService wareHousesService,
                                            IAccountingService accountingService,
                                            IDialogService dialogService,
                                            ILiteDbService <VisitStore> conn) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "拜访选择终端客户";
            _conn = conn;

            this.PageSize = 20;


            //搜索(默认触发Load)
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Skip(1)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //片区选择
            this.WhenAnyValue(x => x.Filter.DistrictId)
            .Where(s => s > 0)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //距离排序
            this.WhenAnyValue(x => x.Filter.DistanceOrderBy)
            .Where(s => s > 0)
            .Select(s => s)
            .Skip(1)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //加载数据
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    System.Diagnostics.Debug.Print("----------------------CurrentCustomerPageViewModel----------------------------->");

                    //重载时排它
                    ItemTreshold = 1;

                    try
                    {
                        if (Terminals != null && Terminals.Any())
                        {
                            Terminals?.Clear();
                        }
                    }
                    catch (Exception) { }

                    PageCounter  = 0;
                    itemTreshold = true;

                    DataVewEnable  = false;
                    NullViewEnable = true;

                    this.Longitude = GlobalSettings.Longitude ?? 0;
                    this.Latitude  = GlobalSettings.Latitude ?? 0;

                    string searchStr    = Filter?.SerchKey;
                    int?districtId      = Filter?.DistrictId;
                    int?channelId       = Filter?.ChannelId;
                    int?businessUserId  = Filter?.BusinessUserId;
                    int?rankId          = Filter?.RankId;
                    int pageNumber      = 0;
                    int pageSize        = PageSize;
                    int?lineTierId      = Filter?.LineId;
                    int distanceOrderBy = Filter.DistanceOrderBy;

                    var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                       districtId,
                                                                       channelId,
                                                                       rankId,
                                                                       lineTierId,
                                                                       businessUserId,
                                                                       true,
                                                                       distanceOrderBy,
                                                                       GlobalSettings.Latitude ?? 0,
                                                                       GlobalSettings.Longitude ?? 0,
                                                                       1.5,
                                                                       pageNumber,
                                                                       pageSize);


                    var series = tuple.Item2;
                    if (series != null && series.Any())
                    {
                        this.Terminals = new AsyncObservableCollection <TerminalModel>(series);
                    }
                    else
                    {
                        ItemTreshold = -1;
                    }

                    itemTreshold = false;
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    DataVewEnable  = true;
                    NullViewEnable = false;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1 || itemTreshold)
                {
                    return;
                }

                try
                {
                    itemTreshold = true;
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            string searchStr    = Filter?.SerchKey;
                            int?districtId      = Filter?.DistrictId;
                            int?channelId       = Filter?.ChannelId;
                            int?businessUserId  = Filter?.BusinessUserId;
                            int?rankId          = Filter?.RankId;
                            int pageNumber      = pageIdex;
                            int pageSize        = PageSize;
                            int?lineTierId      = Filter?.LineId;
                            int distanceOrderBy = Filter.DistanceOrderBy;

                            var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                               districtId,
                                                                               channelId,
                                                                               rankId,
                                                                               lineTierId,
                                                                               businessUserId,
                                                                               true,
                                                                               distanceOrderBy,
                                                                               GlobalSettings.Latitude ?? 0,
                                                                               GlobalSettings.Longitude ?? 0,
                                                                               1.5,
                                                                               pageNumber,
                                                                               pageSize);

                            var series = tuple.Item2;
                            if (series != null && series.Any())
                            {
                                try
                                {
                                    foreach (var s in series)
                                    {
                                        if (!(this.Terminals?.Select(s => s.Id).Contains(s.Id) ?? true))
                                        {
                                            this.Terminals?.Add(s);
                                        }
                                    }
                                }
                                catch (Exception) { }
                                itemTreshold = false;
                            }
                            else
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });


            //线路选择
            this.LineSelected = ReactiveCommand.Create <object>(async e => await SelectUserLine((data) =>
            {
                if (data != null)
                {
                    Filter.LineId   = data.Id;
                    Filter.LineName = data.Name;
                    if (Filter.LineId > 0)
                    {
                        var dts = data.Terminals;
                        if (dts != null && dts.Any())
                        {
                            var series = dts.OrderByDescending(t => t.Id);

                            series?.ToList().ForEach(s =>
                            {
                                s.RankName = string.IsNullOrEmpty(s.RankName) ? "A级" : s.RankName;
                                s.Distance = MapHelper.CalculateDistance(GlobalSettings.Latitude ?? 0, GlobalSettings.Longitude ?? 0, s.Location_Lat ?? 0, s.Location_Lng ?? 0);
                            });

                            if (series.Count() > 0)
                            {
                                Terminals = new AsyncObservableCollection <TerminalModel>(series);
                                MessageBus.Current.SendMessage(Terminals, Constants.TRACKTERMINALS_KEY);
                            }
                        }
                    }
                }
            }, Filter.LineId));

            //打开导航
            this.OpenNavigationToCommand = ReactiveCommand.Create <TerminalModel>(e =>
            {
                try
                {
                    var _baiduLocationService = App.Resolve <IBaiduNavigationService>();
                    _baiduLocationService?.OpenNavigationTo(e.Location_Lat ?? 0, e.Location_Lng ?? 0, e.Address);
                }
                catch (Exception)
                {
                    _dialogService.LongAlert("没有安装导航软件");
                }
            });

            //距离排序
            this.DistanceOrderCommand = ReactiveCommand.Create <int>(e =>
            {
                if (!OrderByDistance)
                {
                    this.OrderByDistance        = true;
                    this.Filter.DistanceOrderBy = 1;
                }
                else
                {
                    this.OrderByDistance        = false;
                    this.Filter.DistanceOrderBy = 2;
                }
            });

            //片区选择
            this.DistrictSelected = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("SelectAreaPage", null));

            //附近客户
            this.OtherCustomerCommand = ReactiveCommand.Create <object>(e =>
            {
                if (this.MapVewEnable == false)
                {
                    Title = "附近客户";
                    this.ListVewEnable = false;
                    this.MapVewEnable  = true;
                    Filter.LineId      = 0;
                    ((ICommand)RefreshCommand)?.Execute(null);
                }
                else
                {
                    Title = "选择客户";
                    this.ListVewEnable = true;
                    this.MapVewEnable  = false;
                }
            });

            //添加客户
            this.AddCustomerCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("AddCustomerPage"));

            //客户选择
            this.WhenAnyValue(x => x.Selecter)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                await this.NavigateAsync("VisitStorePage", ("Terminaler", item));
                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);


            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.NEARCUSTOMER, (m, vm) => {
                      if (this != null)
                      {
                          Title         = "附近客户";
                          Filter.LineId = 0;
                          ((ICommand)RefreshCommand)?.Execute(null);
                      }
                  } },
                //清空单据
                { MenuEnum.LINESELECT, (m, vm) => {
                      if (this != null)
                      {
                          ((ICommand)LineSelected)?.Execute(null);
                      }
                  } }
            });

            this.BindBusyCommand(Load);
        }
コード例 #5
0
        public VisitRecordsPageViewModel(INavigationService navigationService,
                                         ITerminalService terminalService,
                                         IDialogService dialogService) : base(navigationService, dialogService)
        {
            Title = "业务员拜访记录";

            _terminalService = terminalService;

            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    //重载时排它
                    ItemTreshold = 1;
                    Terminals?.Clear();

                    DataVewEnable  = false;
                    NullViewEnable = true;

                    int?terminalId = Filter?.TerminalId ?? 0;
                    int?districtId = Filter?.DistrictId ?? 0;

                    int?businessUserId = Settings.UserId;
                    if (Filter?.BusinessUserId > 0)
                    {
                        businessUserId = Filter?.BusinessUserId;
                    }

                    DateTime start = Filter.StartTime ?? DateTime.Now.AddDays(-30);
                    DateTime end   = Filter.EndTime ?? DateTime.Now;

                    //清除列表
                    VisitStores?.Clear();

                    var items = await _terminalService.GetVisitStoresAsync(terminalId,
                                                                           districtId,
                                                                           businessUserId,
                                                                           start,
                                                                           end,
                                                                           0,
                                                                           PageSize,
                                                                           this.ForceRefresh,
                                                                           new System.Threading.CancellationToken());

                    if (items != null)
                    {
                        var pending = items.ToList();
                        pending.ForEach(v =>
                        {
                            v.DoorheadPhoto = v.DoorheadPhotos.FirstOrDefault()?.StoragePath;

                            var tts = v.SignOutDateTime.Subtract(v.SigninDateTime).TotalSeconds;
                            v.OnStoreStopSeconds    = (int)tts;
                            v.OnStoreStopSecondsFMT = CommonHelper.ConvetToSeconds((int)tts);
                            v.SaleAmount ??= 0;
                            v.FaceImage = string.IsNullOrEmpty(v.FaceImage) ? "profile_placeholder.png" : v.FaceImage;
                        });

                        this.TotalOnTime = pending.Select(v => v.SignOutDateTime.Subtract(v.SigninDateTime).Minutes).Sum();
                        this.TotalAmount = pending.Select(v => v.SaleAmount).Sum();

                        foreach (var group in pending.GroupBy(s => s.BusinessUserId))
                        {
                            var firs = group.FirstOrDefault();
                            VisitStores.Add(new VisitStoreGroup(firs?.BusinessUserName, firs.FaceImage, group.ToList()));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    NullViewEnable = false;
                    DataVewEnable  = true;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1)
                {
                    return;
                }
                try
                {
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            try
                            {
                                int?terminalId     = Filter?.TerminalId ?? 0;
                                int?districtId     = Filter?.DistrictId ?? 0;
                                int?businessUserId = Filter?.BusinessUserId ?? 0;
                                DateTime start     = Filter.StartTime ?? DateTime.Now;
                                DateTime end       = Filter.EndTime ?? DateTime.Now;

                                //清除列表
                                VisitStores?.Clear();

                                var items = await _terminalService.GetVisitStoresAsync(terminalId,
                                                                                       districtId,
                                                                                       businessUserId,
                                                                                       start,
                                                                                       end,
                                                                                       pageIdex,
                                                                                       PageSize,
                                                                                       this.ForceRefresh,
                                                                                       new System.Threading.CancellationToken());

                                if (items != null)
                                {
                                    var pending = items.ToList();
                                    pending.ForEach(v =>
                                    {
                                        var tts                 = v.SignOutDateTime.Subtract(v.SigninDateTime).TotalSeconds;
                                        v.DoorheadPhoto         = v.DoorheadPhotos.FirstOrDefault()?.StoragePath;
                                        v.OnStoreStopSeconds    = (int)tts;
                                        v.OnStoreStopSecondsFMT = CommonHelper.ConvetToSeconds((int)tts);
                                        v.SaleAmount ??= 0;
                                        v.FaceImage = string.IsNullOrEmpty(v.FaceImage) ? "profile_placeholder.png" : v.FaceImage;
                                    });

                                    this.TotalOnTime = pending.Select(v => v.SignOutDateTime.Subtract(v.SigninDateTime).Minutes).Sum();
                                    this.TotalAmount = pending.Select(v => v.SaleAmount).Sum();

                                    foreach (var group in pending.GroupBy(s => s.BusinessUserId))
                                    {
                                        var firs = group.FirstOrDefault();
                                        VisitStores.Add(new VisitStoreGroup(firs?.BusinessUserName, firs.FaceImage, group.ToList()));
                                    }
                                }

                                if (items.Count() == 0 || items.Count() == VisitStores.Count)
                                {
                                    ItemTreshold = -1;
                                }
                            }
                            catch (Exception ex)
                            {
                                Crashes.TrackError(ex);
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });


            //预览照片
            this.PhotoCommand = ReactiveCommand.Create <string>(async item =>
            {
                if (item != null)
                {
                    var images = new List <string>()
                    {
                        item
                    };
                    await this.NavigateAsync("ImageViewerPage", ("ImageInfos", images));
                }
            });

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //TODAY
                { MenuEnum.TODAY, (m, vm) => {
                      Filter.StartTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
                      Filter.EndTime   = DateTime.Now;
                      ((ICommand)Load)?.Execute(null);
                  } },
                //YESTDAY
                { MenuEnum.YESTDAY, (m, vm) => {
                      Filter.StartTime = DateTime.Now.AddDays(-1);
                      Filter.EndTime   = DateTime.Now;
                      ((ICommand)Load)?.Execute(null);
                  } },
                //MONTH
                { MenuEnum.MONTH, (m, vm) => {
                      Filter.StartTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01 00:00:00"));
                      Filter.EndTime   = DateTime.Now;
                      ((ICommand)Load)?.Execute(null);
                  } },
                //THISWEEBK
                { MenuEnum.THISWEEBK, (m, vm) => {
                      Filter.StartTime = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek);
                      Filter.EndTime   = DateTime.Now;
                      ((ICommand)Load)?.Execute(null);
                  } },
                //OTHER
                { MenuEnum.OTHER, (m, vm) => {
                      SelectDateRang(true);
                  } }
            });

            this.BindBusyCommand(Load);
        }
コード例 #6
0
        public CustomerArchivesPageViewModel(INavigationService navigationService,
                                             IProductService productService,
                                             IUserService userService,
                                             ITerminalService terminalService,
                                             IWareHousesService wareHousesService,
                                             IAccountingService accountingService,
                                             IDialogService dialogService,
                                             ILiteDbService <VisitStore> conn) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "客户档案";
            _conn = conn;

            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Skip(1)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null)).DisposeWith(DeactivateWith);

            //片区选择
            this.WhenAnyValue(x => x.Filter.DistrictId)
            .Where(s => s > 0)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //加载数据
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    //重载时排它
                    ItemTreshold = 1;
                    Terminals?.Clear();

                    DataVewEnable  = false;
                    NullViewEnable = true;

                    string searchStr    = Filter?.SerchKey;
                    int?districtId      = Filter?.DistrictId;
                    int?channelId       = Filter?.ChannelId;
                    int?businessUserId  = Filter?.BusinessUserId;
                    int?rankId          = Filter?.RankId;
                    int pageNumber      = 0;
                    int pageSize        = PageSize;
                    int?lineTierId      = Filter?.LineId;
                    int distanceOrderBy = Filter.DistanceOrderBy;

                    var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                       districtId,
                                                                       channelId,
                                                                       rankId,
                                                                       lineTierId,
                                                                       businessUserId,
                                                                       true,
                                                                       distanceOrderBy,
                                                                       0,
                                                                       0,
                                                                       0,
                                                                       pageIndex: pageNumber,
                                                                       pageSize: pageSize);

                    var series = tuple.Item2;
                    Title      = $"客户档案({tuple.Item1})家";

                    if (series != null && series.Any())
                    {
                        this.Terminals = new AsyncObservableCollection <TerminalModel>(series);
                    }
                    else
                    {
                        ItemTreshold = -1;
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    NullViewEnable = false;
                    DataVewEnable  = true;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1)
                {
                    return;
                }

                try
                {
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            string searchStr    = Filter?.SerchKey;
                            int?districtId      = Filter?.DistrictId;
                            int?channelId       = Filter?.ChannelId;
                            int?businessUserId  = Filter?.BusinessUserId;
                            int?rankId          = Filter?.RankId;
                            int pageNumber      = pageIdex;
                            int pageSize        = PageSize;
                            int?lineTierId      = Filter?.LineId;
                            int distanceOrderBy = Filter.DistanceOrderBy;

                            //string searchStr = "", int? districtId = 0, int? channelId = 0, int? rankId = 0, int? lineId = 0, int? businessUserId = 0, bool status = true, int distanceOrderBy = 0, double lat = 0, double lng = 0, double range = 1.5, int pageIndex = 0, int pageSize = 20
                            var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                               districtId,
                                                                               channelId,
                                                                               rankId,
                                                                               lineTierId,
                                                                               businessUserId,
                                                                               true,
                                                                               distanceOrderBy,
                                                                               0,
                                                                               0,
                                                                               0,
                                                                               pageIndex: pageNumber,
                                                                               pageSize: pageSize);

                            var series = tuple.Item2;
                            if (series != null && series.Any())
                            {
                                foreach (var s in series)
                                {
                                    if (!(this.Terminals?.Select(s => s.Id).Contains(s.Id) ?? false))
                                    {
                                        this.Terminals?.Add(s);
                                    }
                                }
                            }
                            else
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });

            //打开导航
            this.OpenNavigationToCommand = ReactiveCommand.Create <TerminalModel>(e =>
            {
                try
                {
                    if (e != null)
                    {
                        var _baiduLocationService = App.Resolve <IBaiduNavigationService>();
                        _baiduLocationService?.OpenNavigationTo(e.Location_Lat ?? 0, e.Location_Lng ?? 0, e.Address);
                    }
                }
                catch (Exception)
                {
                    _dialogService.LongAlert("没有安装导航软件");
                }
            });

            //编辑客户
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                if (item != null)
                {
                    await this.NavigateAsync("AddCustomerPage", ("Terminaler", item), ("Edit", true));
                }
                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);

            //添加客户
            this.AddCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("AddCustomerPage", ("Edit", false)));

            //员工选择
            this.BusinessSelected = ReactiveCommand.Create <object>(async e =>
            {
                await SelectUser((data) =>
                {
                    if (data != null)
                    {
                        Filter.BusinessUserId   = data.Id;
                        Filter.BusinessUserName = data.Column;
                        ((ICommand)Load)?.Execute(null);
                    }
                }, Enums.UserRoleType.Employees);
            });
            this.BindBusyCommand(Load);
        }