diff --git a/BBWY.Client/APIServices/OrderService.cs b/BBWY.Client/APIServices/OrderService.cs index 829f88be..93a9657a 100644 --- a/BBWY.Client/APIServices/OrderService.cs +++ b/BBWY.Client/APIServices/OrderService.cs @@ -172,19 +172,12 @@ namespace BBWY.Client.APIServices }, null, HttpMethod.Post); } - /// - /// 关联代发订单 - /// - /// - /// - /// - public ApiResponse RelationPurchaseOrder(OrderDropShipping orderDropShipping, IList relationPurchaseOrderSkuList, decimal platformCommissionRatio) + public ApiResponse RelationPurchaseOrderV2(IList orderDropShippingList, decimal platformCommissionRatio) { - return SendRequest(globalContext.BBYWApiHost, "api/order/RelationPurchaseOrder", new + return SendRequest(globalContext.BBYWApiHost, "api/order/RelationPurchaseOrderV2", new { - orderDropShipping, - relationPurchaseOrderSkuList, - platformCommissionRatio + orderDropShippingList, + platformCommissionRatio, }, null, HttpMethod.Post); } diff --git a/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs index 7f417178..111c2d24 100644 --- a/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs +++ b/BBWY.Client/Models/Order/RelationPurchaseOrderSku.cs @@ -9,7 +9,7 @@ namespace BBWY.Client.Models { SingleSkuAmountStr = (0).ToString(); } - + private bool isSelected; private string singleSkuAmountStr; private decimal singleSkuAmount; private decimal skuAmount; @@ -65,5 +65,6 @@ namespace BBWY.Client.Models [JsonIgnore] public Action OnSkuAmountChanged { get; set; } + public bool IsSelected { get => isSelected; set { Set(ref isSelected, value); } } } } diff --git a/BBWY.Client/Resources/Themes/Path.xaml b/BBWY.Client/Resources/Themes/Path.xaml index ee3f6081..6fb002b1 100644 --- a/BBWY.Client/Resources/Themes/Path.xaml +++ b/BBWY.Client/Resources/Themes/Path.xaml @@ -22,4 +22,8 @@ + + \ No newline at end of file diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs index 1df73a67..35ddd5bc 100644 --- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs +++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs @@ -347,6 +347,25 @@ namespace BBWY.Client.ViewModels private void RelationPurchaseOrder_Closed(object sender, EventArgs e) { + var relationPurchaseOrder = sender as RelationPurchaseOrder; + if (relationPurchaseOrder.DialogResult != true) + return; + var orderDropShippingList = relationPurchaseOrder.OrderDropShippingList; + var orderId = relationPurchaseOrder.OrderId; + IsLoading = true; + Task.Factory.StartNew(() => orderService.RelationPurchaseOrderV2(orderDropShippingList, globalContext.User.Shop.PlatformCommissionRatio ?? 0.05M)) + .ContinueWith(t => + { + var response = t.Result; + if (!response.Success) + { + IsLoading = false; + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "关联采购订单")); + return; + } + RefreshOrder(orderId); + }); + //var relationPurchaseOrder = sender as RelationPurchaseOrder; //if (relationPurchaseOrder.DialogResult != true) // return; diff --git a/BBWY.Client/Views/Order/ManualCalculationCost.xaml b/BBWY.Client/Views/Order/ManualCalculationCost.xaml index 2311dd60..8ce2c948 100644 --- a/BBWY.Client/Views/Order/ManualCalculationCost.xaml +++ b/BBWY.Client/Views/Order/ManualCalculationCost.xaml @@ -203,17 +203,17 @@ Click="btn_fillFromLately_Click"/> --> - - - - - - - - - - + + + + + + + + + + diff --git a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml index 500cd995..d95d4aec 100644 --- a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml +++ b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml @@ -9,7 +9,7 @@ xmlns:sys="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" Title="关联采购订单" - Height="500" Width="500" + Height="800" Width="500" Style="{StaticResource bwstyle}" MinButtonVisibility="Collapsed" MaxButtonVisibility="Collapsed"> @@ -26,7 +26,7 @@ - + - + @@ -154,10 +154,12 @@ - + - + @@ -166,21 +168,81 @@ - - - - - - - - - - + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs index 8efe4c7b..35af9b7a 100644 --- a/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs +++ b/BBWY.Client/Views/Order/RelationPurchaseOrder.xaml.cs @@ -1,9 +1,12 @@ 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 { @@ -12,22 +15,48 @@ namespace BBWY.Client.Views.Order /// public partial class RelationPurchaseOrder : BWindow { + public ICommand AddRelationPurchaseOrderSkuCommand { get; set; } + + public ICommand AddOrderDropShippingCommand { get; set; } + + public ICommand CloseShowChooseSkuPanelCommand { get; set; } + + public IList OrderDropShippingList { get; set; } public IList RelationPurchaseOrderSkuList { get; set; } + public IList ChooseRelationPurchaseOrderSkuList { get; set; } + public IList PurchaseAccountList { get; set; } public string OrderId { 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 RelationPurchaseOrder(string orderId, IList purchaseAccountList, IList orderDropShippingList, IList relationPurchaseOrderSkuList) { InitializeComponent(); this.DataContext = this; + this.PurchaseAccountList = purchaseAccountList; this.OrderId = orderId; OrderDropShippingList = new ObservableCollection(); @@ -46,11 +75,22 @@ namespace BBWY.Client.Views.Order } } - this.RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; + RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; + ChooseRelationPurchaseOrderSkuList = new ObservableCollection(); + RefreshChooseRelationPurchaseOrderSkuList(); + foreach (var sku in RelationPurchaseOrderSkuList) sku.OnSkuAmountChanged = OnSkuAmountChanged; OnPurchaseAmountChanged(); + + AddOrderDropShippingCommand = new RelayCommand(() => OrderDropShippingList.Add(new OrderDropShipping() + { + BuyerAccount = PurchaseAccountList.FirstOrDefault()?.AccountName, + OnPurchaseAmountChanged = OnPurchaseAmountChanged + })); + AddRelationPurchaseOrderSkuCommand = new RelayCommand(AddRelationPurchaseOrderSku); + CloseShowChooseSkuPanelCommand = new RelayCommand(() => IsShowChooseSkuPanel = false); } private void OnSkuAmountChanged() @@ -64,8 +104,23 @@ namespace BBWY.Client.Views.Order TotalCost = OrderDropShippingList.Sum(ods => ods.PurchaseAmount); } - private void btn_Save_Click(object sender, System.Windows.RoutedEventArgs e) + 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) || @@ -77,5 +132,31 @@ namespace BBWY.Client.Views.Order 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); + } } }