using BBWY.Client.APIServices; using BBWY.Client.Models; using BBWY.Client.Models.QiKu; using BBWY.Client.Views.BatchPurchase; using GalaSoft.MvvmLight.Command; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Input; namespace BBWY.Client.ViewModels { public class PackSkuSplitConfigViewModel : BaseVM { public IList PackSkuConfigList { get; set; } private IList storeList; public ICommand SetSplitCountCommand { get; set; } public ICommand SetPackCountAndStoreCommand { get; set; } public ICommand SaveCommand { get; set; } private LogisticsService logisticsService; public PackSkuSplitConfigViewModel(LogisticsService logisticsService) { this.logisticsService = logisticsService; SetSplitCountCommand = new RelayCommand(SetSplitCount); SetPackCountAndStoreCommand = new RelayCommand(SetPackCountAndStore); SaveCommand = new RelayCommand(Save); PackSkuConfigList = new ObservableCollection(); } public void SetData(IList packSkuConfigList) { foreach (var item in packSkuConfigList) PackSkuConfigList.Add(item); } public IList GetPackSkuConfigList() { return PackSkuConfigList; } private void SetSplitCount(PackSkuConfig packSkuConfig) { if (packSkuConfig.SplitCount <= 0) { MessageBox.Show("份数不正确"); return; } packSkuConfig.PackSkuSplitConfigList.Clear(); for (var i = 1; i <= packSkuConfig.SplitCount; i++) { packSkuConfig.PackSkuSplitConfigList.Add(new PackSkuSplitConfig() { Index = i, PackCount = 0 }); } } private void SetPackCountAndStore(PackSkuSplitConfig packSkuSplitConfig) { if (storeList == null) { var response = logisticsService.GetStoreList(); if (!response.Success) { MessageBox.Show(response.Msg, "获取仓库"); return; } storeList = response.Data; } var w = new PackSkuSplitCountAndStoreWindow(packSkuSplitConfig.PackCount, packSkuSplitConfig.Store, storeList); if (w.ShowDialog() == true) { packSkuSplitConfig.PackCount = w.Quantity; packSkuSplitConfig.Store = w.Store; } } private void Save() { if (PackSkuConfigList.Any(s => s.PackSkuSplitConfigList.Count() == 0 || s.PackSkuSplitConfigList.Any(sp => sp.PackCount <= 0))) { MessageBox.Show("装箱设置不正确", "提示"); return; } if (PackSkuConfigList.Any(s => s.PurchaseCount != s.PackSkuSplitConfigList.Sum(sp => sp.PackCount))) { MessageBox.Show("打包份数总数与采购数量不相等", "提示"); return; } GalaSoft.MvvmLight.Messaging.Messenger.Default.Send(true, "PackSkuConfigWindowClose"); } } }