using BBWY.Client.Models; using BBWY.Controls; using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Input; namespace BBWY.Client.Views.Order { /// /// RelationPurchaseOrder.xaml 的交互逻辑 /// public partial class RelationPurchaseOrder : BWindow { public ICommand AddRelationPurchaseOrderSkuCommand { get; set; } public ICommand AddOrderDropShippingCommand { get; set; } public ICommand CloseShowChooseSkuPanelCommand { get; set; } public ICommand RePurchaseCommand { get; set; } public ICommand CopyTextCommand { get; set; } public IList OrderDropShippingList { get; set; } public IList HistoryOrderDropShippingList { get; set; } public IList RelationPurchaseOrderSkuList { get; set; } public IList ChooseRelationPurchaseOrderSkuList { get; set; } public IList PurchaseAccountList { get; set; } public string OrderId { get; set; } public bool IsShowHistoryOrderDropShoppingList { get; set; } public decimal TotalCost { get => totalCost; set { Set(ref totalCost, value); } } public bool IsShowChooseSkuPanel { get => isShowChooseSkuPanel; set { if (Set(ref isShowChooseSkuPanel, value)) { if (!value) OnShowChooseSkuPanelClose(); } } } private decimal totalCost; private bool isShowChooseSkuPanel; private OrderDropShipping currentOds; public bool IsRePurchase { get; private set; } public RelationPurchaseOrder(string orderId, IList purchaseAccountList, IList orderDropShippingList, IList historyOrderDropShippingList, IList relationPurchaseOrderSkuList) { InitializeComponent(); this.DataContext = this; this.PurchaseAccountList = purchaseAccountList; this.OrderId = orderId; OrderDropShippingList = new ObservableCollection(); HistoryOrderDropShippingList = historyOrderDropShippingList; IsShowHistoryOrderDropShoppingList = (historyOrderDropShippingList?.Count() ?? 0) > 0; if (orderDropShippingList != null) { foreach (var ods in orderDropShippingList) { var ods1 = ods.Clone() as OrderDropShipping; ods1.PurchaseFreightStr = ods1.PurchaseFreight.ToString(); var currentOdsSkuList = relationPurchaseOrderSkuList.Where(rsku => rsku.OrderDropShippingId == ods1.Id); foreach (var rsku in currentOdsSkuList) ods1.RelationPurchaseOrderSkuList.Add(rsku); OrderDropShippingList.Add(ods1); ods1.OnPurchaseAmountChanged = OnPurchaseAmountChanged; } } RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; ChooseRelationPurchaseOrderSkuList = new ObservableCollection(); RefreshChooseRelationPurchaseOrderSkuList(); foreach (var sku in RelationPurchaseOrderSkuList) sku.OnSkuAmountChanged = OnSkuAmountChanged; OnPurchaseAmountChanged(); AddOrderDropShippingCommand = new RelayCommand(() => OrderDropShippingList.Add(new OrderDropShipping() { OrderId = this.OrderId, BuyerAccount = PurchaseAccountList.FirstOrDefault()?.AccountName, OnPurchaseAmountChanged = OnPurchaseAmountChanged })); AddRelationPurchaseOrderSkuCommand = new RelayCommand(AddRelationPurchaseOrderSku); CloseShowChooseSkuPanelCommand = new RelayCommand(() => IsShowChooseSkuPanel = false); RePurchaseCommand = new RelayCommand(() => { if (MessageBox.Show("请确认是否重新采购,确定之后之前的采购单号将无法修改", "提醒", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { IsRePurchase = true; this.DialogResult = false; this.Close(); } }); CopyTextCommand = new RelayCommand(s => { try { Clipboard.SetText(s); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ResetColor(); } } ); } private void OnSkuAmountChanged() { foreach (var ods in OrderDropShippingList) ods.SkuAmount = ods.RelationPurchaseOrderSkuList.Sum(sku => sku.SkuAmount); } private void OnPurchaseAmountChanged() { TotalCost = OrderDropShippingList.Sum(ods => ods.PurchaseAmount); } private void btn_Save_Click(object sender, RoutedEventArgs e) { if (OrderDropShippingList.Count() == 0) { MessageBox.Show("关联订单信息不全", "提示"); return; } if (OrderDropShippingList.Any(ods => ods.RelationPurchaseOrderSkuList.Count() == 0 || string.IsNullOrEmpty(ods.PurchaseOrderId) || string.IsNullOrEmpty(ods.SellerAccount) || string.IsNullOrEmpty(ods.BuyerAccount) || ods.PurchaseAmount == 0)) { MessageBox.Show("关联订单信息不全", "提示"); return; } //if (string.IsNullOrEmpty(OrderDropShipping.PurchaseOrderId) || // string.IsNullOrEmpty(OrderDropShipping.SellerAccount) || // string.IsNullOrEmpty(OrderDropShipping.BuyerAccount) || // OrderDropShipping.PurchaseAmount == 0) //{ // MessageBox.Show("关联订单信息不全", "提示"); // return; //} this.DialogResult = true; this.Close(); } private void AddRelationPurchaseOrderSku(OrderDropShipping ods) { currentOds = ods; IsShowChooseSkuPanel = true; } private void OnShowChooseSkuPanelClose() { var chooseSkuList = ChooseRelationPurchaseOrderSkuList.Where(rsku => rsku.IsSelected); foreach (var chooseSku in chooseSkuList) { chooseSku.OrderDropShippingId = currentOds.Id; currentOds.RelationPurchaseOrderSkuList.Add(chooseSku); } RefreshChooseRelationPurchaseOrderSkuList(); } private void RefreshChooseRelationPurchaseOrderSkuList() { ChooseRelationPurchaseOrderSkuList.Clear(); var noChooseList = RelationPurchaseOrderSkuList.Where(rsku => rsku.OrderDropShippingId == null); foreach (var noChooseSku in noChooseList) ChooseRelationPurchaseOrderSkuList.Add(noChooseSku); } } }