using BBWY.Client.APIServices;
using BBWY.Client.Models.PackTask;
using BBWY.Client.ViewModels;
using BBWY.Client.Views.PackTask;
using BBWY.Common.Models;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace BBWY.Client.Models
{
public class BatchPublishTask : NotifyObject
{
#region 属性
private int skuCount;
///
/// Sku任务数
///
public int SkuCount { get => skuCount; set { Set(ref skuCount, value); } }
private string skuId;
///
/// Sku
///
public string SkuId { get => skuId; set { Set(ref skuId, value); } }
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 string brand;
///
/// 品牌
///
public string Brand { get => brand; set { Set(ref brand, value); } }
private string productNo;
///
/// 货号
///
public string ProductNo { get => productNo; set { Set(ref productNo, value); } }
private string brandName;
///
/// 品名(手写上传)
///
public string BrandName { get => brandName; set { Set(ref brandName, value); } }
private int goodsNumber;
///
/// 配件数
///
public int GoodsNumber { get => goodsNumber; set { Set(ref goodsNumber, value); } }
private Worry isWorry;
///
/// 是否加急
///
public Worry IsWorry { get => isWorry; set { Set(ref isWorry, value); } }
private TaskState availability;
///
/// 到货情况(待收货=0,部分收货=1,已到货=2)
///
public TaskState Availability { get => availability; set { Set(ref availability, value); } }
private PackType packType;
///
/// 打包类型(单件=0,多件=1)
///
public PackType PackType { get => packType; set { Set(ref packType, value); } }
private BasicPack basicPack;
///
/// 基础包装(快递袋=0,纸箱=1,麻袋=2)
///
public BasicPack BasicPack { get => basicPack; set { Set(ref basicPack, value); } }
private PositionType positionType;
///
/// 落仓(本地仓=0,齐越仓=1,京东仓=2)
///
public PositionType PositionType { get => positionType; set { Set(ref positionType, value); } }
private string skuTitle;
///
/// sku配件商品名称
///
public string SkuTitle { get => skuTitle; set { Set(ref skuTitle, value); } }
private Need isNeedBarCode;
///
/// 是否需要合格证
///
public Need IsNeedBarCode { get => isNeedBarCode; set { Set(ref isNeedBarCode, value); } }
private Need isNeedCertificateModel;
///
/// 是否需要条形码
///
public Need 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);
IsNeedBarCode = IsSetBarCode ? Need.不需要 : Need.需要;
}
}
private bool isSetCertificate;
///
/// 设置显示(合格证)
///
public bool IsSetCertificate
{
get => isSetCertificate; set
{
Set(ref isSetCertificate, value);
IsNeedCertificateModel = IsSetCertificate ? Need.不需要 : Need.需要;
}
}
private string setSpuCerStatus;
public string SetSpuCerStatus { get => setSpuCerStatus; set { Set(ref setSpuCerStatus, value); } }
private bool isSetSpuCertificate = true;
///
/// 设置spu显示(合格证)
///
public bool IsSetSpuCertificate
{
get => isSetSpuCertificate; set
{
Set(ref isSetSpuCertificate, value);
SetSpuCerStatus = IsSetSpuCertificate ? "设置spu模板" : "修改spu模板";
}
}
private string saveTask;
///
/// 设置显示(合格证)
///
public string SaveTask { get => saveTask; set { Set(ref saveTask, value); } }
private string spuId;
///
/// 合格证
///
public string SpuId { get => spuId; set { Set(ref spuId, value); } }
private CertificateModel spuCertificateModel;
///
/// spu合格证
///
public CertificateModel SpuCertificateModel { get => spuCertificateModel; set { Set(ref spuCertificateModel, 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); } }
private ObservableCollection increateList;
///
/// 增量耗材查询关键字
///
public ObservableCollection IncreateList { get => increateList; set { Set(ref increateList, value); } }
#endregion
string[] increates = new string[] { "气泡纸", "气泡袋", "POP袋", "折纸箱", "气泡纸封边", "彩盒", "剪胶", "剪彩带", "快递袋", "收纳盒", "纸箱子", "装纸箱", "封边", "胶带", "折彩盒" };
public PackTaskService packTaskService;
public ProductService productService;
public BatchPublishTask()
{
IncreateList = new ObservableCollection();
foreach (var item in increates)
{
IncreateList.Add(new IncreateModel
{
IncreateName = item,
IsSelected = false
});
}
SetBarCodeCommand = new RelayCommand(SetBarCode);
SetCertificateCommand = new RelayCommand(SetCertificate);
LookBarCommand = new RelayCommand(LookBar);
LookCerCommand = new RelayCommand(LookCer);
}
#region 方法
public ICommand SetBarCodeCommand { get; set; }
public ICommand SetCertificateCommand { get; set; }
public ICommand LookBarCommand { get; set; }
public ICommand LookCerCommand { get; set; }
private void SetBarCode()
{
if (string.IsNullOrEmpty(SkuId))
{
return;
}
if (BarCodeModel == null)
{
BarCodeModel = new BarCodeModel();
BarCodeModel.ProductNo = ProductNo;
BarCodeModel.Brand = Brand;
BarCodeModel.SkuId = SkuId;
BarCodeModel.SkuName = SkuName;
}
if (!string.IsNullOrEmpty(BrandName))
BarCodeModel.BrandName = BrandName;
SetBarCodeWindow setBarCodeWindow = new SetBarCodeWindow();
setBarCodeWindow.LoadData(BarCodeModel, packTaskService);
setBarCodeWindow.SaveResult = b =>
{
BarCodeModel = b;
IsSetBarCode = false;
IsNeedBarCode = Need.需要;
};
setBarCodeWindow.Show();
}
///
/// 设置合格证
///
private void SetCertificate()
{
if (string.IsNullOrEmpty(SkuId))
return;
SearSpuCer();
if (CertificateModel == null)
{
CertificateModel = new CertificateModel();
CertificateModel.ProductNo = ProductNo;
CertificateModel.Brand = Brand;
CertificateModel.SkuId = SkuId;
}
if (!string.IsNullOrEmpty(BrandName))
CertificateModel.BrandName = BrandName;
SetCerWindow setCerWindow = new SetCerWindow();
setCerWindow.LoadData(certificateModel, packTaskService, spuCertificateModel, IsSetSpuCertificate);
setCerWindow.SaveResult = s =>
{
CertificateModel = s;
IsSetCertificate = false;
IsNeedCertificateModel = Need.需要;
};
setCerWindow.Show();
}
///
/// 查看合格证
///
private void LookCer()
{
LookCerWindow lookCerWindow = new LookCerWindow(CertificateModel);
lookCerWindow.Show();
}
///
/// 查看条形码
///
private void LookBar()
{
LookBarCodeWindow look = new LookBarCodeWindow();
look.SetData(BarCodeModel);
look.Show();
}
///
/// 搜索 skuId
///
public void SearchSku(string skuid)
{
if (string.IsNullOrEmpty(skuid))
return;
ApiResponse productApiResponse = null;
var skuResponse = productService.GetProductSkuList(string.Empty, skuid);
if (skuResponse.Success)
{
if (skuResponse.Data.Count == 0)
{
return;
}
Logo = skuResponse.Data[0].Logo;
SkuName = skuResponse.Data[0].Title;
SpuId = skuResponse.Data[0].ProductId;
productApiResponse = productService.GetProductList(skuResponse.Data[0].ProductId, string.Empty, string.Empty, 1);
if (productApiResponse.Success)
{
if (productApiResponse.Data.Count == 0)
{
return;
}
ProductNo = productApiResponse.Data.Items[0].ProductItemNum;
Brand = productApiResponse.Data.Items[0].BrandName;
}
var productSku = packTaskService.GetProductSku(skuid);
if (productSku == null || !productSku.Success)
{
return;
}
if (productSku.Data.PackConfig != null)
{
var config = productSku.Data.PackConfig;
SkuTitle = config.SkuGoodsTitle;
GoodsNumber = config.GoodsNumber;
PackType = (PackType)config.PackType;
BasicPack = (BasicPack)config.BasicPack;
Availability = (TaskState)config.Availability;
MarkMessage = config.MarkMessage;
CertificatePosition = config.CertificatePosition == null ? CertificatePosition.无 : (CertificatePosition)config.CertificatePosition.Value;
// Increment1 = config.Increment1;
string[] increateDatas = config.Increment1.Split(',');
bool isSelected = false;
foreach (var item in increates)
{
isSelected = false;
if (increateDatas.Contains(item))
{
isSelected = true;
}
App.Current.Dispatcher.Invoke(() =>
{
IncreateList.Add(new IncreateModel
{
IncreateName = item,
IsSelected = isSelected
});
});
}
}
BrandName = productSku.Data.BrandName;
CertificateModel = productSku.Data.Certificate;
IsSetCertificate = false;
if (CertificateModel == null)
{
CertificateModel = new CertificateModel();
IsSetCertificate = true;
}
CertificateModel.Brand = Brand;
if (!string.IsNullOrEmpty(BrandName))
CertificateModel.BrandName = BrandName;
CertificateModel.ProductNo = ProductNo;
CertificateModel.SkuId = skuid;
BarCodeModel = productSku.Data.BarCodeModel;
IsSetBarCode = false;
if (BarCodeModel == null)
{
BarCodeModel = new BarCodeModel();
IsSetBarCode = true;
}
BarCodeModel.Brand = Brand;
if (!string.IsNullOrEmpty(BrandName))
BarCodeModel.BrandName = BrandName;
BarCodeModel.ProductNo = ProductNo;
BarCodeModel.SkuId = skuid;
BarCodeModel.SkuName = SkuName;
}
else
{
App.Current.Dispatcher.Invoke(() => MessageBox.Show(skuResponse.Msg, "加载sku"));
return;
}
//查看有木有存在
}
public void SearSpuCer()
{
if (string.IsNullOrEmpty(SpuId))
{
SearchSku(SkuId);
return;
}
SpuId = SpuId.Trim();//去掉空格 避免数据异常
var productSku = packTaskService.GetSpuCer(SpuId);
if (productSku == null || !productSku.Success)
{
IsSetSpuCertificate = true;
return;
}
SpuCertificateModel = productSku.Data;
IsSetSpuCertificate = false;
if (SpuCertificateModel == null)
{
SpuCertificateModel = new CertificateModel();
IsSetSpuCertificate = true;
SpuCertificateModel.Brand = Brand;
SpuCertificateModel.BrandName = BrandName;
SpuCertificateModel.ProductNo = ProductNo;
SpuCertificateModel.SpuId = SpuId;
}
}
public void InitData()
{
IncreateList = new ObservableCollection();
SpuId = string.Empty;
SaveTask = "发布";
Logo = string.Empty;
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;
foreach (var item in increates)
{
IncreateList.Add(new IncreateModel
{
IncreateName = item,
IsSelected = false
});
}
//SearchSku(SkuId);
}
#endregion
}
}