步步为盈
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.

214 lines
8.3 KiB

using BBWY.Client.Models;
using BBWY.Controls;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
3 years ago
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace BBWY.Client.Views.Order
{
/// <summary>
/// RelationPurchaseOrder.xaml 的交互逻辑
/// </summary>
public partial class RelationPurchaseOrder : BWindow
{
public ICommand AddRelationPurchaseOrderSkuCommand { get; set; }
public ICommand AddOrderDropShippingCommand { get; set; }
public ICommand CloseShowChooseSkuPanelCommand { get; set; }
3 years ago
public ICommand RePurchaseCommand { get; set; }
3 years ago
public ICommand CopyTextCommand { get; set; }
3 years ago
public IList<OrderDropShipping> OrderDropShippingList { get; set; }
3 years ago
public IList<OrderDropShipping> HistoryOrderDropShippingList { get; set; }
public IList<RelationPurchaseOrderSku> RelationPurchaseOrderSkuList { get; set; }
public IList<RelationPurchaseOrderSku> ChooseRelationPurchaseOrderSkuList { get; set; }
3 years ago
public IList<PurchaseAccount> PurchaseAccountList { get; set; }
public string OrderId { get; set; }
3 years ago
public bool IsShowHistoryOrderDropShoppingList { get; set; }
3 years ago
public decimal TotalCost { get => totalCost; set { Set(ref totalCost, value); } }
public bool IsShowChooseSkuPanel
{
get => isShowChooseSkuPanel; set
{
if (Set(ref isShowChooseSkuPanel, value))
{
if (!value)
OnShowChooseSkuPanelClose();
}
}
}
3 years ago
private decimal totalCost;
private bool isShowChooseSkuPanel;
private OrderDropShipping currentOds;
3 years ago
public bool IsRePurchase { get; private set; }
3 years ago
3 years ago
public RelationPurchaseOrder(string orderId,
IList<PurchaseAccount> purchaseAccountList,
IList<OrderDropShipping> orderDropShippingList,
IList<OrderDropShipping> historyOrderDropShippingList,
IList<RelationPurchaseOrderSku> relationPurchaseOrderSkuList)
{
InitializeComponent();
this.DataContext = this;
3 years ago
this.PurchaseAccountList = purchaseAccountList;
this.OrderId = orderId;
OrderDropShippingList = new ObservableCollection<OrderDropShipping>();
3 years ago
HistoryOrderDropShippingList = historyOrderDropShippingList;
IsShowHistoryOrderDropShoppingList = (historyOrderDropShippingList?.Count() ?? 0) > 0;
3 years ago
if (orderDropShippingList != null)
{
3 years ago
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);
3 years ago
OrderDropShippingList.Add(ods1);
ods1.OnPurchaseAmountChanged = OnPurchaseAmountChanged;
ods1.OnPurchasePlatformChanged = OnPurchasePlatformChanged;
3 years ago
}
}
3 years ago
RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList;
ChooseRelationPurchaseOrderSkuList = new ObservableCollection<RelationPurchaseOrderSku>();
RefreshChooseRelationPurchaseOrderSkuList();
foreach (var sku in RelationPurchaseOrderSkuList)
sku.OnSkuAmountChanged = OnSkuAmountChanged;
3 years ago
OnPurchaseAmountChanged();
AddOrderDropShippingCommand = new RelayCommand(() =>
{
var ods = new OrderDropShipping()
{
OrderId = this.OrderId,
//BuyerAccount = PurchaseAccountList.FirstOrDefault()?.AccountName,
OnPurchaseAmountChanged = OnPurchaseAmountChanged,
OnPurchasePlatformChanged = OnPurchasePlatformChanged
};
ods.PurchasePlatform = Platform.;
OrderDropShippingList.Add(ods);
});
AddRelationPurchaseOrderSkuCommand = new RelayCommand<OrderDropShipping>(AddRelationPurchaseOrderSku);
CloseShowChooseSkuPanelCommand = new RelayCommand(() => IsShowChooseSkuPanel = false);
3 years ago
RePurchaseCommand = new RelayCommand(() =>
{
if (MessageBox.Show("请确认是否重新采购,确定之后之前的采购单号将无法修改", "提醒", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
IsRePurchase = true;
this.DialogResult = false;
this.Close();
}
});
3 years ago
CopyTextCommand = new RelayCommand<string>(s =>
{
try
{
Clipboard.SetText(s);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ResetColor();
}
}
);
}
private void OnSkuAmountChanged()
{
3 years ago
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;
}
3 years ago
//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);
}
private void OnPurchasePlatformChanged(OrderDropShipping orderDropShipping)
{
orderDropShipping.BuyerAccount = PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == orderDropShipping.PurchasePlatform)?.AccountName;
}
}
}