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;
namespace BBWY.Client.ViewModels.PackTask
{
public partial class TaskListViewModel : BaseVM, IDenpendency
{
private OrderService orderService;
private StatisticsService statisticsService;
private AfterOrderService afterOrderService;
private ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel;
private DongDongHelper dongdongHelper;
private bool isLoading;
private string searchOrderId;
private DateTime startDate;
private DateTime endDate;
private int pageIndex = 1;
private int pageSize = 10;
private int orderCount;
private OrderState? orderState;
private string searchSku;
private string searchProductId;
private string searchProductNo;
private string searchContactName;
private string searchWaybill;
private bool onlyDF;
private bool excludeSD;
private bool excludeCanceled;
private bool onlyUnhandle;
private Random random;
public GlobalContext globalContext { get; set; }
private bool? includeAfterOrder;
private bool includeExceptionOrder;
//private decimal currentConditionsTotalProfit;
private string searchServiceId;
private long waitPurchaseOrderCount;
private long exceptionOrderCount;
private long waitOutStoreCount;
private long afterSaleOrderUnhandleCount;
private long? queryShopId;
private string querySDOperator;
private bool isSDGroup;
///
/// 需求方创建日期
///
private DateTime createTime;
///
/// 任务状态(已完成=0,未完成=1)
///
private int taskStatus;
///
/// 项目完成时间
///
private DateTime endTime;
///
/// 需求方团队id
///
private string departmentId;
///
/// 需求方店铺id
///
private string shopId;
///
/// 货号品名(手写上传)
///
private string brandName;
///
/// 对接人
///
private string userId;
///
/// skuid
///
private string skuId;
///
/// 采购Sku名称
///
private string skuName;
///
/// sku数量
///
private int skuCount;
///
/// 店铺Sku图链接
///
private string shopSkuImage;
///
/// 打包类型(单件=0,多件=1)
///
private int packType;
///
/// 落仓(本地仓=0,齐越仓=1,京东仓=2)
///
private int positionType;
///
/// 基础包装(快递袋=0,纸箱=1,麻袋=2)
///
private int basicPack;
///
/// 增量1()
///
private int increment1;
///
/// 增量2()
///
private int increment2;
///
/// 工序道数
///
private int processCount;
///
/// 到货情况(待收货=0,部分收货=1,已到货=2)
///
private int availability;
///
/// 条形码id
///
private long barcodeId;
///
/// 合格证
///
private long certificateId;
///
/// 合格证位置(外部包装=0,产品包装=1)
///
private int certificatePosition;
///
/// 箱子耗材(自带=0,4-13号纸箱=1-10,)
///
private int boxConsumables;
///
/// 配件数
///
private int goodsNumber;
///
/// 气泡纸耗材(长=0,宽=1)
///
private int airConsumables;
///
/// 注意事项(对接备注)
///
private string markMessage;
///
/// 主键
///
public long Id { get; set; }
///
/// 需求方创建日期
///
public DateTime Createtime { get; set; }
///
/// 任务状态(已完成=0,未完成=1)
///
public int Taskstatus { get; set; }
///
/// 项目完成时间
///
public DateTime Endtime { get; set; }
///
/// 需求方团队id
///
public string Departmentid { get; set; }
///
/// 需求方店铺id
///
public string Shopid { get; set; }
///
/// 货号品名(手写上传)
///
public string Brandname { get; set; }
///
/// 对接人
///
public string Userid { get; set; }
///
/// skuid
///
public string Skuid { get; set; }
///
/// 采购Sku名称
///
public string Skuname { get; set; }
///
/// sku数量
///
public int Skucount { get; set; }
///
/// 店铺Sku图链接
///
public string Shopskuimage { get; set; }
///
/// 打包类型(单件=0,多件=1)
///
public int Packtype { get; set; }
///
/// 落仓(本地仓=0,齐越仓=1,京东仓=2)
///
public int Positiontype { get; set; }
///
/// 基础包装(快递袋=0,纸箱=1,麻袋=2)
///
public int Basicpack { get; set; }
///
/// 增量1()
///
public int Increment1 { get; set; }
///
/// 增量2()
///
public int Increment2 { get; set; }
///
/// 工序道数
///
public int Processcount { get; set; }
///
/// 到货情况(待收货=0,部分收货=1,已到货=2)
///
public int Availability { get; set; }
///
/// 条形码id
///
public long Barcodeid { get; set; }
///
/// 合格证
///
public long Certificateid { get; set; }
///
/// 合格证位置(外部包装=0,产品包装=1)
///
public int Certificateposition { get; set; }
///
/// 箱子耗材(自带=0,4-13号纸箱=1-10,)
///
public int Boxconsumables { get; set; }
///
/// 配件数
///
public int Goodsnumber { get; set; }
///
/// 气泡纸耗材(长=0,宽=1)
///
public int Airconsumables { get; set; }
///
/// 注意事项(对接备注)
///
public string Markmessage { get; set; }
public IList OrderList { get; set; }
public IList AfterSaleOrderList { get; set; }
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
public string SearchOrderId { get => searchOrderId; set { Set(ref searchOrderId, value); } }
public DateTime StartDate { get => startDate; set { Set(ref startDate, value); } }
public DateTime EndDate { get => endDate; set { Set(ref endDate, 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); } }
public OrderState? OrderState { get => orderState; private set { Set(ref orderState, value); } }
public string SearchSku { get => searchSku; set { Set(ref searchSku, value); } }
public string SearchProductId { get => searchProductId; set { Set(ref searchProductId, value); } }
public string SearchProductNo { get => searchProductNo; set { Set(ref searchProductNo, value); } }
public string SearchContactName { get => searchContactName; set { Set(ref searchContactName, value); } }
public string SearchWaybill { get => searchWaybill; set { Set(ref searchWaybill, value); } }
public bool OnlyDF { get => onlyDF; set { Set(ref onlyDF, value); } }
public bool ExcludeSD { get => excludeSD; set { Set(ref excludeSD, value); } }
public bool ExcludeCanceled { get => excludeCanceled; set { Set(ref excludeCanceled, value); } }
public bool? IncludeAfterOrder { get => includeAfterOrder; set { Set(ref includeAfterOrder, value); } }
public string SearchServiceId { get => searchServiceId; set { Set(ref searchServiceId, value); } }
///
/// 仅显示未处理
///
public bool OnlyUnhandle { get => onlyUnhandle; set { Set(ref onlyUnhandle, value); } }
public ToDayOrderAchievement ToDayOrderAchievement { get; set; }
public ICommand SetOrderStateCommand { get; set; }
public ICommand SearchOrderCommand { get; set; }
public ICommand SyncOrderCommand { get; set; }
public ICommand ExportCommand { get; set; }
public ICommand CopyTextCommand { get; set; }
public ICommand CopyOrderWaybillCommand { get; set; }
public ICommand SetSearchDateCommand { get; set; }
public ICommand OrderPageIndexChangedCommand { get; set; }
public ICommand DecodeConsigneeCommand { get; set; }
public ICommand GetBuyerAccountCommand { get; set; }
public ICommand ChooseStorageTypeCommand { get; set; }
public ICommand EditCostCommand { get; set; }
public ICommand OutStockCommand { get; set; }
public ICommand EditVenderRemarkCommand { get; set; }
public ICommand SetIncludeAfterOrderCommand { get; set; }
public ICommand FindAfterSaleOrderCommand { get; set; }
public ICommand EditAfterSaleOrderCommand { get; set; }
public ICommand EditAfterSaleOrderRefundPurchaseAmountCommand { get; set; }
public ICommand SetIncludeExceptionOrderCommand { get; set; }
public ICommand OpenSkuDetailCommand { get; set; }
///
/// 当前条件利润汇总
///
//public decimal CurrentConditionsTotalProfit { get => currentConditionsTotalProfit; set { Set(ref currentConditionsTotalProfit, value); } }
///
/// 是否包含异常订单
///
public bool IncludeExceptionOrder { get => includeExceptionOrder; set { Set(ref includeExceptionOrder, value); } }
public long WaitPurchaseOrderCount { get => waitPurchaseOrderCount; set { Set(ref waitPurchaseOrderCount, value); } }
public long ExceptionOrderCount { get => exceptionOrderCount; set { Set(ref exceptionOrderCount, value); } }
public long WaitOutStoreCount { get => waitOutStoreCount; set { Set(ref waitOutStoreCount, value); } }
public long AfterSaleOrderUnhandleCount { get => afterSaleOrderUnhandleCount; set { Set(ref afterSaleOrderUnhandleCount, value); } }
///
/// 是否为刷单组
///
public bool IsSDGroup { get => isSDGroup; set { Set(ref isSDGroup, value); } }
public TaskListViewModel(OrderService orderService, StatisticsService statisticsService, AfterOrderService afterOrderService, GlobalContext globalContext, ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel, DongDongHelper dongdongHelper)
{
IsSDGroup = globalContext.User.TeamName == "刷单组";
if (IsSDGroup)
{
querySDOperator = globalContext.User.Name;
}
else
{
queryShopId = globalContext.User.Shop.ShopId;
}
random = new Random();
this.dongdongHelper = dongdongHelper;
this.globalContext = globalContext;
this.orderService = orderService;
this.statisticsService = statisticsService;
this.afterOrderService = afterOrderService;
this.choosePurchaseSchemeViewModel = choosePurchaseSchemeViewModel;
OrderList = new ObservableCollection();
AfterSaleOrderList = new ObservableCollection();
EndDate = DateTime.Now;
StartDate = DateTime.Now.Date;
ToDayOrderAchievement = new ToDayOrderAchievement();
InitSearchParam();
SetOrderStateCommand = new RelayCommand(SetOrderState);
SearchOrderCommand = new RelayCommand(() =>
{
PageIndex = 1;
System.Threading.Tasks.Task.Factory.StartNew(() => LoadOrder(1)); //手动点击查询订单
});
SyncOrderCommand = new RelayCommand(SyncOrder);
CopyTextCommand = new RelayCommand(s =>
{
try
{
Clipboard.SetText(s);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ResetColor();
}
}
);
CopyOrderWaybillCommand = new RelayCommand(o => Clipboard.SetText(o.WaybillNo));
SetSearchDateCommand = new RelayCommand(d =>
{
EndDate = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now;
StartDate = DateTime.Now.Date.AddDays(d * -1);
PageIndex = 1;
System.Threading.Tasks.Task.Factory.StartNew(() => LoadOrder(1)); //点击日期查询订单
});
OrderPageIndexChangedCommand = new RelayCommand(p =>
{
System.Threading.Tasks.Task.Factory.StartNew(() => LoadOrder(p.PageIndex));
});
//DecodeConsigneeCommand = new RelayCommand(DecodeConsignee);
GetBuyerAccountCommand = new RelayCommand(GetBuyerAccount);
ChooseStorageTypeCommand = new RelayCommand