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

470 lines
14 KiB

2 years ago
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;
2 years ago
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;
2 years ago
namespace BBWY.Client.ViewModels.PackTask
{
2 years ago
/// <summary>
///
/// </summary>
public partial class TaskListViewModel : BaseVM, IDenpendency//注入服务
2 years ago
{
2 years ago
#region 属性绑定
2 years ago
/// <summary>
2 years ago
/// 查询时间段
2 years ago
/// </summary>
2 years ago
private DateTime startTime;
public DateTime StartTime { get => startTime; set { Set(ref startTime, value); } }
2 years ago
private DateTime endTime;
2 years ago
public DateTime EndTime { get => endTime; set { Set(ref endTime, value); } }
2 years ago
/// <summary>
2 years ago
/// 查询任务id
2 years ago
/// </summary>
2 years ago
private string searchTaskId;
public string SearchTaskId
{
get => searchTaskId; set
{
Set(ref searchTaskId, value);
}
}
2 years ago
/// <summary>
2 years ago
/// 查询Sku
2 years ago
/// </summary>
2 years ago
private string searchSkuId;
public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } }
2 years ago
2 years ago
public TaskState? taskState;
2 years ago
/// <summary>
2 years ago
/// 任务状态
2 years ago
/// </summary>
2 years ago
public TaskState? TaskState
{
get => taskState; private set
{
Set(ref taskState, value);
}
}
2 years ago
2 years ago
private int pageIndex = 1;
private int pageSize = 10;
2 years ago
2 years ago
public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } }
2 years ago
2 years ago
public int PageSize { get => pageSize; set { Set(ref pageSize, value); } }
private int orderCount;//总数量
public int OrderCount { get => orderCount; set { Set(ref orderCount, value); } }
2 years ago
/// <summary>
2 years ago
/// 未到货数量
2 years ago
/// </summary>
2 years ago
public int NoArrivedCount { get => noArrivedCount; set { Set(ref noArrivedCount, value); } }
private int noArrivedCount;
private int someArrivedCount;
2 years ago
/// <summary>
2 years ago
/// 部分到货数量
2 years ago
/// </summary>
2 years ago
public int SomeArrivedCount { get => someArrivedCount; set { Set(ref someArrivedCount, value); } }
2 years ago
2 years ago
private int arrivedCount;
2 years ago
/// <summary>
2 years ago
/// 已到货数量
2 years ago
/// </summary>
2 years ago
public int ArrivedCount { get => arrivedCount; set { Set(ref arrivedCount, value); } }
//private int totalCount;
///// <summary>
///// 全部数量
///// </summary>
//public int TotalCount { get => totalCount; set { Set(ref totalCount, value); } }
2 years ago
2 years ago
private bool isLoading;
2 years ago
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
2 years ago
private readonly PackTaskService packTaskService;
WorkProcessService workProcessService;
public int? taskStatus { get; set; }
private ObservableCollection<PackTaskModel> packTaskList;
2 years ago
/// <summary>
2 years ago
/// 动态数据表
2 years ago
/// </summary>
2 years ago
public ObservableCollection<PackTaskModel> PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }
2 years ago
2 years ago
2 years ago
#endregion
2 years ago
2 years ago
public TaskListViewModel(PackTaskService packTaskService, GlobalContext globalContext, ProductService productService, ConsumableService consumableService, WorkProcessService workProcessService, IncreateServiceService increateServiceService)
2 years ago
{
2 years ago
this.packTaskService = packTaskService;
//TaskState = BBWY.Client.Models. TaskState.全部;
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
2 years ago
2 years ago
SetTaskStateCommand = new RelayCommand<TaskState?>(SetTaskState);
CreateTaskCommand = new RelayCommand(CreateTask);
SearchTaskCommand = new RelayCommand(() =>
2 years ago
{
PageIndex = 1;
2 years ago
Task.Factory.StartNew(() => SearchTaskList()); //手动点击查询订单
2 years ago
});
2 years ago
TaskPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
2 years ago
{
2 years ago
LoadIndex(p.PageIndex);
2 years ago
});
2 years ago
OpenSkuDetailCommand = new RelayCommand<object>(OpenSkuDetail);
CopyTextCommand = new RelayCommand<object>(s =>
{
try
{
Clipboard.SetText(s.ToString());
}
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
2 years ago
//加载数据
SetTaskState(Models.TaskState.);
this.globalContext = globalContext;
this.productService = productService;
this.consumableService = consumableService;
this.workProcessService = workProcessService;
this.increateServiceService = increateServiceService;
2 years ago
}
2 years ago
2 years ago
private void IsLoadCount()
2 years ago
{
2 years ago
var packTaskResult = packTaskService.GetAllCount();
if (packTaskResult != null && packTaskResult.Success)
2 years ago
{
2 years ago
App.Current.Dispatcher.Invoke(() =>
2 years ago
{
2 years ago
ArrivedCount = packTaskResult.Data.ArrivedCount;
NoArrivedCount = packTaskResult.Data.NoArrivedCount;
SomeArrivedCount = packTaskResult.Data.SomeArrivedCount;
2 years ago
});
2 years ago
}
2 years ago
}
2 years ago
private void LoadIndex(int pageIndex)
2 years ago
{
2 years ago
PageIndex = pageIndex;//
SearchTaskList();
2 years ago
}
2 years ago
#region 事件绑定
/// <summary>
/// 筛选数据
/// </summary>
public ICommand SetTaskStateCommand { get; set; }
/// <summary>
/// 搜索数据
/// </summary>
public ICommand SearchTaskCommand { get; set; }
2 years ago
2 years ago
/// <summary>
/// 创建任务
/// </summary>
public ICommand CreateTaskCommand { get; set; }
2 years ago
2 years ago
/// <summary>
/// 页面改变事件
/// </summary>
public ICommand TaskPageIndexChangedCommand { get; set; }
2 years ago
2 years ago
/// <summary>
/// 打开图片链接
/// </summary>
public ICommand OpenSkuDetailCommand { get; set; }
/// <summary>
/// 复制
/// </summary>
public ICommand CopyTextCommand { get; set; }
2 years ago
2 years ago
public void SetTaskState(TaskState? taskState)
2 years ago
{
2 years ago
TaskState = taskState;
switch (taskState)
2 years ago
{
2 years ago
case null:
break;
case Models.TaskState.:
case Models.TaskState.: //未完成的数据
case Models.TaskState.:
taskStatus = null;
TaskState = taskState;
taskStatus = 0;
break;
case Models.TaskState.: //所有数据
TaskState = null;
taskStatus = null;
break;
case Models.TaskState.:
TaskState = null;
taskStatus = 1;
break;
2 years ago
2 years ago
default:
break;
2 years ago
}
2 years ago
SearchTaskList();
2 years ago
}
2 years ago
private ConsumableService consumableService;
private IncreateServiceService increateServiceService;
2 years ago
public void ReflashTask()//刷新界面
{
SearchTaskList();
}
2 years ago
/// <summary>
/// 搜索任务列表
/// </summary>
public void SearchTaskList()
2 years ago
{
2 years ago
IsLoading = true;
Task.Factory.StartNew(() =>
2 years ago
{
2 years ago
try
2 years ago
{
2 years ago
PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
var datas = packTaskService.GetOrderList(SearchSkuId, SearchTaskId, StartTime, EndTime, (this.TaskState), taskStatus,
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.Items)
2 years ago
{
2 years ago
var data = new PackTaskModel(packTaskService, consumableService, workProcessService, increateServiceService)
{
Brand = item.Brand,
SkuId = item.SkuId,
AcceptName = item.UserName,
Availability = (TaskState)item.Availability,
BasicPack = (BasicPack)item.BasicPack,
DepartmentName = item.DepartmentName,
CertificatePosition = (CertificatePosition)item.CertificatePosition,
GoodsNumber = item.GoodsNumber,
Increment1 = item.Increment1,
Increment2 = (Increment)item.Increment2,
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,
PositionType = (PositionType)item.PositionType,
SkuCount = item.SkuCount,
SkuTitle = item.SkuGoodsTitle,
TaskId = item.TaskId,
TaskStatus = (TaskStateType)item.TaskStatus,
EndTime = item.CreateTime,
IsWorry = (Worry)item.IsWorry
};
if (item.BarCodeDTO != null && item.BarCodeDTO.Id > 0)
{
data.BarCodeModel = item.BarCodeDTO;
}
if (item.certificate != null)
{
data.CertificateModel = item.certificate;
}
if (item.FeesItemResponse != null)
{
data.FeesItemResponse = item.FeesItemResponse;
data.FeesMoney = item.FeesItemResponse.SingleFees;
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);
}
data.ReflashTask = ReflashTask;
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
PackTaskList.Add(data);
}));
2 years ago
}
2 years ago
2 years ago
}
2 years ago
else
{
MessageBox.Show("查不到数据");
2 years ago
2 years ago
}
IsLoadCount();
2 years ago
}
2 years ago
catch (Exception ex)
2 years ago
{
2 years ago
2 years ago
}
2 years ago
2 years ago
IsLoading = false;
});
2 years ago
}
2 years ago
GlobalContext globalContext;
ProductService productService;
2 years ago
2 years ago
/// <summary>
/// 展示发布任务页面
/// </summary>
public void CreateTask()
2 years ago
{
2 years ago
ViewModelLocator viewModel = new ViewModelLocator();
var createViewModel = viewModel.CreateTaskView;
if (createViewModel.ReflashWindow==null)
{
createViewModel.ReflashWindow = ReflashTask;
}
2 years ago
CreatePackTask create = new CreatePackTask();
create.SendData();
2 years ago
2 years ago
create.Show();
2 years ago
2 years ago
}
2 years ago
/// <summary>
/// 弹出条形码可视化界面
/// </summary>
public void ShowBarCodeWindow()
2 years ago
{
}
2 years ago
/// <summary>
/// 弹出合格证 可视化页面
/// </summary>
public void ShowCertificateWindow()
2 years ago
{
}
2 years ago
/// <summary>
/// 筛选任务状态数据(根据TaskList数据)
/// </summary>
public void SelectTaskStatus() { }
#endregion
2 years ago
private void OpenSkuDetail(object param)
{
var paramList = (object[])param;
// var orderId = paramList[0].ToString();
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);
MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
}
}
2 years ago
2 years ago
}
}