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; namespace BBWY.Client.ViewModels.PackTask { public partial class WareHouseListViewModel : BaseVM, IDenpendency//注入服务 { #region 属性绑定 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 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 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); } } 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); } } public TaskState? taskState; /// /// 任务状态 /// public TaskState? TaskState { get => taskState; private 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); } } 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); } } private int? IsWorry { get; set; } public int? taskStatus { get; set; } 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); } } #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(() => { PageIndex = 1; Task.Factory.StartNew(() => SearchTaskList()); //手动点击查询订单 }); TaskPageIndexChangedCommand = new RelayCommand(p => { LoadIndex(p.PageIndex); }); OpenSkuDetailCommand = new RelayCommand(OpenSkuDetail); StartTime = DateTime.Now.Date; EndTime = DateTime.Now.Date; IsLoading = false; SetTaskStatusCommand = new RelayCommand(SetTaskStatus); //加载数据 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 => { PageIndex = 1; SealBoxConfigureType = s; PositionState = s == SealBoxConfigureType.已配置 ? PositionState.已配置待落仓 : PositionState.待落仓; Task.Factory.StartNew(() => SearchTaskList()); }); LookBoxConfigureCommand = new RelayCommand(LookBoxConfigure); PrintBoxConfigureCommand = new RelayCommand(PrintBoxConfigure); } /// /// 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 }; 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.云仓) { 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 LookBoxConfigureCommand { get; set; } /// /// 待配置 /已配置 /// public ICommand SetSealBoxConfigureTypeCommand { get; set; } public ICommand CompeteFallWareCommand { get; set; } public ICommand CompeteSealBoxCommand { get; set; } public ICommand SetTaskStatusCommand { 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; } /// /// 完成封箱 /// /// 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 SetTaskStatus(object obj) { var objList = (object[])obj; long taskId = (long)objList[0]; string orderId = (string)objList[1]; ///修改完成 var model = packTaskService.UpdateTaskStatus(taskId, 1, orderId); if (model != null && model.Success) SearchTaskList(); } public void SetTaskState(TaskState? taskState) { PageIndex = 1; TaskState = taskState; SearchTaskList(); } /// /// 搜索任务列表 /// public void SearchTaskList() { 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(() => { 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, }); })); } } 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); 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.BeginInvoke(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, }); })); } } 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, IsWorry, SearchDepartment, SearchSkuId, SearchTaskId, StartTime, EndTime, (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, ShopName = item.ShopName, SkuName = item.SkuName, Id = 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, }; 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.BeginInvoke(new Action(() => { PackTaskList.Add(data); })); } } else { } IsLoadCount(); IsLoading = false; }); } 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(); })); } } 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 } }