步步为盈
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.

731 lines
25 KiB

2 years ago
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;
2 years ago
using GalaSoft.MvvmLight.Messaging;
2 years ago
using BBWY.Client.Models.APIModel;
using BBWY.Client.Models.PackTask;
2 years ago
using BBWY.Client.Views.SealBox;
2 years ago
namespace BBWY.Client.ViewModels.PackTask
{
public partial class WareHouseListViewModel : BaseVM, IDenpendency//注入服务
{
#region 属性绑定
2 years ago
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);
}
}
2 years ago
private ObservableCollection<WaitFallWareModel> waitFallWareList;
/// <summary>
/// 待落仓列表
/// </summary>
public ObservableCollection<WaitFallWareModel> WaitFallWareList { get => waitFallWareList; set { Set(ref waitFallWareList, value); } }
2 years ago
private ObservableCollection<SealBoxModel> waitSealBoxModels;
/// <summary>
/// 分箱列表
/// </summary>
public ObservableCollection<SealBoxModel> WaitSealBoxModels { get => waitSealBoxModels; set { Set(ref waitSealBoxModels, value); } }
2 years ago
private ObservableCollection<PackTaskModel> packTaskList;
/// <summary>
/// 打包任务列表
/// </summary>
public ObservableCollection<PackTaskModel> PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }
2 years ago
2 years ago
/// <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); } }
2 years ago
private string searchShopName;
2 years ago
public string SearchShopName
{
get => searchShopName; set
{
Set(ref searchShopName, value);
}
}
2 years ago
/// <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); } }
2 years ago
public PackTaskState? taskState;
2 years ago
/// <summary>
/// 任务状态
/// </summary>
2 years ago
public PackTaskState? TaskState
2 years ago
{
get => taskState; private set
{
Set(ref taskState, value);
}
}
private int pageIndex = 1;
private int pageSize = 10;
private int orderCount;//总数量
private Visibility tipVisitity;
/// <summary>
///
/// </summary>
public Visibility TipVisitity { get => tipVisitity; set { Set(ref tipVisitity, value); } }
/// <summary>
/// 未到货数量
/// </summary>
2 years ago
public string NoArrivedCount { get => noArrivedCount; set { Set(ref noArrivedCount, value); } }
private string noArrivedCount;
private string someArrivedCount;
2 years ago
/// <summary>
/// 部分到货数量
/// </summary>
2 years ago
public string SomeArrivedCount { get => someArrivedCount; set { Set(ref someArrivedCount, value); } }
private string worryCount;
2 years ago
/// <summary>
/// 加急数
/// </summary>
2 years ago
public string WorryCount { get => worryCount; set { Set(ref worryCount, value); } }
2 years ago
2 years ago
private string arrivedCount;
2 years ago
/// <summary>
/// 已到货数量
/// </summary>
2 years ago
public string ArrivedCount { get => arrivedCount; set { Set(ref arrivedCount, value); } }
private string waitPackCount;
/// <summary>
2 years ago
/// 待打包任务数
2 years ago
/// </summary>
public string WaitPackCount { get => waitPackCount; set { Set(ref waitPackCount, value); } }
2 years ago
private string waitSealBoxCount;
2 years ago
/// <summary>
2 years ago
/// 带封箱任务数
2 years ago
/// </summary>
2 years ago
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); } }
2 years ago
private string waitOutbound;
/// <summary>
2 years ago
/// 待出库任务数
2 years ago
/// </summary>
public string WaitOutbound { get => waitOutbound; set { Set(ref waitOutbound, value); } }
2 years ago
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); } }
2 years ago
2 years ago
private int? IsWorry { get; set; }
public int? taskStatus { get; set; }
public string searchDepartment;
public string SearchDepartment
{
get => searchDepartment; set
{
Set(ref searchDepartment, value);
}
}
#endregion
private readonly ProductService productService;
private readonly ConsumableService consumableService;
private readonly WorkProcessService workProcessService;
private readonly PackTaskService packTaskService;
private readonly IncreateServiceService increateServiceService;
2 years ago
public GlobalContext globalContext;
public WareHouseListViewModel(PackTaskService packTaskService, ConsumableService consumableService, WorkProcessService workProcessService, IncreateServiceService increateServiceService, ProductService productService, BatchPurchaseService batchPurchaseService, GlobalContext globalContext)
2 years ago
{
2 years ago
this.globalContext = globalContext;
2 years ago
this.packTaskService = packTaskService;
this.consumableService = consumableService;
2 years ago
//Messenger.Default.Send(globalContext, "AcceptGlobalContext");
2 years ago
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
2 years ago
SetTaskStateCommand = new RelayCommand<PackTaskState?>(SetTaskState);
2 years ago
SearchTaskCommand = new RelayCommand(() =>
{
PageIndex = 1;
Task.Factory.StartNew(() => SearchTaskList()); //手动点击查询订单
});
TaskPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
{
LoadIndex(p.PageIndex);
});
2 years ago
OpenSkuDetailCommand = new RelayCommand<object>(OpenSkuDetail);
CopyTextCommand = new RelayCommand<object>(s =>
{
try
{
2 years ago
if (s != null)
Clipboard.SetText(s.ToString());
2 years ago
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ResetColor();
}
});
2 years ago
StartTime = DateTime.Now.Date;
EndTime = DateTime.Now.Date;
IsLoading = false;
2 years ago
SetTaskStatusCommand = new RelayCommand<object>(SetTaskStatus);
2 years ago
//加载数据
2 years ago
SetTaskState(null);
2 years ago
this.workProcessService = workProcessService;
this.increateServiceService = increateServiceService;
this.productService = productService;
2 years ago
this.batchPurchaseService = batchPurchaseService;
2 years ago
UpdateTaskStateCommand = new RelayCommand<object>(UpdateTaskState);
2 years ago
2 years ago
CompeteSealBoxCommand = new RelayCommand<object>(CompeteSealBox);
2 years ago
SetSealBoxCommand = new RelayCommand<object>(SetSealBox);
2 years ago
CompeteFallWareCommand = new RelayCommand<object>(CompeteFallWare);
}
/// <summary>
/// 完成落仓(todo:)
/// </summary>
/// <param name="obj"></param>
private void CompeteFallWare(object obj)
{
//throw new NotImplementedException();
2 years ago
}
private void SetSealBox(object obj)
{
2 years ago
var model = (SealBoxModel)obj;
SetSealBoxWindow setSealBoxWindow = new SetSealBoxWindow(model);
setSealBoxWindow.SendBoxCount = boxCount =>
{
model.SealBoxCount = boxCount;
2 years ago
};
setSealBoxWindow.ShowDialog();
2 years ago
}
2 years ago
2 years ago
#region 事件绑定
2 years ago
public ICommand CompeteFallWareCommand { get; set; }
2 years ago
public ICommand CompeteSealBoxCommand { get; set; }
2 years ago
2 years ago
public ICommand SetTaskStatusCommand { get; set; }
2 years ago
/// <summary>
/// 打开图片链接
/// </summary>
public ICommand OpenSkuDetailCommand { get; set; }
/// <summary>
/// 复制
/// </summary>
public ICommand CopyTextCommand { get; set; }
2 years ago
/// <summary>
/// 筛选数据
/// </summary>
public ICommand SetTaskStateCommand { get; set; }
/// <summary>
/// 修改任务状态
/// </summary>
public ICommand UpdateTaskStateCommand { get; set; }
2 years ago
/// <summary>
/// 搜索数据
/// </summary>
public ICommand SearchTaskCommand { get; set; }
/// <summary>
/// 创建任务
/// </summary>
public ICommand CreateTaskCommand { get; set; }
/// <summary>
/// 页面改变事件
/// </summary>
public ICommand TaskPageIndexChangedCommand { get; set; }
2 years ago
/// <summary>
/// 设置分箱数量
/// </summary>
public ICommand SetSealBoxCommand { get; set; }
2 years ago
2 years ago
BatchPurchaseService batchPurchaseService;
2 years ago
2 years ago
private void CompeteSealBox(object obj)
{
2 years ago
var model = (SealBoxModel)obj;
2 years ago
2 years ago
if (model.SealBoxCount == null || model.SealBoxCount.Value <= 0)
2 years ago
{
System.Windows.MessageBox.Show("请先设置封箱数量");
return;
}
2 years ago
2 years ago
var objList = obj as SealBoxModel;
2 years ago
2 years ago
CompeteSealBox competeSealBox = new CompeteSealBox();
competeSealBox.WareId = objList.WareId;
2 years ago
competeSealBox.BoxCount = model.SealBoxCount.Value;
2 years ago
competeSealBox.TaskId = objList.SealBoxSkus.Select(s => s.TaskId).ToArray();
var res = packTaskService.CompeteSealBox(competeSealBox);
2 years ago
if (res != null && res.Success)
{
SearchTaskList();
}
}
private void UpdateTaskState(object obj)
{
var objList = (object[])obj;
long taskId = (long)objList[0];
2 years ago
var packTaskState = (PackTaskState)objList[1];
ApiResponse<object> res = null;
switch (packTaskState)
{
case PackTaskState.:
case PackTaskState.:
2 years ago
if (System.Windows.MessageBox.Show("是否确认收货?", "提示",
MessageBoxButton.YesNo,
MessageBoxImage.Warning) != MessageBoxResult.Yes)
return;
res = packTaskService.SetPackTaskState(taskId, PackTaskState.);
break;
case PackTaskState.:
break;
case PackTaskState.:
2 years ago
var packModel = PackTaskList.SingleOrDefault(p => p.TaskId == taskId);
if (packModel == null || packModel.FeesItemResponse == null || packModel.FeesItemResponse.DiscountAllFees == 0)
{
System.Windows.MessageBox.Show("请先设置打包费用!");
return;
}
res = packTaskService.SetPackTaskState(taskId, PackTaskState.);
break;
case PackTaskState.:
break;
case PackTaskState.:
break;
case PackTaskState.:
break;
case PackTaskState.:
break;
default:
break;
}
2 years ago
if (res != null && res.Success)
{
SearchTaskList();
}
2 years ago
}
2 years ago
public void SetTaskStatus(object obj)
2 years ago
{
var objList = (object[])obj;
long taskId = (long)objList[0];
2 years ago
string orderId = (string)objList[1];
2 years ago
///修改完成
2 years ago
var model = packTaskService.UpdateTaskStatus(taskId, 1, orderId);
2 years ago
if (model != null && model.Success)
2 years ago
SearchTaskList();
2 years ago
2 years ago
}
public void SetTaskState(PackTaskState? taskState)
2 years ago
{
2 years ago
TaskState = taskState;
2 years ago
SearchTaskList();
}
2 years ago
//public void SetTaskState(TaskState? taskState)
//{
// IsWorry = null;
// TaskState = null;
// taskStatus = null;
// switch (taskState)
// {
// case null:
// break;
// case Models.TaskState.已到货:
// case Models.TaskState.部分到货: //未完成的数据
// case Models.TaskState.未到货:
// TaskState = taskState;
// taskStatus = 0;
// break;
// case Models.TaskState.全部: //所有数据
// break;
// case Models.TaskState.已完成:
// taskStatus = 1;
// break;
// case Models.TaskState.加急:
// taskStatus = 0;
// IsWorry = 1;
// break;
// default:
// break;
// }
// SearchTaskList();
//}
2 years ago
2 years ago
/// <summary>
/// 搜索任务列表
/// </summary>
public void SearchTaskList()
{
2 years ago
long? taskId = null;
2 years ago
try
{
2 years ago
if (SearchTaskId != null && !string.IsNullOrEmpty(SearchTaskId.Trim()))
2 years ago
taskId = Convert.ToInt64(SearchTaskId);
2 years ago
}
catch
{
2 years ago
taskId = null;
2 years ago
}
2 years ago
2 years ago
2 years ago
IsLoading = true;
2 years ago
2 years ago
if (TaskState == PackTaskState.)
Task.Factory.StartNew(() =>
{
WaitFallWareList = new ObservableCollection<WaitFallWareModel>();
var datas = packTaskService.SearchWaitFallWareList(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,
});
}));
}
}
else
{
//App.Current.Dispatcher.BeginInvoke(new Action(() =>
//{
// new TipsWindow("查不到数据").Show();
//}));
}
IsLoadCount();
IsLoading = false;
});
else if (TaskState == PackTaskState.)
2 years ago
Task.Factory.StartNew(() =>
2 years ago
{
2 years ago
WaitSealBoxModels = new ObservableCollection<SealBoxModel>();
var datas = packTaskService.SearchWaitSealBoxList(SearchShopName, taskId, SearchSkuId, PageIndex, PageSize);
if (datas != null && datas.Data != null && datas.Success)
2 years ago
{
2 years ago
var dataModel = datas.Data;
OrderCount = dataModel.TotalCount;
foreach (var item in dataModel.WaitSealBoxModels)
2 years ago
{
2 years ago
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
WaitSealBoxModels.Add(new SealBoxModel
{
AcceptUserName = string.Join("|", item.AcceptUserNames.Select(a => a.UserName)),
DepartmentName = item.DepartmentName,
SealBoxSkus = item.SealBoxSkus,
ShopId = item.ShopId,
ShopName = item.ShopName,
WareId = item.WareId,
WareName = item.WareName,
});
}));
}
}
else
{
//App.Current.Dispatcher.BeginInvoke(new Action(() =>
//{
// new TipsWindow("查不到数据").Show();
//}));
}
IsLoadCount();
IsLoading = false;
});
else
Task.Factory.StartNew(() =>
{
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
var datas = packTaskService.GetWareHouseList(SearchWayBillNo, SearchExpressName, IsWorry, SearchDepartment, SearchSkuId, SearchTaskId, StartTime, EndTime, (this.TaskState), SearchShopName,
2 years ago
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 = (TaskState)item.Availability,
BasicPack = (BasicPack)item.BasicPack,
DepartmentName = item.DepartmentName,
CertificatePosition = (CertificatePosition)item.CertificatePosition,
GoodsNumber = item.GoodsNumber,
Increment1 = item.Increment1,
ItemList = new List<SkuMessage>() { new SkuMessage
2 years ago
{ BrandName = item.BrandName,
GoodsNo = item.ProductItemNum, Logo= item.Logo,
2 years ago
ShopName = item.ShopName, SkuName = item.SkuName,
Id = item.SkuId
2 years ago
} },
2 years ago
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,
};
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);
}));
2 years ago
}
2 years ago
}
else
{
}
IsLoadCount();
IsLoading = false;
});
2 years ago
2 years ago
2 years ago
2 years ago
}
private void IsLoadCount()
{
var packTaskResult = packTaskService.GetWareAllCount();
2 years ago
if (packTaskResult != null && packTaskResult.Success && packTaskResult.Data != null)
{
2 years ago
App.Current.Dispatcher.Invoke(new Action(() =>
{
2 years ago
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();
2 years ago
WaitSealBoxCount = packTaskResult.Data.WaitSealBox?.ToString();
WaitFallWareCount= packTaskResult.Data.WaitFallWareCount?.ToString();
}));
}
}
private void LoadIndex(int pageIndex)
{
PageIndex = pageIndex;//
SearchTaskList();
}
2 years ago
public void ReflashTask()//刷新界面
{
SearchTaskList();
}
2 years ago
2 years ago
private void OpenSkuDetail(object param)
{
2 years ago
var paramList = (object[])param;
2 years ago
var skuId = paramList[1].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调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
}
}
2 years ago
#endregion
}
}