|
|
@ -19,14 +19,17 @@ namespace BBWY.Client.ViewModels |
|
|
|
{ |
|
|
|
#region Properties
|
|
|
|
private GlobalContext globalContext; |
|
|
|
private OneBoundAPIService oneBoundAPIService; |
|
|
|
private PurchaseService purchaseService; |
|
|
|
private PurchaseProductAPIService purchaseProductAPIService; |
|
|
|
|
|
|
|
private string purchaserName; |
|
|
|
private bool isLoading; |
|
|
|
|
|
|
|
//public Product Product { get; set; }
|
|
|
|
private Platform purchasePlatform; |
|
|
|
|
|
|
|
|
|
|
|
private IDictionary<Platform, string> urlPatternDictionary; |
|
|
|
|
|
|
|
|
|
|
|
public IList<ProductSku> ProductSkuList { get; set; } |
|
|
|
|
|
|
@ -35,6 +38,8 @@ namespace BBWY.Client.ViewModels |
|
|
|
public string PurchaserLocation { get; set; } |
|
|
|
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } |
|
|
|
|
|
|
|
public Platform PurchasePlatform { get => purchasePlatform; set { Set(ref purchasePlatform, value); } } |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ICommands
|
|
|
@ -58,10 +63,9 @@ namespace BBWY.Client.ViewModels |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
public BindingPurchaseProductViewModel(PurchaseProductAPIService purchaseProductAPIService, OneBoundAPIService oneBoundAPIService, PurchaseService purchaseService, GlobalContext globalContext) |
|
|
|
public BindingPurchaseProductViewModel(PurchaseProductAPIService purchaseProductAPIService, PurchaseService purchaseService, GlobalContext globalContext) |
|
|
|
{ |
|
|
|
this.globalContext = globalContext; |
|
|
|
this.oneBoundAPIService = oneBoundAPIService; |
|
|
|
this.purchaseService = purchaseService; |
|
|
|
this.purchaseProductAPIService = purchaseProductAPIService; |
|
|
|
ClosingCommand = new RelayCommand<System.ComponentModel.CancelEventArgs>(Closing); |
|
|
@ -73,14 +77,20 @@ namespace BBWY.Client.ViewModels |
|
|
|
SavePurchaseSchemeCommand = new RelayCommand(SavePurchaseScheme); |
|
|
|
SearchPurchaseSkuNameCommand = new RelayCommand<PurchaseSchemeProduct>(SearchPurchaseSkuName); |
|
|
|
ClearPurchaseSkuNameCommand = new RelayCommand<PurchaseSchemeProduct>(ClearPurchaseSkuName); |
|
|
|
urlPatternDictionary = new Dictionary<Platform, string>() |
|
|
|
{ |
|
|
|
{ Platform.阿里巴巴,@"^(https://detail.1688.com/offer/(\d+).html)[^\s]*" }, |
|
|
|
{ Platform.拳探, @"^(https://qt.qiyue666.com/goods_detail/(\d+))(\?\w*)?$" } |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public void SetData(IList<ProductSku> productSkuList, string purchaserId, string purchaserName) |
|
|
|
public void SetData(IList<ProductSku> productSkuList, string purchaserId, string purchaserName, Platform purchasePlatform) |
|
|
|
{ |
|
|
|
this.ProductSkuList = productSkuList; |
|
|
|
//this.Product = product;
|
|
|
|
this.PurchaserId = purchaserId; |
|
|
|
this.PurchaserName = purchaserName; |
|
|
|
this.PurchasePlatform = purchasePlatform; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void Load() |
|
|
@ -88,48 +98,48 @@ namespace BBWY.Client.ViewModels |
|
|
|
if (!string.IsNullOrEmpty(PurchaserId)) |
|
|
|
{ |
|
|
|
IsLoading = true; |
|
|
|
Task.Factory.StartNew(() => purchaseService.GetPurchaseSchemeList(ProductSkuList.Select(s => s.Id).ToList(), PurchaserId, globalContext.User.Shop.ShopId)).ContinueWith(r => |
|
|
|
{ |
|
|
|
var apiResponse = r.Result; |
|
|
|
if (!apiResponse.Success) |
|
|
|
{ |
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)delegate |
|
|
|
{ |
|
|
|
MessageBox.Show(apiResponse.Msg, "查询采购方案"); |
|
|
|
}); |
|
|
|
IsLoading = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var purchaseSchemeList = apiResponse.Data; |
|
|
|
|
|
|
|
var waitList = new List<EventWaitHandle>(); |
|
|
|
foreach (var sku in ProductSkuList) |
|
|
|
{ |
|
|
|
//当前SKU下当前采购商的采购方案
|
|
|
|
var apiScheme = purchaseSchemeList.FirstOrDefault(s => s.SkuId == sku.Id && s.PurchaserId == PurchaserId); |
|
|
|
|
|
|
|
if (apiScheme == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
sku.SelectedPurchaseScheme = PurchaseScheme.Convert(apiScheme); |
|
|
|
var ewh = new ManualResetEvent(false); |
|
|
|
waitList.Add(ewh); |
|
|
|
|
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
foreach (var purchaseSchemeProduct in sku.SelectedPurchaseScheme.PurchaseSchemeProductList) |
|
|
|
{ |
|
|
|
purchaseSchemeProduct.IsEditing = false; |
|
|
|
LoadPurchaseProduct(sku.SelectedPurchaseScheme.PurchasePlatform, purchaseSchemeProduct, purchaseSchemeProduct.PurchaseProductId, null, out _); |
|
|
|
} |
|
|
|
ewh.Set(); |
|
|
|
ewh.Dispose(); |
|
|
|
}); |
|
|
|
} |
|
|
|
WaitHandle.WaitAll(waitList.ToArray()); |
|
|
|
IsLoading = false; |
|
|
|
}); |
|
|
|
Task.Factory.StartNew(() => purchaseService.GetPurchaseSchemeList(ProductSkuList.Select(s => s.Id).ToList(), PurchaserId, globalContext.User.Shop.ShopId, purchasePlatform: PurchasePlatform)).ContinueWith(r => |
|
|
|
{ |
|
|
|
var apiResponse = r.Result; |
|
|
|
if (!apiResponse.Success) |
|
|
|
{ |
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)delegate |
|
|
|
{ |
|
|
|
MessageBox.Show(apiResponse.Msg, "查询采购方案"); |
|
|
|
}); |
|
|
|
IsLoading = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var purchaseSchemeList = apiResponse.Data; |
|
|
|
|
|
|
|
var waitList = new List<EventWaitHandle>(); |
|
|
|
foreach (var sku in ProductSkuList) |
|
|
|
{ |
|
|
|
//当前SKU下当前采购商的采购方案
|
|
|
|
var apiScheme = purchaseSchemeList.FirstOrDefault(s => s.SkuId == sku.Id && s.PurchaserId == PurchaserId); |
|
|
|
|
|
|
|
if (apiScheme == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
sku.SelectedPurchaseScheme = PurchaseScheme.Convert(apiScheme); |
|
|
|
var ewh = new ManualResetEvent(false); |
|
|
|
waitList.Add(ewh); |
|
|
|
|
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
foreach (var purchaseSchemeProduct in sku.SelectedPurchaseScheme.PurchaseSchemeProductList) |
|
|
|
{ |
|
|
|
purchaseSchemeProduct.IsEditing = false; |
|
|
|
LoadPurchaseProduct(sku.SelectedPurchaseScheme.PurchasePlatform, purchaseSchemeProduct, purchaseSchemeProduct.PurchaseProductId, null, out _); |
|
|
|
} |
|
|
|
ewh.Set(); |
|
|
|
ewh.Dispose(); |
|
|
|
}); |
|
|
|
} |
|
|
|
WaitHandle.WaitAll(waitList.ToArray()); |
|
|
|
IsLoading = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -243,20 +253,6 @@ namespace BBWY.Client.ViewModels |
|
|
|
// }).ToList();
|
|
|
|
//}
|
|
|
|
|
|
|
|
private string GetSkuLogo(JToken skuJToken, JArray prop_img) |
|
|
|
{ |
|
|
|
if (!prop_img.HasValues) |
|
|
|
return "pack://application:,,,/Resources/Images/defaultItem.png"; |
|
|
|
var properties = skuJToken.Value<string>("properties").Split(';', StringSplitOptions.RemoveEmptyEntries); |
|
|
|
foreach (var p in properties) |
|
|
|
{ |
|
|
|
var imgJToken = prop_img.FirstOrDefault(g => g.Value<string>("properties") == p); |
|
|
|
if (imgJToken != null) |
|
|
|
return imgJToken.Value<string>("url"); |
|
|
|
} |
|
|
|
return "pack://application:,,,/Resources/Images/defaultItem.png"; |
|
|
|
} |
|
|
|
|
|
|
|
private void AddPurchaseProduct(ProductSku productSku) |
|
|
|
{ |
|
|
|
if (productSku.PurchaseSchemeList.Count > 4) |
|
|
@ -271,7 +267,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
{ |
|
|
|
ProductId = productSku.ProductId, |
|
|
|
SkuId = productSku.Id, |
|
|
|
PurchasePlatform = Platform.阿里巴巴 |
|
|
|
PurchasePlatform = PurchasePlatform |
|
|
|
}; |
|
|
|
} |
|
|
|
else if (productSku.SelectedPurchaseScheme.PurchaseSchemeProductList.Count >= 4) |
|
|
@ -309,7 +305,10 @@ namespace BBWY.Client.ViewModels |
|
|
|
MessageBox.Show("商品url不能为空"); |
|
|
|
return; |
|
|
|
} |
|
|
|
var match = Regex.Match(purchaseSchemeProduct.PurchaseUrl, @"^(https://detail.1688.com/offer/(\d+).html)[^\s]*"); |
|
|
|
|
|
|
|
urlPatternDictionary.TryGetValue(PurchasePlatform, out string pattern); |
|
|
|
|
|
|
|
var match = Regex.Match(purchaseSchemeProduct.PurchaseUrl, pattern); |
|
|
|
if (!match.Success) |
|
|
|
{ |
|
|
|
MessageBox.Show("未能识别的url"); |
|
|
|