步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1178 lines
50 KiB

using BBWY.Client.APIServices;
using BBWY.Client.Helpers;
using BBWY.Client.Models;
using BBWY.Client.Views.Order;
using BBWY.Common.Models;
using BBWY.Controls;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Input;
using System.Windows;
using BBWY.Common.Extensions;
using System.Threading.Tasks;
using BBWY.Client.Views.PackTask;
using HandyControl.Tools.Extension;
using Newtonsoft.Json;
using BBWY.Client.Models.APIModel.Response.PackTask;
using BBWY.Client.Models.PackTask;
using WebSocketSharp;
using BBWY.Client.Models.APIModel;
using BBWY.Client.Views.SealBox;
using BBWY.Client.Models.SealBox;
using BBWY.Client.ViewModels.SealBox;
using BBWY.Client.Views.FallWare;
using BBWY.Client.Models.FallWare;
using BBWY.Client.Views.TaskOverTime;
namespace BBWY.Client.ViewModels.PackTask
{
/// <summary>
///
/// </summary>
public partial class TaskListViewModel : BaseVM, IDenpendency//注入服务
{
#region 属性绑定
private ObservableCollection<WareWaitCompleted> waitCompletedList;
/// <summary>
/// 待完结列表
/// </summary>
public ObservableCollection<WareWaitCompleted> WaitCompletedList { get => waitCompletedList; set { Set(ref waitCompletedList, value); } }
private string sealBoxWaitConfigureCount;
/// <summary>
/// 封箱 待配置数
/// </summary>
public string SealBoxWaitConfigureCount { get => sealBoxWaitConfigureCount; set { Set(ref sealBoxWaitConfigureCount, value); } }
private string sealBoxConfiguredCount;
/// <summary>
///封箱 已配置数
/// </summary>
public string SealBoxConfiguredCount { get => sealBoxConfiguredCount; set { Set(ref sealBoxConfiguredCount, value); } }
private SealBoxConfigureType sealBoxConfigureType;
/// <summary>
/// 封箱配置状态
/// </summary>
public SealBoxConfigureType SealBoxConfigureType { get => sealBoxConfigureType; set { Set(ref sealBoxConfigureType, value); } }
//private SealBoxConfigureType fallWareConfigureType;
///// <summary>
///// 落仓配置状态
///// </summary>
//public SealBoxConfigureType FallWareConfigureType { get => fallWareConfigureType; set { Set(ref fallWareConfigureType, value); } }
private ObservableCollection<SealBoxWaitConfigureModel> sealBoxWaitConfigureList;
/// <summary>
/// 封箱待配置列表
/// </summary>
public ObservableCollection<SealBoxWaitConfigureModel> SealBoxWaitConfigureList { get => sealBoxWaitConfigureList; set { Set(ref sealBoxWaitConfigureList, value); } }
private ObservableCollection<SealBoxConfiguredModel> sealBoxConfiguredList;
/// <summary>
/// 封箱已配置列表
/// </summary>
public ObservableCollection<SealBoxConfiguredModel> SealBoxConfiguredList { get => sealBoxConfiguredList; set { Set(ref sealBoxConfiguredList, value); } }
private ObservableCollection<FallWareConfiguredModel> fallWareWaitConfigureList;
/// <summary>
/// 落仓待配置列表
/// </summary>
public ObservableCollection<FallWareConfiguredModel> FallWareWaitConfigureList { get => fallWareWaitConfigureList; set { Set(ref fallWareWaitConfigureList, value); } }
private ObservableCollection<FallWareConfiguredModel> fallWareConfiguredList;
/// <summary>
/// 落仓已配置列表
/// </summary>
public ObservableCollection<FallWareConfiguredModel> FallWareConfiguredList { get => fallWareConfiguredList; set { Set(ref fallWareConfiguredList, value); } }
///// <summary>
///// 查询时间段
///// </summary>
//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); } }
/// <summary>
/// 查询任务id
/// </summary>
private string searchTaskId;
public string SearchTaskId
{
get => searchTaskId; set
{
Set(ref searchTaskId, value);
}
}
/// <summary>
/// 查询Sku
/// </summary>
private string searchSkuId;
public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } }
/// <summary>
/// 查询Spu
/// </summary>
private string searchSpuId;
public string SearchSpuId { get => searchSpuId; set { Set(ref searchSpuId, value); } }
/// <summary>
/// 查询拳探订单号
/// </summary>
private string searchOrderSn;
public string SearchOrderSn { get => searchOrderSn; set { Set(ref searchOrderSn, value); } }
private TaskState? taskState;
/// <summary>
/// 任务状态
/// </summary>
public TaskState? TaskState
{
get => taskState; set
{
Set(ref taskState, value);
}
}
private int pageIndex = 1;
private int pageSize = 10;
public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } }
public int PageSize { get => pageSize; set { Set(ref pageSize, value); } }
private int orderCount;//总数量
public int OrderCount { get => orderCount; set { Set(ref orderCount, value); } }
/// <summary>
/// 未到货数量
/// </summary>
public string NoArrivedCount { get => noArrivedCount; set { Set(ref noArrivedCount, value); } }
private string noArrivedCount;
private string someArrivedCount;
/// <summary>
/// 部分到货数量
/// </summary>
public string SomeArrivedCount { get => someArrivedCount; set { Set(ref someArrivedCount, value); } }
private string arrivedCount;
/// <summary>
/// 已到货数量
/// </summary>
public string ArrivedCount { get => arrivedCount; set { Set(ref arrivedCount, value); } }
private bool isLoading;
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
private string waitScheduleCount;
/// <summary>
/// 待排单任务数
/// </summary>
public string WaitScheduleCount { get => waitScheduleCount; set { Set(ref waitScheduleCount, value); } }
private string waitPackCount;
/// <summary>
/// 待打包任务数
/// </summary>
public string WaitPackCount { get => waitPackCount; set { Set(ref waitPackCount, value); } }
private string waitSealBoxCount;
/// <summary>
/// 带封箱任务数
/// </summary>
public string WaitSealBoxCount { get => waitSealBoxCount; set { Set(ref waitSealBoxCount, value); } }
private string waitFallWareCount;
/// <summary>
/// 待落仓任务数
/// </summary>
public string WaitFallWareCount { get => waitFallWareCount; set { Set(ref waitFallWareCount, value); } }
private string waitOutbound;
/// <summary>
/// 待出库任务数
/// </summary>
public string WaitOutbound { get => waitOutbound; set { Set(ref waitOutbound, value); } }
private string waitCompleted;
/// <summary>
/// 待完成任务数
/// </summary>
public string WaitCompleted { get => waitCompleted; set { Set(ref waitCompleted, value); } }
private SealBoxService sealBoxService;
private PackTaskService packTaskService;
private ObservableCollection<PackTaskModel> packTaskList;
/// <summary>
/// 动态数据表
/// </summary>
public ObservableCollection<PackTaskModel> PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }
#endregion
private ObservableCollection<StoreGetSelfData> storeGetSelfDataList;
/// <summary>
/// 商家自取记录任务列表
/// </summary>
public ObservableCollection<StoreGetSelfData> StoreGetSelfDataList { get => storeGetSelfDataList; set { Set(ref storeGetSelfDataList, value); } }
public TaskListViewModel(PackTaskService packTaskService, GlobalContext globalContext, SealBoxService sealBoxService)
{
this.globalContext = globalContext;
this.packTaskService = packTaskService;
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
SetTaskStateCommand = new RelayCommand<TaskState?>(SetTaskState);
SetSealBoxConfigureTypeCommand = new RelayCommand<SealBoxConfigureType>(s =>
{
SealBoxConfigureType = s;
Task.Factory.StartNew(() => SearchTaskList());
});
CreateTaskCommand = new RelayCommand(CreateTask);
SearchTaskCommand = new RelayCommand(() =>
{
Task.Factory.StartNew(() => SearchTaskList()); //手动点击查询订单
});
TaskPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
{
LoadIndex(p.PageIndex);
});
OpenSkuDetailCommand = new RelayCommand<object>(OpenSkuDetail);
DeletedTaskCommand = new RelayCommand<object>(DeletedTask);
ConfiguredSealBoxCommand = new RelayCommand(ConfiguredSealBox);
UpdateSealBoxConfiguredCommand = new RelayCommand<SealBoxConfiguredModel>(UpdateSealBoxConfigured);
//StartTime = DateTime.Now.Date;
//EndTime = DateTime.Now.Date;
IsLoading = false;
//加载数据
SetTaskState(null);
this.sealBoxService = sealBoxService;
SealBoxConfigureType = SealBoxConfigureType.;
SetFallWareConfiguredCommand = new RelayCommand<object>(SetFallWareConfigured);
SubmitOverTimeMarkMsgCommand = new RelayCommand<object>(SubmitOverTimeMarkMsg);
}
private void SubmitOverTimeMarkMsg(object param)
{
var paramList = (object[])param;
var id = (long)paramList[0];
var markMsg = paramList[1].ToString();
SubmitOverTimeMarkMsgWindow submitOverTimeMarkMsgWindow = new SubmitOverTimeMarkMsgWindow(OverTimeTaskType., id, markMsg, packTaskService, ReflashTask);
submitOverTimeMarkMsgWindow.ShowDialog();
}
private void SetFallWareConfigured(object obj)
{
var fallware = obj as FallWareConfiguredModel;
JDWareBoxModel model = new JDWareBoxModel
{
ShopName = globalContext.User.Shop.ShopName,
WareName = fallware.WareName,
SealBoxId = fallware.SealBoxId,
ProductCount = fallware.SealBoxTotalCount,
BoxCount = fallware.BoxCount.Value,
PrewOrder = fallware.PrewOrder,
ProductTitle = fallware.ProductTitle,
PurchaseOrder = fallware.PurchaseOrder,
WaybillNo = fallware.WaybillNo
};
var w = new SetJDWareBoxWindow2(model, sealBoxService, fallware.WareType.Value, ReflashTask, fallware.TransportOverTime);
w.ShowDialog();
}
private void UpdateSealBoxConfigured(SealBoxConfiguredModel model)
{
var sealBoxId = model.SealBoxId;
var taskIds = model.SealBoxConfigureTasks.Select(s => s.TaskId).ToArray();
var updateSealBoxConfig = sealBoxService.GetUpdateSealBoxConfiguredV2(sealBoxId, taskIds);
if (updateSealBoxConfig == null)
{
MessageBox.Show("网络异常,获取不到带封箱数据");
return;
}
if (!updateSealBoxConfig.Success || updateSealBoxConfig.Data == null)
{
MessageBox.Show(updateSealBoxConfig.Msg);
return;
}
SetSealBoxPolicyWindow setSealBoxPolicyWindow = new SetSealBoxPolicyWindow(updateSealBoxConfig.Data.UpdateSealBoxConfiguredTaskDatas, ReflashTask, sealBoxId);
setSealBoxPolicyWindow.ShowDialog();
}
private void ConfiguredSealBox()
{
var waitSealBoxRes = sealBoxService.GetSealBoxWaitConfigureList(null, null, null, null, null);//获取所有待封装列表
if (waitSealBoxRes == null)
{
MessageBox.Show("网络异常,获取不到带封箱数据");
return;
}
if (!waitSealBoxRes.Success || waitSealBoxRes.Data == null)
{
MessageBox.Show(waitSealBoxRes.Msg);
return;
}
if (waitSealBoxRes.Data.TotalCount <= 0)
{
MessageBox.Show("已全部封箱!");
return;
}
//var taskIds = waitSealBoxRes.Data.SealBoxWaitConfigureModels.Select(w => w.TaskId).ToArray();
//var updateSealBoxConfig = sealBoxService.GetUpdateSealBoxConfigured(0, taskIds);
//if (updateSealBoxConfig == null)
//{
// MessageBox.Show("网络异常,获取不到带封箱数据");
// return;
//}
//if (!updateSealBoxConfig.Success || updateSealBoxConfig.Data == null)
//{
// MessageBox.Show(updateSealBoxConfig.Msg);
// return;
//}
//SealBoxConfigureWindow sealBoxConfigureWindow = new SealBoxConfigureWindow(updateSealBoxConfig.Data.UpdateSealBoxConfiguredTaskDatas, ReflashTask, 0);
//sealBoxConfigureWindow.ShowDialog();
var data = waitSealBoxRes.Data.SealBoxWaitConfigureModels.Select(x => new SealBoxConfigureModel
{
Logo = x.Logo,
WareType = x.WareType,
SkuCount = x.SkuCount,
SkuId = x.SkuId,
SkuName = x.SkuName,
TaskId = x.TaskId,
TaskState = x.TaskState,
WaitConfigureCount = x.SkuCount,
}).ToList();
SetSealBoxPolicyWindow setSealBoxPolicyWindow = new SetSealBoxPolicyWindow(data, ReflashTask, 0);
setSealBoxPolicyWindow.ShowDialog();
}
private void DeletedTask(object obj)
{
var packTaskmodel = (PackTaskModel)obj;
MessageBoxResult result = MessageBox.Show("确定取消任务?", "提示",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result != MessageBoxResult.Yes) return;
packTaskService.DeletedTask(packTaskmodel.TaskId);
Task.Factory.StartNew(() => SearchTaskList());
}
private void IsLoadCount()
{
var packTaskResult = packTaskService.GetTaskAllCount(globalContext.User.Shop.ShopId.ToString());
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();
WaitScheduleCount = packTaskResult.Data.WaitScheduleCount?.ToString();
}));
}
}
private void LoadIndex(int pageIndex)
{
PageIndex = pageIndex;//
SearchTaskList();
}
#region 事件绑定
/// <summary>
/// 提交过期时间数据
/// </summary>
public ICommand SubmitOverTimeMarkMsgCommand { get; set; }
/// <summary>
/// 设置落仓配置信息(上传材料)
/// </summary>
public ICommand SetFallWareConfiguredCommand { get; set; }
/// <summary>
/// 修改封箱数据
/// </summary>
public ICommand UpdateSealBoxConfiguredCommand { get; set; }
/// <summary>
/// 配置封箱策略
/// </summary>
public ICommand ConfiguredSealBoxCommand { get; set; }
/// <summary>
/// 待配置 /已配置
/// </summary>
public ICommand SetSealBoxConfigureTypeCommand { get; set; }
/// <summary>
/// 筛选数据
/// </summary>
public ICommand SetTaskStateCommand { get; set; }
/// <summary>
/// 搜索数据
/// </summary>
public ICommand SearchTaskCommand { get; set; }
/// <summary>
/// 创建任务
/// </summary>
public ICommand CreateTaskCommand { get; set; }
/// <summary>
/// 页面改变事件
/// </summary>
public ICommand TaskPageIndexChangedCommand { get; set; }
/// <summary>
/// 打开图片链接
/// </summary>
public ICommand OpenSkuDetailCommand { get; set; }
/// <summary>
/// 删除任务
/// </summary>
public ICommand DeletedTaskCommand { get; set; }
public void SetTaskState(TaskState? taskState)
{
PageIndex = 1;
TaskState = taskState;
SearchTaskList();
}
public void ReflashTask()//刷新界面
{
SearchTaskList();
}
private List<TaskState> waitSealBoxTaskStates = new List<TaskState> {
Models.TaskState., Models.TaskState., Models.TaskState., Models.TaskState.
};//配置封箱的任务状态范围
private bool IsStartThread = false;
private Thread qualityOverTimeThread = null;
private Thread packOverTimeThread = null;
private Thread sealboxOverTimeThread = null;
private Thread fallwareOverTimeThread = null;
private Thread scheduleOverTimeThread = null;
/// <summary>
/// 搜索任务列表
/// </summary>
public void SearchTaskList()
{
IsStartThread = false;
long? taskId = null;
try
{
if (SearchTaskId != null && !string.IsNullOrEmpty(SearchTaskId.Trim()))
taskId = Convert.ToInt64(SearchTaskId);
}
catch
{
System.Windows.MessageBox.Show("任务id必须为数字");
return;
}
IsLoading = true;
if (TaskState == null || !waitSealBoxTaskStates.Contains(TaskState.Value))
Task.Factory.StartNew(() =>
{
try
{
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
var datas = packTaskService.SearchTaskList(SearchSkuId, SearchTaskId, SearchSpuId, SearchOrderSn, this.TaskState,
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()
{
SkuId = item.SkuId,
AcceptName = item.UserName,
BasicPack = (BasicPack)item.BasicPack,
DepartmentName = item.DepartmentName,
CertificatePosition = (CertificatePosition)item.CertificatePosition,
GoodsNumber = item.GoodsNumber,
Increment1 = item.Increment1,
ItemList = new List<SkuMessage>() { new SkuMessage
{ BrandName = item.BrandName,
GoodsNo = item.ProductItemNum, Logo= item.Logo,
SkuName = item.SkuName,
SkuId = item.SkuId,
} },
ShowMarkMessage = item.ShowMarkMessage,
PackType = (PackType)item.PackType,
PositionType = item.PositionType,
SkuCount = item.SkuCount,
SkuTitle = item.SkuGoodsTitle,
TaskId = item.TaskId,
EndTime = item.CreateTime,
BrandName = item.BrandName,
OrderId = item.OrderId,
TaskState = item.TaskState,
QualityCompletionOverTime = item.QualityCompletionOverTime,
PackCompletionOverTime = item.PackCompletionOverTime,
ShopName = item.ShopName,
SkuPurchaseSchemeId = item.SkuPurchaseSchemeId,
ScheduleOverTimeMarkMsg = item.ScheduleOverTimeMarkMsg,
ScheduleOverTime = item.ScheduleOverTime,
PackProcessType = item.PackProcessType,
SendToSetSkuConfigureTime = item.SendToSetSkuConfigureTime,
};
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 (data.BarCodeModel.LabelModel == BarcodeLabelModel.)
data.BarCodeModel.LabelModel = BarcodeLabelModel.;
}
if (item.Cers != null)
{
data.CertificateModel = item.Cers;
}
if (item.FeesItemResponse != null)
{
data.FeesItemResponse = item.FeesItemResponse;
data.FeesMoney = item.FeesItemResponse.AllFees;
data.IsShowFees = item.FeesItemResponse.AllFees > 0 ? true : false;
data.FeesItemResponse.DiscountSingleFees = item.FeesItemResponse.SingleFees * item.FeesItemResponse.disCount;
data.FeesItemResponse.DiscountAllFees = item.FeesItemResponse.AllFees * item.FeesItemResponse.disCount;
}
else
{
data.IsShowFees = false;
}
if (item.PackUserName != null && item.PackUserName.Count() > 0)
{
data.PackUser = string.Join("\r\n", item.PackUserName);
}
data.ReflashTask = ReflashTask;
App.Current.Dispatcher.Invoke(new Action(() =>
{
PackTaskList.Add(data);
}));
}
//任务状态为待验收
if (TaskState == Models.TaskState.)
{
var packtasks = PackTaskList.Where(p => p.TaskState == Models.TaskState. && p.QualityCompletionOverTime != null).ToList();
if (packtasks.Count() > 0)
{
//if (qualityOverTimeThread!=null)
//{
// qualityOverTimeThread.Abort();
//}
qualityOverTimeThread = new Thread(() =>
{
IsStartThread = true;
while (IsStartThread)
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
foreach (var item in packtasks)
{
TimeSpan datetime;
if (item.SendToSetSkuConfigureTime != null)
datetime = item.QualityCompletionOverTime.Value.Subtract(item.SendToSetSkuConfigureTime.Value);
else
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)
{
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}天{datetime.Hours}小时{datetime.Minutes}分";
}
else
{
item.IsPackOverTime = true;
item.PackRemainTime = $"{-datetime.Days}天{-datetime.Hours}小时{-datetime.Minutes}分";
}
}
}));
Thread.Sleep(1000);
}
});
//任务倒计时数据
packOverTimeThread.IsBackground = true;
packOverTimeThread.Start();
}
}
if (TaskState == Models.TaskState.)
{
var packCompletedTasks = PackTaskList.Where(p => p.TaskState == Models.TaskState. && p.ScheduleOverTime != null).ToList();
if (packCompletedTasks.Count() > 0)
{
//if (packOverTimeThread!=null)
//{
// packOverTimeThread.Abort();
//}
scheduleOverTimeThread = new Thread(() =>
{
IsStartThread = true;
while (IsStartThread)
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
foreach (var item in packCompletedTasks)
{
var datetime = item.ScheduleOverTime.Value.Subtract(DateTime.Now);
if (datetime.TotalMilliseconds > 0)
{
item.IsScheduleOverTime = false;
item.ScheduleRemainTime = OverTimeHelper.GetTimeString(datetime);
}
else
{
item.IsScheduleOverTime = true;
item.ScheduleRemainTime = OverTimeHelper.GetTimeString(datetime);
}
}
}));
Thread.Sleep(1000);
}
});
//任务倒计时数据
scheduleOverTimeThread.IsBackground = true;
scheduleOverTimeThread.Start();
}
}
}
else
{
if (datas != null) System.Windows.MessageBox.Show(datas.Msg);
}
IsLoadCount();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
IsLoading = false;
});
if (TaskState != null && waitSealBoxTaskStates.Contains(TaskState.Value))//封箱操作
{
if (TaskState == Models.TaskState.)
Task.Factory.StartNew(() =>
{
try
{
if (SealBoxConfigureType == SealBoxConfigureType.)
{
SealBoxWaitConfigureList = new ObservableCollection<SealBoxWaitConfigureModel>();
ApiResponse<SealBoxWaitConfigureResponse> sealBoxWaitRes = sealBoxService.GetSealBoxWaitConfigureList(SearchSkuId, SearchTaskId, PageSize, PageIndex, SearchSpuId);
if (sealBoxWaitRes == null)
{
System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
}
if (!sealBoxWaitRes.Success || sealBoxWaitRes.Data == null)
{
System.Windows.MessageBox.Show(sealBoxWaitRes.Msg); IsLoading = false; return;
}
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
OrderCount = sealBoxWaitRes.Data.TotalCount;
}));
foreach (var item in sealBoxWaitRes.Data.SealBoxWaitConfigureModels)
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SealBoxWaitConfigureList.Add(item);
}));
}
}
if (SealBoxConfigureType == SealBoxConfigureType.)
{
SealBoxConfiguredList = new ObservableCollection<SealBoxConfiguredModel>();
var sealBoxRes = sealBoxService.GetSealBoxConfiguredList(PositionState., SearchSkuId, SearchTaskId, globalContext.User.Shop.ShopId.ToString(), PageSize, PageIndex);
if (sealBoxRes == null)
{
System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
}
if (!sealBoxRes.Success || sealBoxRes.Data == null)
{
System.Windows.MessageBox.Show(sealBoxRes.Msg); IsLoading = false; return;
}
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
OrderCount = sealBoxRes.Data.TotalCount;
}));
foreach (var item in sealBoxRes.Data.SealBoxConfiguredModels)
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
SealBoxConfiguredList.Add(item);
}));
}
Thread.Sleep(500);
var sealboxTasks = SealBoxConfiguredList.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();
}
}
IsLoadSealBoxCount();
IsLoadCount();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
IsLoading = false;
});
if (TaskState == Models.TaskState.)
Task.Factory.StartNew(() =>
{
try
{
if (SealBoxConfigureType == SealBoxConfigureType.)
{
FallWareWaitConfigureList = new ObservableCollection<FallWareConfiguredModel>();
var fallWareRes = sealBoxService.SearchFallWareConfiguredList(PositionState., taskId, SearchSkuId, PageIndex, PageSize);
if (fallWareRes == null)
{
System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
}
if (!fallWareRes.Success || fallWareRes.Data == null)
{
System.Windows.MessageBox.Show(fallWareRes.Msg); IsLoading = false; return;
}
App.Current.Dispatcher.Invoke(new Action(() =>
{
OrderCount = fallWareRes.Data.TotalCount;
}));
foreach (var item in fallWareRes.Data.FallWareConfiguredModels)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
FallWareWaitConfigureList.Add(item);
}));
}
var fallWareTasks = FallWareWaitConfigureList.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();
}
}
if (SealBoxConfigureType == SealBoxConfigureType.)
{
FallWareConfiguredList = new ObservableCollection<FallWareConfiguredModel>();
var fallWareRes = sealBoxService.SearchFallWareConfiguredList(PositionState., taskId, SearchSkuId, PageIndex, PageSize);
if (fallWareRes == null)
{
System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
}
if (!fallWareRes.Success || fallWareRes.Data == null)
{
System.Windows.MessageBox.Show(fallWareRes.Msg); IsLoading = false; return;
}
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
OrderCount = fallWareRes.Data.TotalCount;
}));
foreach (var item in fallWareRes.Data.FallWareConfiguredModels)
{
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
FallWareConfiguredList.Add(item);
}));
}
}
IsLoadFallWareCount();
IsLoadCount();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
IsLoading = false;
});
if (TaskState == Models.TaskState.)
{
Task.Factory.StartNew(() =>
{
WaitCompletedList = new ObservableCollection<WareWaitCompleted>();
var datas = sealBoxService.GetWareWaitCompletedList(globalContext.User.Shop.ShopId.ToString(), null, taskId, SearchSkuId, 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;
});
}
if (TaskState == Models.TaskState.)
{
Task.Factory.StartNew(() =>
{
StoreGetSelfDataList = new ObservableCollection<StoreGetSelfData>();
var datas = packTaskService.SearchStoreGetSelfList(SearchTaskId, SearchOrderSn, SearchSpuId, SearchSkuId, null, null, PageIndex, PageSize, globalContext.User.Shop.ShopId.ToString());
if (datas != null && datas.Data != null && datas.Success)
{
var dataModel = datas.Data;
OrderCount = dataModel.TotalCount;
foreach (var item in dataModel.StoreGetSelfResponseList)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
StoreGetSelfDataList.Add(item);
}));
}
}
else
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
MessageBox.Show(datas?.Msg);
}));
}
IsLoading = false;
});
}
}
}
GlobalContext globalContext;
private void IsLoadFallWareCount()
{
var res = sealBoxService.GetFallWareConfigureCounts(globalContext.User.Shop.ShopId.ToString());
if (res != null && res.Success && res.Data != null)
{
SealBoxWaitConfigureCount = res.Data.FallWareWaitConfigureCount.ToString();
SealBoxConfiguredCount = res.Data.FallWareConfiguredCount.ToString();
}
}
private void IsLoadSealBoxCount()
{
var res = sealBoxService.GetSealBoxPackStateCount();
if (res != null && res.Success && res.Data != null)
{
SealBoxWaitConfigureCount = res.Data.SealBoxWaitConfigureCount.ToString();
SealBoxConfiguredCount = res.Data.SealBoxConfiguredCount.ToString();
}
}
/// <summary>
/// 展示发布任务页面
/// </summary>
public void CreateTask()
{
PublishTaskWindow publish = new PublishTaskWindow(ReflashTask);
publish.ShowDialog();
}
/// <summary>
/// 弹出条形码可视化界面
/// </summary>
public void ShowBarCodeWindow()
{
}
/// <summary>
/// 弹出合格证 可视化页面
/// </summary>
public void ShowCertificateWindow()
{
}
#endregion
private void OpenSkuDetail(object param)
{
var paramList = (object[])param;
// var orderId = paramList[0].ToString();
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);
MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
}
}
}
}