|
|
|
using BBWY.Client.APIServices;
|
|
|
|
using BBWY.Client.Models;
|
|
|
|
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.Net.Mail;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace BBWY.Client.ViewModels
|
|
|
|
{
|
|
|
|
public class BatchPublishTaskViewModel : BaseVM, IDenpendency
|
|
|
|
{
|
|
|
|
|
|
|
|
PackTaskService packTaskService;
|
|
|
|
ProductService productService;
|
|
|
|
private bool isLoading = false;
|
|
|
|
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
|
|
|
|
|
|
|
|
private ObservableCollection<BatchPublishTask> batchPublishTasks;
|
|
|
|
public ObservableCollection<BatchPublishTask> BatchPublishTasks { get => batchPublishTasks; set { Set(ref batchPublishTasks, value); } }
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand CreateTaskCommand { get; set; }
|
|
|
|
public BatchPublishTaskViewModel(PackTaskService packTaskService, ProductService productService, GlobalContext globalContext)
|
|
|
|
{
|
|
|
|
BatchPublishTasks = new ObservableCollection<BatchPublishTask>();
|
|
|
|
this.packTaskService = packTaskService;
|
|
|
|
this.productService = productService;
|
|
|
|
CreateTaskCommand = new RelayCommand<object>(CreateTask);
|
|
|
|
this.globalContext = globalContext;
|
|
|
|
}
|
|
|
|
GlobalContext globalContext;
|
|
|
|
private void CreateTask(object obj)
|
|
|
|
{
|
|
|
|
foreach (var task in batchPublishTasks)
|
|
|
|
{
|
|
|
|
string increateStr = "";
|
|
|
|
var increates = task.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
|
|
|
|
{
|
|
|
|
ProductNo = task.ProductNo,
|
|
|
|
Logo = task.Logo,
|
|
|
|
SkuName = task.SkuName,
|
|
|
|
BrandName = task.BrandName,
|
|
|
|
Availability = (int)task.Availability,
|
|
|
|
BasicPack = (int)task.BasicPack,
|
|
|
|
SkuId = task.SkuId,
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
Increment1 = increateStr,
|
|
|
|
CertificatePosition = (int)task.CertificatePosition,
|
|
|
|
PackType = (int)task.PackType,
|
|
|
|
MarkMessage = task.MarkMessage,
|
|
|
|
PositionType = (int)task.PositionType,
|
|
|
|
GoodsNumber = task.GoodsNumber,
|
|
|
|
SkuGoodsTitle = task.SkuTitle,
|
|
|
|
SkuCount = task.SkuCount,
|
|
|
|
UserId = globalContext.User.Id.ToString(),
|
|
|
|
ShopId = PurchaserId,
|
|
|
|
IsWorry = task.IsWorry,
|
|
|
|
OrderId = orderId
|
|
|
|
};
|
|
|
|
if (task.IsNeedBarCode == Need.需要)
|
|
|
|
{
|
|
|
|
if (task.BarCodeModel == null || task.BarCodeModel.Id <= 0)
|
|
|
|
{
|
|
|
|
new TipsWindow("请设置条形码模板").Show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createTaskModel.BarCodeId = task.BarCodeModel.Id;
|
|
|
|
}
|
|
|
|
if (task.IsNeedCertificateModel == Need.需要)
|
|
|
|
{
|
|
|
|
if (task.CertificateModel == null || task.CertificateModel.Id <= 0)
|
|
|
|
{
|
|
|
|
new TipsWindow("请设置合格证模板").Show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createTaskModel.CertificateId = task.CertificateModel.Id;//
|
|
|
|
}
|
|
|
|
ApiResponse<object> res = null;
|
|
|
|
res = packTaskService.CreateTask(createTaskModel);
|
|
|
|
|
|
|
|
if (!res.Success)
|
|
|
|
{
|
|
|
|
new TipsWindow(res.Msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var win = obj as System.Windows.Window;
|
|
|
|
if (PublishTask != null) PublishTask();
|
|
|
|
win.Close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action PublishTask { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
Platform platform; string orderId; string PurchaserId;
|
|
|
|
public void AddSkus(Platform platform, string orderId, string PurchaserId, List<PurchaseOrderSku> purchaseOrderSkus)
|
|
|
|
{
|
|
|
|
BatchPublishTasks = new ObservableCollection<BatchPublishTask>();
|
|
|
|
this.platform = platform; this.orderId = orderId;
|
|
|
|
this.PurchaserId = PurchaserId;
|
|
|
|
BatchPublishTask model = null;
|
|
|
|
IsLoading = true;
|
|
|
|
foreach (var item in purchaseOrderSkus)
|
|
|
|
{
|
|
|
|
model = new BatchPublishTask();
|
|
|
|
model.productService = productService;
|
|
|
|
model.packTaskService = packTaskService;
|
|
|
|
model.SkuId = item.SkuId;
|
|
|
|
model.SkuCount = item.Quantity.Value;
|
|
|
|
model.Logo = item.Logo;
|
|
|
|
model.SpuId = item.ProductId;
|
|
|
|
model.SkuName = item.SkuTitle;
|
|
|
|
model.SearchSku(item.SkuId);
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
BatchPublishTasks.Add(model);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IsLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|