|
|
|
using BBWY.Client.APIServices;
|
|
|
|
using BBWY.Client.Models;
|
|
|
|
using BBWY.Common.Models;
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
namespace BBWY.Client.ViewModels
|
|
|
|
{
|
|
|
|
public class ChoosePurchaseSchemeViewModel : BaseVM, IDenpendency
|
|
|
|
{
|
|
|
|
private PurchaseService purchaseService;
|
|
|
|
private GlobalContext globalContext;
|
|
|
|
private BindingPurchaseProductViewModel bindingPurchaseProduct;
|
|
|
|
public string SkuId { get; set; }
|
|
|
|
public string SkuName { get; set; }
|
|
|
|
public IList<PurchaseScheme> PurchaseSchemeList { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand DeleteCommand { get; set; }
|
|
|
|
public ICommand EditCommand { get; set; }
|
|
|
|
|
|
|
|
public ChoosePurchaseSchemeViewModel(PurchaseService purchaseService, GlobalContext globalContext, BindingPurchaseProductViewModel bindingPurchaseProduct)
|
|
|
|
{
|
|
|
|
this.purchaseService = purchaseService;
|
|
|
|
this.globalContext = globalContext;
|
|
|
|
this.bindingPurchaseProduct = bindingPurchaseProduct;
|
|
|
|
PurchaseSchemeList = new ObservableCollection<PurchaseScheme>();
|
|
|
|
DeleteCommand = new RelayCommand<PurchaseScheme>(Delete);
|
|
|
|
EditCommand = new RelayCommand<PurchaseScheme>(Edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Load()
|
|
|
|
{
|
|
|
|
PurchaseSchemeList.Clear();
|
|
|
|
Task.Factory.StartNew(() => purchaseService.GetPurchaseSchemeList(new string[] { SkuId }, globalContext.User.Shop.ShopId)).ContinueWith(t =>
|
|
|
|
{
|
|
|
|
var r = t.Result;
|
|
|
|
if (!r.Success)
|
|
|
|
{
|
|
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(r.Msg, "获取采购方案"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
foreach (var apiModel in r.Data) PurchaseSchemeList.Add(PurchaseScheme.Convert(apiModel));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Unload()
|
|
|
|
{
|
|
|
|
this.SkuId = this.SkuName = string.Empty;
|
|
|
|
PurchaseSchemeList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData(string skuId, string skuName)
|
|
|
|
{
|
|
|
|
this.SkuId = skuId;
|
|
|
|
this.SkuName = skuName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(PurchaseScheme purchaseScheme)
|
|
|
|
{
|
|
|
|
Task.Factory.StartNew(() => purchaseService.DeletePurchaseScheme(purchaseScheme.Id)).ContinueWith(r =>
|
|
|
|
{
|
|
|
|
var response = r.Result;
|
|
|
|
if (response.Success)
|
|
|
|
App.Current.Dispatcher.Invoke(() => PurchaseSchemeList.Remove(purchaseScheme));
|
|
|
|
else
|
|
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "删除采购方案"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Edit(PurchaseScheme purchaseScheme)
|
|
|
|
{
|
|
|
|
var skuList = new List<ProductSku>()
|
|
|
|
{
|
|
|
|
new ProductSku(){ Id=purchaseScheme.SkuId,ProductId=purchaseScheme.ProductId, Title=SkuName}
|
|
|
|
};
|
|
|
|
bindingPurchaseProduct.SetData(skuList, purchaseScheme.PurchaserId, purchaseScheme.PurchaserName);
|
|
|
|
var bindingView = new Views.Ware.BindingPurchaseProduct();
|
|
|
|
var r = bindingView.ShowDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|