|
|
@ -6,8 +6,8 @@ using Newtonsoft.Json.Linq; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows; |
|
|
|
using System.Windows.Input; |
|
|
@ -20,8 +20,6 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
public IList<PurchaseSchemeProductSku> PurchaseSchemeProductSkuList { get; set; } |
|
|
|
|
|
|
|
public PurchaseScheme PurchaseScheme { get; set; } |
|
|
|
public PurchaseAccount PurchaseAccount { get; set; } |
|
|
|
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } |
|
|
|
|
|
|
|
public decimal ProductAmount { get => productAmount; set { Set(ref productAmount, value); } } |
|
|
@ -45,12 +43,16 @@ namespace BBWY.Client.ViewModels |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Purchaser purchaser; |
|
|
|
private Order order; |
|
|
|
private PurchaseAccount purchaseAccount; |
|
|
|
|
|
|
|
private IList<PurchaseScheme> purchaseSchemeList; |
|
|
|
private OrderListViewModel orderListViewModel; |
|
|
|
private GlobalContext globalContext; |
|
|
|
private string orderId; |
|
|
|
private int skuItemCount; |
|
|
|
private bool isLoading; |
|
|
|
private OneBoundAPIService oneBoundAPIService; |
|
|
|
private PurchaseService purchaseService; |
|
|
|
private PurchaseOrderService purchaseOrderService; |
|
|
|
private DelayTrigger delayTrigger; |
|
|
|
|
|
|
@ -68,48 +70,69 @@ namespace BBWY.Client.ViewModels |
|
|
|
private PurchaseOrderMode purchaseOrderMode = PurchaseOrderMode.代发; |
|
|
|
private string tradeMode; |
|
|
|
|
|
|
|
public _1688PreviewPurchaseViewModel(OneBoundAPIService oneBoundAPIService, PurchaseOrderService purchaseOrderService, GlobalContext globalContext, OrderListViewModel orderListViewModel) |
|
|
|
public _1688PreviewPurchaseViewModel(OneBoundAPIService oneBoundAPIService, |
|
|
|
PurchaseService purchaseService, |
|
|
|
PurchaseOrderService purchaseOrderService, |
|
|
|
GlobalContext globalContext, |
|
|
|
OrderListViewModel orderListViewModel) |
|
|
|
{ |
|
|
|
this.oneBoundAPIService = oneBoundAPIService; |
|
|
|
this.purchaseOrderService = purchaseOrderService; |
|
|
|
this.purchaseService = purchaseService; |
|
|
|
this.delayTrigger = new DelayTrigger(); |
|
|
|
this.delayTrigger.OnExecute = OnDelayTriggerExecute; |
|
|
|
PurchaseSchemeProductSkuList = new ObservableCollection<PurchaseSchemeProductSku>(); |
|
|
|
purchaseSchemeList = new List<PurchaseScheme>(); |
|
|
|
FastCreateOrderCommand = new RelayCommand(FastCreateOrder); |
|
|
|
this.globalContext = globalContext; |
|
|
|
this.orderListViewModel = orderListViewModel; |
|
|
|
//PurchaseOrderMode = PurchaseOrderMode.代发;
|
|
|
|
} |
|
|
|
|
|
|
|
public void SetData(string orderId, int skuItemCount, PurchaseScheme purchaseScheme, PurchaseAccount purchaseAccount, Consignee consignee) |
|
|
|
public void SetData(Order order, Purchaser purchaser, PurchaseAccount purchaseAccount) |
|
|
|
{ |
|
|
|
this.orderId = orderId; |
|
|
|
this.skuItemCount = skuItemCount; |
|
|
|
this.PurchaseScheme = purchaseScheme; |
|
|
|
this.PurchaseAccount = purchaseAccount; |
|
|
|
this.order = order; |
|
|
|
this.purchaser = purchaser; |
|
|
|
this.purchaseAccount = purchaseAccount; |
|
|
|
|
|
|
|
this.ContactName = consignee.ContactName; |
|
|
|
this.Address = consignee.Address; |
|
|
|
this.Province = consignee.Province; |
|
|
|
this.City = consignee.City; |
|
|
|
this.County = consignee.County; |
|
|
|
this.Town = consignee.Town; |
|
|
|
this.Mobile = consignee.Mobile; |
|
|
|
this.ContactName = order.Consignee.ContactName; |
|
|
|
this.Address = order.Consignee.Address; |
|
|
|
this.Province = order.Consignee.Province; |
|
|
|
this.City = order.Consignee.City; |
|
|
|
this.County = order.Consignee.County; |
|
|
|
this.Town = order.Consignee.Town; |
|
|
|
this.Mobile = order.Consignee.Mobile; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void Load() |
|
|
|
{ |
|
|
|
IsLoading = true; |
|
|
|
|
|
|
|
Task.Factory.StartNew(() => purchaseService.GetPurchaseSchemeList(order.ItemList.Select(osku => osku.Id).ToList(), purchaser.Id, globalContext.User.Shop.ShopId)) |
|
|
|
.ContinueWith(r => |
|
|
|
{ |
|
|
|
var purchaseSchemeResponse = r.Result; |
|
|
|
if (!purchaseSchemeResponse.Success) |
|
|
|
{ |
|
|
|
IsLoading = false; |
|
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(purchaseSchemeResponse.Msg, "获取采购方案")); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var waitList = new List<WaitHandle>(); |
|
|
|
foreach (var purchaseSchemeProduct in PurchaseScheme.PurchaseSchemeProductList) |
|
|
|
foreach (var purchaseSchemeApiModel in purchaseSchemeResponse.Data) |
|
|
|
{ |
|
|
|
var purchaseScheme = PurchaseScheme.Convert(purchaseSchemeApiModel); |
|
|
|
purchaseSchemeList.Add(purchaseScheme); |
|
|
|
foreach (var purchaseSchemeProduct in purchaseScheme.PurchaseSchemeProductList) |
|
|
|
{ |
|
|
|
var ewh = new ManualResetEvent(false); |
|
|
|
waitList.Add(ewh); |
|
|
|
Task.Factory.StartNew(() => LoadPurchaseProduct(purchaseSchemeProduct, ewh)); |
|
|
|
var orderSku = order.ItemList.FirstOrDefault(osku => osku.Id == purchaseScheme.SkuId); |
|
|
|
Task.Factory.StartNew(() => LoadPurchaseProduct(purchaseSchemeProduct, orderSku, ewh)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
WaitHandle.WaitAll(waitList.ToArray()); |
|
|
|
//IsLoading = false;
|
|
|
|
if (PurchaseSchemeProductSkuList.Count() > 0) |
|
|
@ -124,19 +147,21 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
protected override void Unload() |
|
|
|
{ |
|
|
|
order = null; |
|
|
|
purchaser = null; |
|
|
|
purchaseAccount = null; |
|
|
|
|
|
|
|
purchaseSchemeList.Clear(); |
|
|
|
PurchaseSchemeProductSkuList.Clear(); |
|
|
|
PurchaseScheme = null; |
|
|
|
orderId = string.Empty; |
|
|
|
tradeMode = string.Empty; |
|
|
|
skuItemCount = 0; |
|
|
|
ProductAmount = FreightAmount = TotalAmount = 0; |
|
|
|
ContactName = Address = Mobile = Province = City = County = Town = PrucahseRemark = string.Empty; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void LoadPurchaseProduct(PurchaseSchemeProduct purchaseSchemeProduct, ManualResetEvent ewh) |
|
|
|
private void LoadPurchaseProduct(PurchaseSchemeProduct purchaseSchemeProduct, OrderSku orderSku, ManualResetEvent ewh) |
|
|
|
{ |
|
|
|
var purchaseSchemeProductSkuList = LoadPurchaseProductCore(purchaseSchemeProduct.PurchaseProductId, out string errorMsg); |
|
|
|
var purchaseSchemeProductSkuList = LoadPurchaseProductCore(purchaseSchemeProduct, out string errorMsg); |
|
|
|
if (purchaseSchemeProductSkuList != null && purchaseSchemeProductSkuList.Count > 0) |
|
|
|
{ |
|
|
|
App.Current.Dispatcher.Invoke(() => |
|
|
@ -146,7 +171,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
if (purchaseSchemeProduct.SelectedSkuIdList.Any(s => s == purchaseSchemeProductSku.PurchaseSkuId)) |
|
|
|
{ |
|
|
|
PurchaseSchemeProductSkuList.Add(purchaseSchemeProductSku); |
|
|
|
purchaseSchemeProductSku.ItemTotal = skuItemCount; |
|
|
|
purchaseSchemeProductSku.ItemTotal = orderSku.ItemTotal; |
|
|
|
purchaseSchemeProductSku.OnItemTotalChanged = OnItemTotalChanged; |
|
|
|
} |
|
|
|
} |
|
|
@ -156,11 +181,11 @@ namespace BBWY.Client.ViewModels |
|
|
|
ewh.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
private IList<PurchaseSchemeProductSku> LoadPurchaseProductCore(string purchseProductId, out string errorMsg) |
|
|
|
private IList<PurchaseSchemeProductSku> LoadPurchaseProductCore(PurchaseSchemeProduct purchaseSchemeProduct, out string errorMsg) |
|
|
|
{ |
|
|
|
errorMsg = string.Empty; |
|
|
|
//1688商品详情接口
|
|
|
|
var response = oneBoundAPIService.GetProductInfo("1688", purchseProductId); |
|
|
|
var response = oneBoundAPIService.GetProductInfo("1688", purchaseSchemeProduct.PurchaseProductId); |
|
|
|
if (!response.Success) |
|
|
|
{ |
|
|
|
//记录日志
|
|
|
@ -183,15 +208,15 @@ namespace BBWY.Client.ViewModels |
|
|
|
var skuJArray = (JArray)jobject["item"]["skus"]["sku"]; |
|
|
|
if (skuJArray.Count == 0) |
|
|
|
{ |
|
|
|
errorMsg = $"商品{purchseProductId}缺少sku信息"; |
|
|
|
errorMsg = $"商品{purchaseSchemeProduct.PurchaseProductId}缺少sku信息"; |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return skuJArray.Select(j => new PurchaseSchemeProductSku() |
|
|
|
{ |
|
|
|
ProductId = PurchaseScheme.ProductId, |
|
|
|
SkuId = PurchaseScheme.SkuId, |
|
|
|
PurchaseProductId = purchseProductId, |
|
|
|
ProductId = purchaseSchemeProduct.ProductId, |
|
|
|
SkuId = purchaseSchemeProduct.SkuId, |
|
|
|
PurchaseProductId = purchaseSchemeProduct.PurchaseProductId, |
|
|
|
Price = j.Value<decimal>("price"), |
|
|
|
PurchaseSkuId = j.Value<string>("sku_id"), |
|
|
|
PurchaseSkuSpecId = j.Value<string>("spec_id"), |
|
|
@ -235,7 +260,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
Province = Province, |
|
|
|
TelePhone = Mobile, |
|
|
|
Town = Town |
|
|
|
}, PurchaseSchemeProductSkuList, Platform.阿里巴巴, PurchaseAccount, PurchaseOrderMode)) |
|
|
|
}, PurchaseSchemeProductSkuList, Platform.阿里巴巴, purchaseAccount, PurchaseOrderMode)) |
|
|
|
.ContinueWith(t => |
|
|
|
{ |
|
|
|
IsLoading = false; |
|
|
@ -286,15 +311,15 @@ namespace BBWY.Client.ViewModels |
|
|
|
Town = Town |
|
|
|
}, PurchaseSchemeProductSkuList, |
|
|
|
Platform.阿里巴巴, |
|
|
|
PurchaseAccount, |
|
|
|
purchaseAccount, |
|
|
|
PurchaseOrderMode, |
|
|
|
tradeMode, |
|
|
|
PrucahseRemark, |
|
|
|
orderId, |
|
|
|
order.Id, |
|
|
|
globalContext.User.Shop.ShopId, |
|
|
|
PurchaseAccount.Id, |
|
|
|
PurchaseAccount.AccountName, |
|
|
|
PurchaseScheme.PurchaserName)).ContinueWith(t => |
|
|
|
purchaseAccount.Id, |
|
|
|
purchaseAccount.AccountName, |
|
|
|
purchaseSchemeList[0].PurchaserName)).ContinueWith(t => |
|
|
|
{ |
|
|
|
IsLoading = false; |
|
|
|
var r = t.Result; |
|
|
@ -305,7 +330,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
} |
|
|
|
|
|
|
|
//刷新订单列表
|
|
|
|
orderListViewModel.RefreshOrder(orderId); |
|
|
|
orderListViewModel.RefreshOrder(order.Id); |
|
|
|
|
|
|
|
//关闭当前窗口
|
|
|
|
GalaSoft.MvvmLight.Messaging.Messenger.Default.Send<object>(null, "OnlinePurchase_Close"); |
|
|
|