diff --git a/BBWY.Client/ViewModels/PackTask/CreatePackTaskViewModel.cs b/BBWY.Client/ViewModels/PackTask/CreatePackTaskViewModel.cs new file mode 100644 index 00000000..4aec0128 --- /dev/null +++ b/BBWY.Client/ViewModels/PackTask/CreatePackTaskViewModel.cs @@ -0,0 +1,807 @@ +using BBWY.Client.APIServices; +using BBWY.Client.Helpers; +using BBWY.Client.Models; +using BBWY.Client.Models.APIModel.Request; +using BBWY.Client.Models.PackTask; +using BBWY.Client.Views.PackTask; +using BBWY.Common.Models; +using BBWY.Common.Trigger; +using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Messaging; +using NPOI.Util; +using Org.BouncyCastle.Asn1.Crmf; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media.TextFormatting; +using System.Windows.Navigation; + +namespace BBWY.Client.ViewModels.PackTask +{ + public class CreatePackTaskViewModel : BaseVM + { + private bool isLoading = false; + public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } + + private Worry isWorry; + /// + /// 是否加急 + /// + public Worry IsWorry { get => isWorry; set { Set(ref isWorry, value); } } + + + private DelayTrigger delayTrigger; + private string searchIncrementKeyWord; + /// + /// 增量耗材查询关键字 + /// + public string SearchIncrementKeyWord + { + get => searchIncrementKeyWord; set + { + if (Set(ref searchIncrementKeyWord, value)) + { + delayTrigger.SetKey(value); + } + + } + } + + private ObservableCollection increateList; + /// + /// 增量耗材查询关键字 + /// + public ObservableCollection IncreateList { get => increateList; set { Set(ref increateList, value); } } + + private string searchSkuId; + /// + /// skuId + /// + public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } } + + /// + /// 店铺Sku图链接 + /// + private string logo; + /// + /// 店铺Sku图链接 + /// + public string Logo { get => logo; set { Set(ref logo, value); } } + + + + private string skuName; + /// + /// 采购Sku名称 + /// + public string SkuName { get => skuName; set { Set(ref skuName, value); } } + + + private long barCodeId; + /// + /// 条形码id + /// + public long BarCodeId { get => barCodeId; set { Set(ref barCodeId, value); } } + + private string brand; + /// + /// 品牌 + /// + public string Brand { get => brand; set { Set(ref brand, value); } } + + + private string brandName; + /// + /// 品名(手写上传) + /// + public string BrandName { get => brandName; set { Set(ref brandName, value); } } + + /// + /// 需求方店铺id + /// + private string shopName; + /// + /// 需求方店铺id + /// + public string ShopName { get => shopName; set { Set(ref shopName, value); } } + + + private string modelNo; + /// + /// 货号 + /// + public string ModelNo { get => modelNo; set { Set(ref modelNo, value); } } + /// + /// 货号 + /// + private string productNo; + /// + /// 货号 + /// + public string ProductNo { get => productNo; set { Set(ref productNo, value); } } + + private int goodsNumber; + /// + /// 配件数 + /// + public int GoodsNumber { get => goodsNumber; set { Set(ref goodsNumber, value); } } + + private DateTime endTime; + /// + /// 提交时间 + /// + public DateTime EndTime { get => endTime; set { Set(ref endTime, value); } } + + + private long taskId; + /// + /// 绑定数据 + /// + public long TaskId { get => taskId; set { Set(ref taskId, value); } } + + + private string departmentName; + /// + /// 部门名称 + /// + public string DepartmentName { get => departmentName; set { Set(ref departmentName, value); } } + + + private string acceptName; + /// + /// 对接人 + /// + public string AcceptName { get => acceptName; set { Set(ref acceptName, value); } } + + + private int skuCount; + /// + /// sku数量 + /// + public int SkuCount { get => skuCount; set { Set(ref skuCount, value); } } + + + private TaskState availability; + /// + /// 到货情况(待收货=0,部分收货=1,已到货=2) + /// + public TaskState Availability { get => availability; set { Set(ref availability, value); } } + + + + private int taskStatus; + /// + /// 任务状态(已完成=0,未完成=1) + /// + public int TaskStatus { get => taskStatus; set { Set(ref taskStatus, value); } } + + + private PackType packType; + /// + /// 打包类型(单件=0,多件=1) + /// + public PackType PackType { get => packType; set { Set(ref packType, value); } } + + private string skuTitle; + /// + /// sku配件商品名称 + /// + public string SkuTitle { get => skuTitle; set { Set(ref skuTitle, value); } } + + + private BasicPack basicPack; + /// + /// 基础包装(快递袋=0,纸箱=1,麻袋=2) + /// + public BasicPack BasicPack { get => basicPack; set { Set(ref basicPack, value); } } + + + + private Increment increment1; + /// + /// 增量1() + /// + public Increment Increment1 { get => increment1; set { Set(ref increment1, value); } } + + + private Increment increment2; + /// + /// 增量2() + /// + public Increment Increment2 { get => increment2; set { Set(ref increment2, value); } } + + + private PositionType positionType; + /// + /// 落仓(本地仓=0,齐越仓=1,京东仓=2) + /// + public PositionType PositionType { get => positionType; set { Set(ref positionType, value); } } + + private string isNeedBarCode; + /// + /// 是否需要合格证 + /// + public string IsNeedBarCode { get => isNeedBarCode; set { Set(ref isNeedBarCode, value); } } + + + private string isNeedCertificateModel; + /// + /// 是否需要条形码 + /// + public string IsNeedCertificateModel { get => isNeedCertificateModel; set { Set(ref isNeedCertificateModel, value); } } + + + + + private BarCodeModel barCodeModel; + /// + /// 条形码 + /// + public BarCodeModel BarCodeModel { get => barCodeModel; set { Set(ref barCodeModel, value); } } + + + private bool isSetBarCode; + /// + /// 设置显示(条形码) + /// + public bool IsSetBarCode { get => isSetBarCode; set { Set(ref isSetBarCode, value); } } + + private bool isSetCertificate; + /// + /// 设置显示(合格证) + /// + public bool IsSetCertificate { get => isSetCertificate; set { Set(ref isSetCertificate, value); } } + + + + + + private CertificateModel certificateModel; + /// + /// 合格证 + /// + public CertificateModel CertificateModel { get => certificateModel; set { Set(ref certificateModel, value); } } + + /// + /// 合格证位置(外部包装=0,产品包装=1) + /// + private CertificatePosition certificatePosition; + /// + /// 合格证位置(外部包装=0,产品包装=1) + /// + public CertificatePosition CertificatePosition { get => certificatePosition; set { Set(ref certificatePosition, value); } } + + /// + /// 注意事项(对接备注) + /// + private string markMessage; + /// + /// 注意事项(对接备注) + /// + public string MarkMessage { get => markMessage; set { Set(ref markMessage, value); } } + + /// + /// 服务收费 (单个任务id 消耗的总费用) + /// + private decimal feesMoney; + /// + /// 服务收费 (单个任务id 消耗的总费用) + /// + public decimal FeesMoney { get => feesMoney; set { Set(ref feesMoney, value); } } + + /// + /// 打包员 + /// + private string packUser; + /// + /// 打包员 + /// + public string PackUser { get => packUser; set { Set(ref packUser, value); } } + + private string printName; + /// + /// 选中的打印机名称 + /// + public string PrintName { get => printName; set { Set(ref printName, value); } } + + private List printNames; + /// + /// 选中的打印机名称 + /// + public List PrintNames { get => printNames; set { Set(ref printNames, value); } } + + private int printNums; + /// + /// 打印数 + /// + public int PrintNums { get => printNums; set { Set(ref printNums, value); } } + + + private readonly PackTaskService packTaskService; + private readonly GlobalContext globalContext; + private readonly ProductService productService; + + + private string AccepUserId = "";//对接人 + public ICommand SetBarCodeCommand { get; set; } + public ICommand SetCertificateCommand { get; set; } + public ICommand SearchSkuCommand { get; set; } + public ICommand CreateTaskCommand { get; set; } + public ICommand SaveCerCommand { get; set; } + public ICommand SaveBarCodeCommand { get; set; } + + public ICommand BarLabelCheckCommand { get; set; } + public ICommand CerLabelCheckCommand { get; set; } + + public ICommand LookBarCommand { get; set; } + public ICommand LookCerCommand { get; set; } + + + + public void InitData() + { + + //Logo = string.Empty; + //SearchSkuId = ""; + //SkuId = ""; + //SkuCount = 0; + //SkuName = string.Empty; + //ProductNo= string.Empty; + //Brand =string.Empty; + //brandName = string.Empty; + //this.MarkMessage = ""; + //IsSetBarCode = true; + //IsSetCertificate =true; + //BarCodeModel = null; + //CertificateModel = null; + //SkuTitle= string.Empty; + //GoodsNumber = 0; + //string[] increates = new string[] { "气泡纸", "气泡袋", "POP袋", "折纸箱", "气泡纸封边", "彩盒", "剪胶", "剪彩带", "快递袋", "收纳盒", "纸箱子", "装纸箱", "封边", "胶带", "折彩盒" }; + //IncreateList = new ObservableCollection(); + //foreach (var item in increates) + //{ + // IncreateList.Add(new IncreateModel + // { + // IncreateName = item, + // IsSelected = false + // }); + //} + } + + public CreatePackTaskViewModel(PackTaskService packTaskService, GlobalContext globalContext, ProductService productService) + { + Messenger.Default.Register(this, "InitData", message => { + + InitData(); + }); + //RaisePropertyChanged(string.Empty); + //this.RaisePropertyChanged(nameof(CreatePackTaskViewModel)); + + this.productService = productService; + this.packTaskService = packTaskService; + + AccepUserId = globalContext.User.Id.ToString(); + + IsSetBarCode = true; + IsSetCertificate = true; + //数据库获取增量耗材数据 + + string[] increates = new string[] { "气泡纸", "气泡袋", "POP袋", "折纸箱", "气泡纸封边", "彩盒", "剪胶", "剪彩带", "快递袋", "收纳盒", "纸箱子", "装纸箱", "封边", "胶带", "折彩盒" }; + IncreateList = new ObservableCollection(); + foreach (var item in increates) + { + IncreateList.Add(new IncreateModel + { + IncreateName = item, + IsSelected = false + }); + } + + + + + //查询sku + SearchSkuCommand = new RelayCommand(() => + { + Task.Factory.StartNew(() => { SearchSku(); }); + + }); + CreateTaskCommand = new RelayCommand(CreateTask); + this.globalContext = globalContext; + SetBarCodeCommand = new RelayCommand(SetBarCode); + SetCertificateCommand = new RelayCommand(SetCertificate); + SaveBarCodeCommand = new RelayCommand(SaveBarCode); + + SaveCerCommand = new RelayCommand(SaveCer); + BarLabelCheckCommand = new RelayCommand(BarLabelCheck); + CerLabelCheckCommand = new RelayCommand(CerLabelCheck); + + LookBarCommand = new RelayCommand(LookBar); + LookCerCommand = new RelayCommand(LookCer); + PrintNames = new List(); + delayTrigger = new DelayTrigger(500); + delayTrigger.OnExecute = OnSearchIncreateKeyWordChanged; + BarLabelCheck(BarcodeLabelModel.barsimplify);//默认精简模式 + } + + + + private void OnSearchIncreateKeyWordChanged(string key) + { + foreach (var s in this.IncreateList) + s.IsSelected = false; + + App.Current.Dispatcher.Invoke(() => + { + this.IncreateList.Clear(); + + + string[] increates = new string[] { "气泡纸", "气泡袋", "POP袋", "折纸箱", "气泡纸封边", "彩盒", "剪胶", "剪彩带", "快递袋", "收纳盒", "纸箱子", "装纸箱", "封边", "胶带", "折彩盒" }; + List keyWordShopList = new List(); + foreach (var item in increates) + { + keyWordShopList.Add(new IncreateModel + { + IncreateName = item, + IsSelected = false + }); + } + if (!string.IsNullOrEmpty(key.Trim())) + { + keyWordShopList = keyWordShopList.Where(s => s.IncreateName.Contains(key)).ToList(); + + } + if (keyWordShopList.Count() > 0) + { + foreach (var shop in keyWordShopList) + IncreateList.Add(shop); + } + + }); + } + + /// + /// 查看合格证 + /// + private void LookCer() + { + LookCerWindow lookCerWindow = new LookCerWindow(CertificateModel); + lookCerWindow.Show(); + } + /// + /// 查看条形码 + /// + private void LookBar() + { + LookBarCodeWindow look = new LookBarCodeWindow(new BarCodeModel + { + Brand = Brand, + BrandName = BrandName, + LabelModel = LabelModel, + ProductNo = ProductNo, + SkuId = SkuId, + SkuName = SkuName + }); + look.Show(); + } + + private void CerLabelCheck(CerHave3C cer) + { + CertificateModel.IsLogo = (int)cer; + } + /// + /// + /// + /// + /// + private void BarLabelCheck(BarcodeLabelModel barcodeLabelModel) + { + LabelModel = barcodeLabelModel; + + if (LabelModel == BarcodeLabelModel.barstander)//标准版 判断数据是否异常 + { + if (string.IsNullOrEmpty(ProductNo) || ProductNo == "待填写") + { + TipsWindow tips = new TipsWindow("该SKU无货号信息,将影响条形码打印\r\n请先设置好货号信息或调整打印模板类型"); + tips.ShowDialog(); + } + } + + //throw new NotImplementedException(); + } + + /// + /// 设置合格证 + /// + private void SetCertificate() + { + if (CertificateModel == null) + { + new TipsWindow("请先查询Sku数据").ShowDialog(); + return; + } + CertificateModel.BrandName = BrandName; + setCerWindow = new SetCerWindow(); + setCerWindow.ShowDialog(); + //throw new NotImplementedException(); + } + /// + /// 保存合格证 + /// + private void SaveCer() + { + if (string.IsNullOrEmpty(CertificateModel.ExcuteStander) || string.IsNullOrEmpty(CertificateModel.ProductNo) + || string.IsNullOrEmpty(CertificateModel.Shader) || string.IsNullOrEmpty(CertificateModel.BrandName) + || string.IsNullOrEmpty(CertificateModel.Brand) || string.IsNullOrEmpty(CertificateModel.ProductShop) + || string.IsNullOrEmpty(CertificateModel.ProductAdress)) + { + new TipsWindow("参数出错!请重新填写!").ShowDialog(); + return; + } + var standers = CertificateModel.ExcuteStander.Split(',', StringSplitOptions.RemoveEmptyEntries); + CertificateLabelModel labelModel = CertificateLabelModel.CerStanderSingle; + bool IsTwo = false; + + if (standers.Count() > 2) + { + IsTwo = true; + } + + switch (CertificateModel.IsLogo) + { + case 0://没图 + if (IsTwo) + { + labelModel = CertificateLabelModel.CerStanderDouble; break; + } + labelModel = CertificateLabelModel.CerStanderSingle; + break; + case 1://含3c图 + if (IsTwo) + { + labelModel = CertificateLabelModel.Cer3CDouble; break; + } + labelModel = CertificateLabelModel.Cer3CSingle; + break; + default: + break; + } + CertificateModel.LabelModel = labelModel; + var resData = packTaskService.SaveCer(new CerRequest + { + Brand = CertificateModel.Brand, + BrandName = CertificateModel.BrandName, + ProductNo = CertificateModel.ProductNo, + SkuId = CertificateModel.SkuId, + ExcuteStander = CertificateModel.ExcuteStander, + LabelModel = (int)CertificateModel.LabelModel, + FactoryNumber = CertificateModel.FactoryNumber, + IsLogo = CertificateModel.IsLogo, + ProductAdress = CertificateModel.ProductAdress, + ProductShop = CertificateModel.ProductShop, + Shader = CertificateModel.Shader + + + }); + if (resData == null || !resData.Success) + { + IsSetCertificate = false; + return; + } + CertificateModel.Id = resData.Data; + IsSetCertificate = false; + setCerWindow.Close(); + } + + SetBarCodeWindow setBarCodeWindow = null; SetCerWindow setCerWindow = null; + private void SetBarCode() + { + + if (BarCodeModel == null) + { + new TipsWindow("请先查询sku数据").ShowDialog(); + return; + } + BarCodeModel.BrandName = BrandName; + setBarCodeWindow = new SetBarCodeWindow(); + + setBarCodeWindow.ShowDialog(); + } + + public BarcodeLabelModel LabelModel = BarcodeLabelModel.barsimplify; + + private void SaveBarCode() + { + //保存到服务器中 返回id + var resData = packTaskService.SaveBarCode(new BarCodeRequest + { + Brand = Brand, + BrandName = BrandName, + ProductNo = ProductNo, + SkuId = SkuId, + SkuName = SkuName, + LabelModel = LabelModel + + }); + if (resData == null || !resData.Success) + { + IsSetBarCode = false; + return; + } + BarCodeId = resData.Data; + BarCodeModel.Id = BarCodeId; + IsSetBarCode = false; + setBarCodeWindow.Close(); + } + + public string SkuId { get; set; } + + + + /// + /// 发布任务 + /// + public void CreateTask(object obj) + { + + + if (string.IsNullOrEmpty(SkuId)) + { + new TipsWindow("请先搜索SkuId!").ShowDialog(); + return; + } + string increateStr = ""; + var increates = IncreateList.Where(i => i.IsSelected).Select(i => i.IncreateName); + if (increates != null && increates.Count() > 0) + { + increateStr = string.Join(",", increates); + } + + + var createTaskModel = new Models.APIModel.Request.CreateTaskRequest + { + BrandName = BrandName, + Availability = (int)Availability, + BasicPack = (int)BasicPack, + SkuId = SkuId, + CreateTime = DateTime.Now, + Increment1 = increateStr, + Increment2 = (int)Increment2, + CertificatePosition = (int)CertificatePosition, + PackType = (int)PackType, + MarkMessage = markMessage, + PositionType = (int)PositionType, + GoodsNumber = GoodsNumber, + SkuGoodsTitle = SkuTitle, + SkuCount = SkuCount, + UserId = AccepUserId, + ShopId = globalContext.User.Shop.ShopId.ToString(), + IsWorry = IsWorry + }; + if (IsNeedBarCode == "需要") + { + if (BarCodeModel == null || BarCodeModel.Id <= 0) + { + new TipsWindow("请设置条形码模板").ShowDialog(); + return; + } + createTaskModel.BarCodeId = BarCodeId; + } + if (IsNeedCertificateModel == "需要") + { + if (CertificateModel == null || CertificateModel.Id <= 0) + { + new TipsWindow("请设置合格证模板").ShowDialog(); + return; + } + createTaskModel.CertificateId = CertificateModel.Id;// + } + + var res = packTaskService.CreateTask(createTaskModel); + if (res.Success) + { + // Application.Current.Shutdown(0); + new TipsWindow("发布成功").ShowDialog(); + var win = obj as System.Windows.Window; + win.Close(); + + + + //MessageBox.Success("发布成功"); + } + } + + + /// + /// 搜索 skuId + /// + public void SearchSku() + { + + + + + + IsLoading = true; + SkuId = searchSkuId; + ApiResponse productApiResponse = null; + var skuResponse = productService.GetProductSkuList(string.Empty, SkuId); + if (skuResponse.Success) + { + if (skuResponse.Data.Count == 0) + { + IsLoading = false; + return; + } + Logo = skuResponse.Data[0].Logo; + SkuName = skuResponse.Data[0].Title; + // ProductNo = skuResponse.Data[0].ProductItemNum; + + + + productApiResponse = productService.GetProductList(skuResponse.Data[0].ProductId, string.Empty, string.Empty, 1); + + if (productApiResponse.Success) + { + if (productApiResponse.Data.Count == 0) + { + IsLoading = false; + return; + } + + ProductNo = productApiResponse.Data.Items[0].ProductItemNum; + Brand = productApiResponse.Data.Items[0].BrandName; + + } + var productSku = packTaskService.GetProductSku(searchSkuId); + if (productSku == null || !productSku.Success) + { + IsLoading = false; + return; + } + BrandName = productSku.Data.BrandName; + + IsSetCertificate = true; + CertificateModel = productSku.Data.Certificate; + if (CertificateModel == null) + { + CertificateModel = new CertificateModel(); + + } + CertificateModel.Brand = Brand; + CertificateModel.BrandName = BrandName; + CertificateModel.ProductNo = ProductNo; + CertificateModel.SkuId = SkuId; + BarCodeModel = productSku.Data.BarCodeModel; + if (BarCodeModel == null) + { + BarCodeModel = new BarCodeModel(); + } + BarCodeModel.Brand = Brand; + BarCodeModel.BrandName = BrandName; + BarCodeModel.ProductNo = ProductNo; + BarCodeModel.SkuId = SkuId; + BarCodeModel.SkuName = SkuName; + IsSetBarCode = true; + } + else + { + IsLoading = false; + App.Current.Dispatcher.Invoke(() => MessageBox.Show(skuResponse.Msg, "加载sku")); + return; + } + + IsLoading = false; + //查看有木有存在 + } + + } +} diff --git a/dll/Interop.BarTender.dll b/dll/Interop.BarTender.dll new file mode 100644 index 00000000..4f88a5d7 Binary files /dev/null and b/dll/Interop.BarTender.dll differ