using BBWY.Client.APIServices; using BBWY.Client.Models.APIModel.Response.PackTask; using BBWY.Client.Models; using BBWY.Client.Views.PackTask; using BBWY.Common.Models; using BBWY.Controls; using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Linq; using System.Windows.Controls; using System.ComponentModel; using HandyControl.Controls; using System.Windows; using System.Collections; using NPOI.SS.Formula.Functions; using GalaSoft.MvvmLight.Messaging; using BBWY.Client.Models.APIModel; using BBWY.Client.Models.PackTask; using BBWY.Client.Views.SealBox; using BBWY.Client.Views.FallWare; using BBWY.Client.Models.FallWare; using WebSocketSharp; using System.Threading; using BBWY.Client.Helpers; using System.Diagnostics.Eventing.Reader; namespace BBWY.Client.ViewModels.PackTask { public partial class WareHouseListViewModel : BaseVM, IDenpendency//注入服务 { //public RelayCommand SelectCmd => new RelayCommand(str => Growl.Info(str)); #region 属性绑定 /// /// 查询时间段 /// private DateTime startTime; public DateTime StartTime { get => startTime; set { Set(ref startTime, value); } } private DateTime endTime; public DateTime EndTime { get => endTime; set { Set(ref endTime, value); } } public IList OverTimeTaskResponses { get; set; } private ObservableCollection overTimeTaskList; /// /// 超时任务列表 /// public ObservableCollection OverTimeTaskList { get => overTimeTaskList; set { Set(ref overTimeTaskList, value); } } private ObservableCollection overTimeTaskTypeList = new ObservableCollection { OverTimeTaskType.全部, OverTimeTaskType.待验收, OverTimeTaskType.待打包, OverTimeTaskType.待封箱, OverTimeTaskType.待落仓, OverTimeTaskType.待转运 }; /// ///超时任务类型 /// public ObservableCollection OverTimeTaskTypeList { get => overTimeTaskTypeList; set { Set(ref overTimeTaskTypeList, value); } } private OverTimeTaskType overTimeTaskState = OverTimeTaskType.全部; /// /// 任务类型(超时) /// public OverTimeTaskType OverTimeTaskState { get => overTimeTaskState; set { Set(ref overTimeTaskState, value); } } private string waitTransportJDWareCount; public string WaitTransportJDWareCount { get => waitTransportJDWareCount; set { Set(ref waitTransportJDWareCount, value); } } private string waitTransportCloudWareCount; public string WaitTransportCloudWareCount { get => waitTransportCloudWareCount; set { Set(ref waitTransportCloudWareCount, value); } } private string waitTransportJuShuiTanCount; public string WaitTransportJuShuiTanCount { get => waitTransportJuShuiTanCount; set { Set(ref waitTransportJuShuiTanCount, value); } } private string waitTransportStoreWareCount; public string WaitTransportStoreWareCount { get => waitTransportStoreWareCount; set { Set(ref waitTransportStoreWareCount, value); } } private string searchWayBillNo; public string SearchWayBillNo { get => searchWayBillNo; set { Set(ref searchWayBillNo, value); } } private string searchExpressName; public string SearchExpressName { get => searchExpressName; set { Set(ref searchExpressName, value); } } public string fallWareWaitConfigureCount; public string FallWareWaitConfigureCount { get => fallWareWaitConfigureCount; set { Set(ref fallWareWaitConfigureCount, value); } } public string fallWareConfiguredCount; public string FallWareConfiguredCount { get => fallWareConfiguredCount; set { Set(ref fallWareConfiguredCount, value); } } private ObservableCollection waitCompletedList; /// /// 待完结列表 /// public ObservableCollection WaitCompletedList { get => waitCompletedList; set { Set(ref waitCompletedList, value); } } private ObservableCollection waitTransportList; /// /// 待转运列表 /// public ObservableCollection WaitTransportList { get => waitTransportList; set { Set(ref waitTransportList, value); } } private ObservableCollection waitFallWareList; /// /// 待落仓列表 /// public ObservableCollection WaitFallWareList { get => waitFallWareList; set { Set(ref waitFallWareList, value); } } private ObservableCollection wareNoSealBoxModels; /// /// 分箱列表(未配置) /// public ObservableCollection WareNoSealBoxModels { get => wareNoSealBoxModels; set { Set(ref wareNoSealBoxModels, value); } } private ObservableCollection waitSealBoxModels; /// /// 分箱列表(已配置) /// public ObservableCollection WaitSealBoxModels { get => waitSealBoxModels; set { Set(ref waitSealBoxModels, value); } } private ObservableCollection packTaskList; /// /// 打包任务列表 /// public ObservableCollection PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } } private string searchShopName; public string SearchShopName { get => searchShopName; set { Set(ref searchShopName, value); } } /// /// 查询任务id /// private string searchTaskId; public string SearchTaskId { get => searchTaskId; set { Set(ref searchTaskId, value); } } /// /// 查询Sku /// private string searchSkuId; public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } } private TaskState? taskState; /// /// 任务状态 /// public TaskState? TaskState { get => taskState; set { Set(ref taskState, value); } } private int pageIndex = 1; private int pageSize = 10; private int orderCount;//总数量 private Visibility tipVisitity; /// /// /// public Visibility TipVisitity { get => tipVisitity; set { Set(ref tipVisitity, value); } } /// /// 未到货数量 /// public string NoArrivedCount { get => noArrivedCount; set { Set(ref noArrivedCount, value); } } private string noArrivedCount; private string someArrivedCount; /// /// 部分到货数量 /// public string SomeArrivedCount { get => someArrivedCount; set { Set(ref someArrivedCount, value); } } private string worryCount; /// /// 加急数 /// public string WorryCount { get => worryCount; set { Set(ref worryCount, value); } } private string arrivedCount; /// /// 已到货数量 /// public string ArrivedCount { get => arrivedCount; set { Set(ref arrivedCount, value); } } private string waitPackCount; /// /// 待打包任务数 /// public string WaitPackCount { get => waitPackCount; set { Set(ref waitPackCount, value); } } private string waitSealBoxCount; /// /// 带封箱任务数 /// public string WaitSealBoxCount { get => waitSealBoxCount; set { Set(ref waitSealBoxCount, value); } } private string waitFallWareCount; /// /// 待落仓任务数 /// public string WaitFallWareCount { get => waitFallWareCount; set { Set(ref waitFallWareCount, value); } } private string waitOutbound; /// /// 待出库任务数 /// public string WaitOutbound { get => waitOutbound; set { Set(ref waitOutbound, value); } } private string waitCompleted; /// /// 待完成任务数 /// public string WaitCompleted { get => waitCompleted; set { Set(ref waitCompleted, value); } } private string waitTransportCount; /// /// 待转运 /// public string WaitTransportCount { get => waitTransportCount; set { Set(ref waitTransportCount, value); } } public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } } public int PageSize { get => pageSize; set { Set(ref pageSize, value); } } public int OrderCount { get => orderCount; set { Set(ref orderCount, value); } } private bool isLoading; public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } public string searchDepartment; public string SearchDepartment { get => searchDepartment; set { Set(ref searchDepartment, value); } } private SealBoxConfigureType sealBoxConfigureType; /// /// 封箱配置状态 /// public SealBoxConfigureType SealBoxConfigureType { get => sealBoxConfigureType; set { Set(ref sealBoxConfigureType, value); } } private WareType selectWareType; public WareType SelectWareType { get => selectWareType; set { Set(ref selectWareType, value); } } #endregion private readonly PackTaskService packTaskService; private readonly SealBoxService sealBoxService; public GlobalContext globalContext; public WareHouseListViewModel(PackTaskService packTaskService, GlobalContext globalContext, SealBoxService sealBoxService) { this.globalContext = globalContext; this.sealBoxService = sealBoxService; this.packTaskService = packTaskService; //Messenger.Default.Send(globalContext, "AcceptGlobalContext"); PackTaskList = new ObservableCollection();//初始化数据 SetTaskStateCommand = new RelayCommand(SetTaskState); SearchTaskCommand = new RelayCommand(() => { SearchTaskList(); //手动点击查询订单 }); TaskPageIndexChangedCommand = new RelayCommand(p => { LoadIndex(p.PageIndex); }); OpenSkuDetailCommand = new RelayCommand(OpenSkuDetail); StartTime = DateTime.Now.Date; EndTime = DateTime.Now.Date; IsLoading = false; TaskState = null; //加载数据 SelectWareType = WareType.云仓; SetTaskState(null); UpdateTaskStateCommand = new RelayCommand(UpdateTaskState); CompeteSealBoxCommand = new RelayCommand(CompeteSealBox); SetSealBoxCommand = new RelayCommand(SetSealBox); CompeteFallWareCommand = new RelayCommand(CompeteFallWare); SealBoxConfigureType = SealBoxConfigureType.待配置; PositionState = PositionState.待落仓; SetSealBoxConfigureTypeCommand = new RelayCommand(s => { SealBoxConfigureType = s; PositionState = s == SealBoxConfigureType.已配置 ? PositionState.已配置待落仓 : PositionState.待落仓; SearchTaskList(); }); LookBoxConfigureCommand = new RelayCommand(LookBoxConfigure); PrintBoxConfigureCommand = new RelayCommand(PrintBoxConfigure); DeletedTaskCommand = new RelayCommand(DeletedTask); StoreGetBySelfCommand = new RelayCommand(StoreGetBySelf); CompletedPackTaskCommand = new RelayCommand(CompletedPackTask); SetWareTypeCommand = new RelayCommand(s => { SelectWareType = s; SearchTaskList(); }); CompeteWaitTransportCommand = new RelayCommand(CompeteWaitTransport); CompeteWaitCompletedCommand = new RelayCommand(CompeteWaitCompleted); } private void CompeteWaitCompleted(object obj) { var model = (WareWaitCompleted)obj; if (System.Windows.MessageBox.Show("是否完成任务?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; var res = sealBoxService.WareCompetedWaitCompleted(model.SealBoxId); if (res == null) { return; } if (!res.Success) { System.Windows.MessageBox.Show(res.Msg); return; } Task.Factory.StartNew(() => SearchTaskList()); } private void CompeteWaitTransport(object obj) { var model = (WareWaitTransport)obj; if (System.Windows.MessageBox.Show("是否完成转运?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; var res = sealBoxService.WareCompeteTransport(model.SealBoxId); if (res == null) { return; } if (!res.Success) { System.Windows.MessageBox.Show(res.Msg); return; } Task.Factory.StartNew(() => SearchTaskList()); } private void CompletedPackTask(object obj) { var model = (PackTaskModel)obj; if (model == null || model.FeesItemResponse == null || model.FeesItemResponse.DiscountAllFees == 0) { System.Windows.MessageBox.Show("请先设置打包费用!"); return; } if (System.Windows.MessageBox.Show("是否完成打包?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; var res = packTaskService.CompletedPackTask(model.TaskId); if (res == null) { return; } if (!res.Success) { System.Windows.MessageBox.Show(res.Msg); return; } Task.Factory.StartNew(() => SearchTaskList()); } private void StoreGetBySelf(long taskId) { MessageBoxResult result = System.Windows.MessageBox.Show($"确定商家自取,任务id:{taskId}?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) return; var res = packTaskService.StoreGetBySelf(taskId); if (res == null) { return; } if (!res.Success) { System.Windows.MessageBox.Show(res.Msg, "错误信息"); return; } Task.Factory.StartNew(() => SearchTaskList()); } private void DeletedTask(object obj) { var packTaskmodel = (PackTaskModel)obj; //if (!packTaskmodel.OrderId.IsNullOrEmpty()) //{ // System.Windows.MessageBox.Show($"暂不支持删除采购组的任务,如要删除,请到采购列表取消订单:{packTaskmodel.OrderId}"); // return; //} MessageBoxResult result = System.Windows.MessageBox.Show($"确定取消任务{packTaskmodel.TaskId}?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) return; packTaskService.DeletedTask(packTaskmodel.TaskId); Task.Factory.StartNew(() => SearchTaskList()); } /// /// todo: 打印数据 /// /// private void PrintBoxConfigure(object obj) { var fallware = obj as WaitFallWareModel; JDWareBoxModel model = new JDWareBoxModel { ShopName = globalContext.User.Shop.ShopName, WareName = fallware.WareName, SealBoxId = fallware.SealBoxId, ProductCount = fallware.ProductCount, BoxCount = fallware.SealBoxCount, PrewOrder = fallware.BoxConfigureData.PrewOrder, ProductTitle = fallware.BoxConfigureData.ProductTitle, PurchaseOrder = fallware.BoxConfigureData.PurchaseOrder, WaybillNo = fallware.BoxConfigureData.WaybillNo }; if (fallware.WareType == WareType.京仓) { //加载模板数据 } if (fallware.WareType == WareType.云仓) { } //打印 } private void LookBoxConfigure(object obj) { var fallware = obj as WaitFallWareModel; JDWareBoxModel model = new JDWareBoxModel { ShopName = globalContext.User.Shop.ShopName, WareName = fallware.WareName, SealBoxId = fallware.SealBoxId, ProductCount = fallware.ProductCount, BoxCount = fallware.SealBoxCount, PrewOrder = fallware.BoxConfigureData.PrewOrder, ProductTitle = fallware.BoxConfigureData.ProductTitle, PurchaseOrder = fallware.BoxConfigureData.PurchaseOrder, WaybillNo = fallware.BoxConfigureData.WaybillNo, ProviderName = fallware.BoxConfigureData.ProviderName }; if (fallware.WareType == WareType.京仓) { SetJDWareBoxWindow window = new SetJDWareBoxWindow(model, sealBoxService, fallware.WareType, ReflashTask, false); window.Show(); //var w = new SetJDWareBoxWindow2(model, sealBoxService, fallware.WareType, ReflashTask, false); //w.ShowDialog(); } if (fallware.WareType == WareType.云仓 || fallware.WareType == WareType.聚水潭齐越仓) { SetCloudWareBoxWindow window = new SetCloudWareBoxWindow(model, sealBoxService, fallware.WareType, ReflashTask, false); window.Show(); } } public PositionState PositionState { get; set; } /// /// 完成落仓(todo:) /// /// private void CompeteFallWare(object obj) { if (System.Windows.MessageBox.Show("是否完成落仓?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; var model = obj as WaitFallWareModel; var res = sealBoxService.WareCompeteFallWare(model.SealBoxId); if (res != null && res.Success) { ReflashTask(); return; } if (res == null) { System.Windows.MessageBox.Show("网络异常"); return; } System.Windows.MessageBox.Show(res.Msg); } private void SetSealBox(object obj) { var model = (SealBoxModel)obj; if (model.SealBoxSkus.Any(s => s.TaskState == Models.TaskState.待验收 || s.TaskState == Models.TaskState.待打包)) { System.Windows.MessageBox.Show("无法封箱,存在未打包完成的任务"); return; } SetSealBoxWindow setSealBoxWindow = new SetSealBoxWindow(model); setSealBoxWindow.SendBoxCount = boxCount => { model.SealBoxCount = boxCount; }; setSealBoxWindow.ShowDialog(); } #region 事件绑定 /// /// 待完结 完成事件 /// public ICommand CompeteWaitCompletedCommand { get; set; } /// /// 待转运 完成事件 /// public ICommand CompeteWaitTransportCommand { get; set; } /// /// 设置仓库类型 /// public ICommand SetWareTypeCommand { get; set; } /// /// 查看箱唛配置 /// public ICommand LookBoxConfigureCommand { get; set; } /// /// 待配置 /已配置 /// public ICommand SetSealBoxConfigureTypeCommand { get; set; } public ICommand CompeteFallWareCommand { get; set; } public ICommand CompeteSealBoxCommand { get; set; } public ICommand CompletedPackTaskCommand { get; set; } /// /// 打开图片链接 /// public ICommand OpenSkuDetailCommand { get; set; } /// /// 筛选数据 /// public ICommand SetTaskStateCommand { get; set; } /// /// 修改任务状态 /// public ICommand UpdateTaskStateCommand { get; set; } /// /// 搜索数据 /// public ICommand SearchTaskCommand { get; set; } /// /// 创建任务 /// public ICommand CreateTaskCommand { get; set; } /// /// 页面改变事件 /// public ICommand TaskPageIndexChangedCommand { get; set; } /// /// 设置分箱数量 /// public ICommand SetSealBoxCommand { get; set; } /// /// 打印封箱数据 /// public ICommand PrintBoxConfigureCommand { get; set; } /// /// 删除任务 /// public ICommand DeletedTaskCommand { get; set; } /// /// 商家自取 /// public ICommand StoreGetBySelfCommand { get; set; } /// /// 完成封箱 /// /// private void CompeteSealBox(object obj) { var model = (SealBoxModel)obj; if (model.SealBoxCount == null || model.SealBoxCount.Value <= 0) { System.Windows.MessageBox.Show("请先设置封箱数量"); return; } var res = sealBoxService.WareCompeteSealBox(model.SealBoxId, model.SealBoxCount); if (res == null) { System.Windows.MessageBox.Show("网络异常", ""); return; } if (!res.Success || !res.Data) { System.Windows.MessageBox.Show(res.Msg); return; } SearchTaskList(); } private void UpdateTaskState(object obj) { var model = (PackTaskModel)obj; long taskId = model.TaskId; var packTaskState = model.TaskState; ApiResponse res = null; switch (packTaskState) { case Models.TaskState.未到货: case Models.TaskState.部分到货: if (System.Windows.MessageBox.Show("是否确认收货?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; res = packTaskService.SetPackTaskState(taskId, Models.TaskState.待验收); break; case Models.TaskState.待验收: break; case Models.TaskState.待打包: var packModel = PackTaskList.SingleOrDefault(p => p.TaskId == taskId); if (packModel == null || packModel.FeesItemResponse == null || packModel.FeesItemResponse.DiscountAllFees == 0) { System.Windows.MessageBox.Show("请先设置打包费用!"); return; } if (System.Windows.MessageBox.Show("是否完成打包?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) return; res = packTaskService.SetPackTaskState(taskId, Models.TaskState.待封箱); break; case Models.TaskState.待封箱: break; case Models.TaskState.待出库: break; case Models.TaskState.已完成: break; case Models.TaskState.已取消: break; default: break; } if (res != null && res.Success) { SearchTaskList(); } } public void SetTaskState(TaskState? taskState) { TaskState = taskState; if (PageIndex == 1) SearchTaskList(); else PageIndex = 1; } private bool IsStartThread = false; private Thread qualityOverTimeThread = null; private Thread packOverTimeThread = null; private Thread sealboxOverTimeThread = null; private Thread fallwareOverTimeThread = null; private Thread waitTransportOverTimeThread = null; /// /// 搜索任务列表 /// public void SearchTaskList() { PageSize = 10; IsStartThread = false; long? taskId = null; try { if (SearchTaskId != null && !string.IsNullOrEmpty(SearchTaskId.Trim())) taskId = Convert.ToInt64(SearchTaskId); } catch { taskId = null; } IsLoading = true; if (TaskState == Models.TaskState.待出库) { Task.Factory.StartNew(() => { WaitCompletedList = new ObservableCollection(); var datas = sealBoxService.GetWareWaitCompletedList(null, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.WareWaitCompleteds) { App.Current.Dispatcher.BeginInvoke(new Action(() => { WaitCompletedList.Add(item); })); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } IsLoadCount(); IsLoading = false; }); } else if (TaskState == Models.TaskState.已超时) { PageSize = 20; Task.Factory.StartNew(() => { OverTimeTaskList = new ObservableCollection(); var datas = packTaskService.SearchOverTimeTaskList(null, StartTime, EndTime, OverTimeTaskState, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.OverTimeTaskResponses) { App.Current.Dispatcher.BeginInvoke(new Action(() => { OverTimeTaskList.Add(item); })); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } IsLoadCount(); IsLoading = false; }); } else if (TaskState == Models.TaskState.待转运) { Task.Factory.StartNew(() => { WaitTransportList = new ObservableCollection(); var datas = sealBoxService.GetWareWaitTransportList(SelectWareType, PageSize, PageIndex); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.WareWaitTransports) { App.Current.Dispatcher.Invoke(new Action(() => { WaitTransportList.Add(item); })); } var sealboxTasks = WaitTransportList.Where(p => p.TransportOverTime != null).ToList(); if (sealboxTasks.Count() > 0 && TaskState == Models.TaskState.待转运) { waitTransportOverTimeThread = new Thread(() => { IsStartThread = true; while (IsStartThread) { App.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var item in sealboxTasks) { var datetime = item.TransportOverTime.Value.Subtract(DateTime.Now); if (datetime.TotalMilliseconds > 0) { item.IsWaitTransportOverTime = false; item.WaitTransportRemainTime = $"{datetime.Hours}小时{datetime.Minutes}分"; } else { item.IsWaitTransportOverTime = true; item.WaitTransportRemainTime = datetime.Days == 0 ? $"{-datetime.Hours}小时{-datetime.Minutes}分" : $"{-datetime.Days}天{-datetime.Hours}小时{-datetime.Minutes}分"; } } })); Thread.Sleep(1000); } }); //任务倒计时数据 waitTransportOverTimeThread.IsBackground = true; waitTransportOverTimeThread.Start(); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } IsLoadCount(); IsLoadWaitTransportCount(); IsLoading = false; }); } else if (TaskState == Models.TaskState.待落仓) Task.Factory.StartNew(() => { WaitFallWareList = new ObservableCollection(); var datas = sealBoxService.SearchWareFallWareConfigureList(PositionState, SearchShopName, taskId, SearchSkuId, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.WaitFallWareList) { App.Current.Dispatcher.Invoke(new Action(() => { WaitFallWareList.Add(new WaitFallWareModel { AcceptUserNames = string.Join("|", item.AcceptUserNames), DepartmentName = item.DepartmentName, SealBoxSkus = item.SealBoxSkus, ShopId = item.ShopId, ShopName = item.ShopName, WareId = item.WareId, WareName = item.WareName, SealBoxCount = item.SealBoxCount, SealBoxId = item.SealBoxId, BoxConfigureData = item.BoxConfigureData, ProductCount = item.ProductCount, WareType = item.WareType, SetPurchaseOrderOverTime=item.SetPurchaseOrderOverTime }); })); } var fallWareTasks = WaitFallWareList.Where(p => p.SetPurchaseOrderOverTime != null).ToList(); if (fallWareTasks.Count() > 0 && TaskState == Models.TaskState.待落仓 && SealBoxConfigureType == SealBoxConfigureType.待配置) { //if (packOverTimeThread!=null) //{ // packOverTimeThread.Abort(); //} fallwareOverTimeThread = new Thread(() => { IsStartThread = true; while (IsStartThread) { App.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var item in fallWareTasks) { var datetime = item.SetPurchaseOrderOverTime.Value.Subtract(DateTime.Now); if (datetime.TotalMilliseconds > 0) { item.IsFallWareOverTime = false; item.FallWareRemainTime = $"{datetime.Hours}小时{datetime.Minutes}分"; } else { item.IsFallWareOverTime = true; item.FallWareRemainTime = datetime.Days == 0 ? $"{-datetime.Hours}小时{-datetime.Minutes}分" : $"{-datetime.Days}天{-datetime.Hours}小时{-datetime.Minutes}分"; } } })); Thread.Sleep(1000); } }); //任务倒计时数据 fallwareOverTimeThread.IsBackground = true; fallwareOverTimeThread.Start(); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } IsLoadCount(); IsLoadFallWareCount(); IsLoading = false; }); else if (TaskState == Models.TaskState.待封箱) Task.Factory.StartNew(() => { //var randNum = new Random().Next(81, 90); var randNum = 90; if (SealBoxConfigureType == SealBoxConfigureType.已配置) { WaitSealBoxModels = new ObservableCollection(); var datas = sealBoxService.GetWareSealBoxList(SearchShopName, taskId, SearchSkuId, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.WaitSealBoxModels) { App.Current.Dispatcher.Invoke(new Action(() => { WaitSealBoxModels.Add(new SealBoxModel { AcceptUserName = string.Join("|", item.AcceptUserNames), DepartmentName = item.DepartmentName, SealBoxSkus = item.SealBoxSkus.Select(s => { s.Logo = s.Logo.Replace("80x80", $"{randNum}x{randNum}"); return s; }).ToList(), ShopId = item.ShopId, ShopName = item.ShopName, WareId = item.WareId, WareName = item.WareName, SealBoxId = item.SealBoxId, SealBoxPackOverTime = item.SealBoxPackOverTime }); })); } var sealboxTasks = WaitSealBoxModels.Where(p => p.SealBoxPackOverTime != null).ToList(); if (sealboxTasks.Count() > 0 && TaskState == Models.TaskState.待封箱) { sealboxOverTimeThread = new Thread(() => { IsStartThread = true; while (IsStartThread) { App.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var item in sealboxTasks) { var datetime = item.SealBoxPackOverTime.Value.Subtract(DateTime.Now); if (datetime.TotalMilliseconds > 0) { item.IsSealBoxOverTime = false; item.SealBoxRemainTime = $"{datetime.Hours}小时{datetime.Minutes}分"; } else { item.IsSealBoxOverTime = true; item.SealBoxRemainTime = datetime.Days == 0 ? $"{-datetime.Hours}小时{-datetime.Minutes}分" : $"{-datetime.Days}天{-datetime.Hours}小时{-datetime.Minutes}分"; } } })); Thread.Sleep(1000); } }); //任务倒计时数据 sealboxOverTimeThread.IsBackground = true; sealboxOverTimeThread.Start(); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } } if (SealBoxConfigureType == SealBoxConfigureType.待配置) { WareNoSealBoxModels = new ObservableCollection(); var datas = sealBoxService.GetWareSealBoxWaitConfigureList(SearchShopName, taskId, SearchSkuId, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.WaitSealBoxModels) { App.Current.Dispatcher.BeginInvoke(new Action(() => { WareNoSealBoxModels.Add(new WareNoSealBoxModel { AcceptUserName = string.Join("|", item.AcceptUserNames), DepartmentName = item.DepartmentName, SealBoxSkus = item.SealBoxSkus.Select(s => { s.Logo = s.Logo.Replace("80x80", $"{randNum}x{randNum}"); return s; }).ToList(), ShopId = item.ShopId, ShopName = item.ShopName, }); })); } } else { if (datas != null) System.Windows.MessageBox.Show(datas.Msg); } } IsLoadSealBoxCount(); IsLoadCount(); IsLoading = false; }); else Task.Factory.StartNew(() => { PackTaskList = new ObservableCollection();//初始化数据 var datas = packTaskService.GetWareHouseList(SearchWayBillNo, SearchExpressName, SearchDepartment, SearchSkuId, SearchTaskId, this.TaskState, SearchShopName, PageIndex, PageSize); if (datas != null && datas.Data != null && datas.Success) { var dataModel = datas.Data; OrderCount = dataModel.TotalCount; foreach (var item in dataModel.Items) { var data = new PackTaskModel() { AcceptName = item.UserName, Availability = (Availability)item.Availability, BasicPack = (BasicPack)item.BasicPack, DepartmentName = item.DepartmentName, CertificatePosition = (CertificatePosition)item.CertificatePosition, GoodsNumber = item.GoodsNumber, Increment1 = item.Increment1, ItemList = new List() { new SkuMessage { BrandName = item.BrandName, GoodsNo = item.ProductItemNum, Logo= item.Logo, SkuName = item.SkuName, SkuId = item.SkuId } }, MarkMessage = item.MarkMessage, PackType = (PackType)item.PackType, TaskState = item.TaskState, PositionType = item.PositionType, SkuCount = item.SkuCount, SkuTitle = item.SkuGoodsTitle, TaskId = item.TaskId, EndTime = item.CreateTime, OrderId = item.OrderId, SkuId = item.SkuId, SkuName = item.SkuName, FloorDragNumber = item.FloorDragNumber, QualityCompletionOverTime = item.QualityCompletionOverTime, PackCompletionOverTime = item.PackCompletionOverTime, ShopName = item.ShopName, //ExpressOrderList = item.ExpressOrderList, }; if (!item.OrderId.IsNullOrEmpty() && !item.SkuId.IsNullOrEmpty()) { var expressData = packTaskService.GetPurchaseExpressOrderList(item.OrderId, item.SkuId); if (expressData != null && expressData.Success && expressData.Data != null) { expressData.Data.ForEach(e => { e.ExpressState = ExpressOrderHelper.GetExpressStateName(e.ExpressState); }); data.ExpressOrderList = expressData.Data; } } if (item.BarCodeDTO != null && item.BarCodeDTO.Id > 0) { data.BarCodeModel = item.BarCodeDTO; } if (item.Cers != null) { data.CertificateModel = item.Cers; } data.ReflashTask = ReflashTask; if (item.FeesItemResponse != null) { data.FeesItemResponse = item.FeesItemResponse; data.FeesMoney = item.FeesItemResponse.SingleFees; data.FeesItemResponse.DiscountAllFees = item.FeesItemResponse.AllFees * item.FeesItemResponse.disCount; data.IsShowFees = data.FeesMoney > 0 ? true : false; } else { data.IsShowFees = false; } if (item.PackUserName != null && item.PackUserName.Count() > 0) { data.PackUser = string.Join("\r\n", item.PackUserName); } App.Current.Dispatcher.Invoke(new Action(() => { PackTaskList.Add(data); })); } if (TaskState == Models.TaskState.待验收) { qualityOverTimeThread = new Thread(() => { var packtasks = PackTaskList.Where(p => p.TaskState == Models.TaskState.待验收 && p.QualityCompletionOverTime != null).ToList(); if (packtasks.Count() > 0) { IsStartThread = true; while (IsStartThread) { App.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var item in packtasks) { var datetime = item.QualityCompletionOverTime.Value.Subtract(DateTime.Now); item.QualityRemainTime = OverTimeHelper.GetTimeString(datetime); if (datetime.TotalMilliseconds > 0) { item.IsQualityOverTime = false; } else { item.IsQualityOverTime = true; } } })); Thread.Sleep(1000); } } }); //任务倒计时数据 qualityOverTimeThread.IsBackground = true; qualityOverTimeThread.Start(); //任务状态为待验收 } if (TaskState == Models.TaskState.待打包) { var packCompletedTasks = PackTaskList.Where(p => p.TaskState == Models.TaskState.待打包 && p.PackCompletionOverTime != null).ToList(); if (packCompletedTasks.Count() > 0) { //if (packOverTimeThread!=null) //{ // packOverTimeThread.Abort(); //} packOverTimeThread = new Thread(() => { IsStartThread = true; while (IsStartThread) { App.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var item in packCompletedTasks) { var datetime = item.PackCompletionOverTime.Value.Subtract(DateTime.Now); if (datetime.TotalMilliseconds > 0) { item.IsPackOverTime = false; item.PackRemainTime = datetime.Days == 0 ? $"{datetime.Hours}小时{datetime.Minutes}分" : $"{datetime.Days}天{datetime.Hours}小时{datetime.Minutes}分"; } else { item.IsPackOverTime = true; item.PackRemainTime = datetime.Days == 0 ? $"{-datetime.Hours}小时{-datetime.Minutes}分" : $"{-datetime.Days}天{-datetime.Hours}小时{-datetime.Minutes}分"; } } })); Thread.Sleep(1000); } }); //任务倒计时数据 packOverTimeThread.IsBackground = true; packOverTimeThread.Start(); } } //任务状态为待打包 } else { } IsLoadCount(); IsLoading = false; }); } private void IsLoadWaitTransportCount() { var res = sealBoxService.GetWareTransportCounts(); if (res != null && res.Success && res.Data != null) { WaitTransportCloudWareCount = res.Data.WaitTransportCloudWareCount; WaitTransportJuShuiTanCount = res.Data.WaitTransportJuShuiTanCount; WaitTransportStoreWareCount = res.Data.WaitTransportStoreWareCount; WaitTransportJDWareCount = res.Data.WaitTransportJDWareCount; } } private void IsLoadSealBoxCount() { var res = sealBoxService.GetWareSealBoxConfigureCounts(); if (res != null && res.Success && res.Data != null) { FallWareWaitConfigureCount = res.Data.SealBoxWaitConfigureCount.ToString(); FallWareConfiguredCount = res.Data.SealBoxConfiguredCount.ToString(); } } private void IsLoadFallWareCount() { var res = sealBoxService.GetFallWareConfigureCounts(null); if (res != null && res.Success && res.Data != null) { FallWareWaitConfigureCount = res.Data.FallWareWaitConfigureCount.ToString(); FallWareConfiguredCount = res.Data.FallWareConfiguredCount.ToString(); } } private void IsLoadCount() { var packTaskResult = packTaskService.GetTaskAllCount(); if (packTaskResult != null && packTaskResult.Success && packTaskResult.Data != null) { App.Current.Dispatcher.Invoke(new Action(() => { ArrivedCount = packTaskResult.Data.ArrivedCount.ToString(); NoArrivedCount = packTaskResult.Data.NoArrivedCount.ToString(); SomeArrivedCount = packTaskResult.Data.SomeArrivedCount.ToString(); WorryCount = packTaskResult.Data.WorryCount.ToString(); WaitOutbound = packTaskResult.Data.WaitOutbound?.ToString(); WaitPackCount = packTaskResult.Data.WaitPackCount?.ToString(); WaitSealBoxCount = packTaskResult.Data.WaitSealBox?.ToString(); WaitFallWareCount = packTaskResult.Data.WaitFallWareCount?.ToString(); WaitCompleted = packTaskResult.Data.WaitCompleted?.ToString(); WaitTransportCount = packTaskResult.Data.WaitTransportCount?.ToString(); })); } } private void LoadIndex(int pageIndex) { PageIndex = pageIndex;// SearchTaskList(); } public void ReflashTask()//刷新界面 { SearchTaskList(); } private void OpenSkuDetail(object param) { var paramList = (object[])param; var skuId = paramList.Last().ToString(); var url = $"https://item.jd.com/{skuId}.html"; try { System.Diagnostics.Process.Start("explorer.exe", url); } catch (Exception ex) { Clipboard.SetText(url); System.Windows.MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示"); } } #endregion } }