You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.2 KiB
93 lines
3.2 KiB
using BBWYB.Client.APIServices;
|
|
using BBWYB.Client.Models;
|
|
using BBWYB.Common.Models;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace BBWYB.Client.ViewModels
|
|
{
|
|
public class ChoosePurchaseSchemeViewModel : BaseVM, IDenpendency
|
|
{
|
|
private PurchaseService purchaseService;
|
|
private GlobalContext globalContext;
|
|
private Order order;
|
|
private bool noPurchaser;
|
|
|
|
public IList<Purchaser> PurchaserList { get; set; }
|
|
public bool NoPurchaser { get => noPurchaser; set { SetProperty(ref noPurchaser, value); } }
|
|
|
|
//public ICommand DeleteCommand { get; set; }
|
|
//public ICommand EditCommand { get; set; }
|
|
public ICommand PreviewPurchaseCommand { get; set; }
|
|
|
|
|
|
|
|
public ChoosePurchaseSchemeViewModel(PurchaseService purchaseService, GlobalContext globalContext)
|
|
{
|
|
this.purchaseService = purchaseService;
|
|
this.globalContext = globalContext;
|
|
this.PurchaserList = new ObservableCollection<Purchaser>();
|
|
//DeleteCommand = new RelayCommand<PurchaseScheme>(Delete);
|
|
//EditCommand = new RelayCommand<PurchaseScheme>(Edit);
|
|
PreviewPurchaseCommand = new RelayCommand<Purchaser>(PreviewPurchase);
|
|
}
|
|
|
|
protected override void Load()
|
|
{
|
|
PurchaserList.Clear();
|
|
Task.Factory.StartNew(() => LoadPurchaser());
|
|
}
|
|
|
|
protected override void Unload()
|
|
{
|
|
this.order = null;
|
|
this.NoPurchaser = false;
|
|
PurchaserList.Clear();
|
|
}
|
|
|
|
public void SetData(Order order)
|
|
{
|
|
this.order = order;
|
|
}
|
|
|
|
public void LoadPurchaser()
|
|
{
|
|
var skuIdList = order.ItemList.Select(osku => osku.SkuId).ToList();
|
|
var purchaserResponse = purchaseService.GetSharePurchaser(skuIdList, globalContext.User.Shop.ShopId);
|
|
if (!purchaserResponse.Success)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(purchaserResponse.Msg, "获取采购商"));
|
|
return;
|
|
}
|
|
NoPurchaser = (purchaserResponse.Data?.Count() ?? 0) == 0;
|
|
if (purchaserResponse.Data != null && purchaserResponse.Data.Count() > 0)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
foreach (var p in purchaserResponse.Data) PurchaserList.Add(p);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
public void PreviewPurchase(Purchaser purchaser)
|
|
{
|
|
var purchaseAccount = globalContext.User.Shop.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == purchaser.Platform);
|
|
if (purchaseAccount == null)
|
|
{
|
|
MessageBox.Show($"缺少{purchaser.Platform}的采购账号", "提示");
|
|
return;
|
|
}
|
|
|
|
var p = new _1688Purchase(order, purchaser, purchaseAccount);
|
|
p.ShowDialog();
|
|
GalaSoft.MvvmLight.Messaging.Messenger.Default.Send<object>(null, "ChoosePurchaseScheme_Close");
|
|
|
|
}
|
|
}
|
|
}
|
|
|