|
@ -1,5 +1,9 @@ |
|
|
using BBWYB.Client.Models; |
|
|
using BBWYB.Client.APIServices; |
|
|
|
|
|
using BBWYB.Client.Models; |
|
|
|
|
|
using BBWYB.Client.Views.Order; |
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging; |
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.ObjectModel; |
|
|
using System.Collections.ObjectModel; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
@ -10,21 +14,27 @@ namespace BBWYB.Client.ViewModels |
|
|
{ |
|
|
{ |
|
|
public class EditPriceViewModel : BaseVM |
|
|
public class EditPriceViewModel : BaseVM |
|
|
{ |
|
|
{ |
|
|
|
|
|
private OrderService orderService; |
|
|
|
|
|
|
|
|
public IList<OrderSkuEditPrice> OrderSkuList { get; set; } |
|
|
public IList<OrderSkuEditPrice> OrderSkuList { get; set; } |
|
|
private Order order; |
|
|
private Order order; |
|
|
private decimal freightAmount; |
|
|
private decimal freightAmount; |
|
|
private bool isResponseFreightChanged; |
|
|
private bool isResponseFreightChanged; |
|
|
|
|
|
|
|
|
public ICommand DistributFreightCommand { get; set; } |
|
|
public ICommand DistributFreightCommand { get; set; } |
|
|
|
|
|
public ICommand SaveCommand { get; set; } |
|
|
|
|
|
|
|
|
public decimal FreightAmount { get => freightAmount; set { SetProperty(ref freightAmount, value); } } |
|
|
public decimal FreightAmount { get => freightAmount; set { SetProperty(ref freightAmount, value); } } |
|
|
|
|
|
|
|
|
public EditPriceViewModel() |
|
|
public EditPriceViewModel(OrderService orderService) |
|
|
{ |
|
|
{ |
|
|
OrderSkuList = new ObservableCollection<OrderSkuEditPrice>(); |
|
|
OrderSkuList = new ObservableCollection<OrderSkuEditPrice>(); |
|
|
DistributFreightCommand = new RelayCommand(DistributFreight); |
|
|
DistributFreightCommand = new RelayCommand(DistributFreight); |
|
|
|
|
|
SaveCommand = new RelayCommand(Save); |
|
|
|
|
|
this.orderService = orderService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SetData(Order order) |
|
|
public void SetData(Order order) |
|
|
{ |
|
|
{ |
|
|
this.order = order; |
|
|
this.order = order; |
|
|
foreach (var orderSku in order.ItemList) |
|
|
foreach (var orderSku in order.ItemList) |
|
@ -67,6 +77,46 @@ namespace BBWYB.Client.ViewModels |
|
|
if (!isResponseFreightChanged) |
|
|
if (!isResponseFreightChanged) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
isResponseFreightChanged = false; |
|
|
|
|
|
var waitDistributFreight = FreightAmount - OrderSkuList.Where(osku => !osku.IsResponseFreightChanged).Sum(osku => osku.FreightAmount); |
|
|
|
|
|
var waitDistributSkuList = OrderSkuList.Where(osku => osku.IsResponseFreightChanged); |
|
|
|
|
|
var totalItemCount = waitDistributSkuList.Sum(osku => osku.ItemTotal); |
|
|
|
|
|
foreach (var orderSku in waitDistributSkuList) |
|
|
|
|
|
{ |
|
|
|
|
|
var quantityRatio = 1M * orderSku.ItemTotal / totalItemCount; |
|
|
|
|
|
var currentFreightAmount = waitDistributFreight * quantityRatio; |
|
|
|
|
|
orderSku.FreightAmount = currentFreightAmount; |
|
|
|
|
|
orderSku.IsResponseFreightChanged = true; |
|
|
|
|
|
} |
|
|
|
|
|
isResponseFreightChanged = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Save() |
|
|
|
|
|
{ |
|
|
|
|
|
if (FreightAmount <= 0) |
|
|
|
|
|
{ |
|
|
|
|
|
MessageBox.Show("运费不正确", "提示"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (OrderSkuList.Any(osku => osku.FreightAmount <= 0 || osku.NewPrice <= 0)) |
|
|
|
|
|
{ |
|
|
|
|
|
MessageBox.Show("运费或单价不正确", "提示"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (Math.Abs(FreightAmount - OrderSkuList.Sum(osku => osku.FreightAmount)) > 1) |
|
|
|
|
|
{ |
|
|
|
|
|
MessageBox.Show("运费超出误差范围", "提示"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var response = orderService.EditPrice(this.order.Id, OrderSkuList); |
|
|
|
|
|
if (!response.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
MessageBox.Show(response.Msg, "提示"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
WeakReferenceMessenger.Default.Send(new Message_EditPrice_Close(null)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|