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.
72 lines
2.3 KiB
72 lines
2.3 KiB
using BBWYB.Client.Models;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace BBWYB.Client.ViewModels
|
|
{
|
|
public class EditPriceViewModel : BaseVM
|
|
{
|
|
public IList<OrderSkuEditPrice> OrderSkuList { get; set; }
|
|
private Order order;
|
|
private decimal freightAmount;
|
|
private bool isResponseFreightChanged;
|
|
|
|
public ICommand DistributFreightCommand { get; set; }
|
|
public decimal FreightAmount { get => freightAmount; set { SetProperty(ref freightAmount, value); } }
|
|
|
|
public EditPriceViewModel()
|
|
{
|
|
OrderSkuList = new ObservableCollection<OrderSkuEditPrice>();
|
|
DistributFreightCommand = new RelayCommand(DistributFreight);
|
|
}
|
|
|
|
private void SetData(Order order)
|
|
{
|
|
this.order = order;
|
|
foreach (var orderSku in order.ItemList)
|
|
{
|
|
OrderSkuList.Add(new OrderSkuEditPrice()
|
|
{
|
|
Id = orderSku.Id,
|
|
Logo = orderSku.Logo,
|
|
Title = orderSku.Title,
|
|
SkuId = orderSku.SkuId,
|
|
Price = orderSku.Price,
|
|
NewPrice = orderSku.Price ?? 0,
|
|
ItemTotal = orderSku.ItemTotal,
|
|
OnFreightChanged = OnFreightChanged
|
|
});
|
|
}
|
|
}
|
|
|
|
private void DistributFreight()
|
|
{
|
|
if (FreightAmount <= 0)
|
|
{
|
|
MessageBox.Show("运费不正确", "提示");
|
|
return;
|
|
}
|
|
isResponseFreightChanged = false;
|
|
var totalItemCount = OrderSkuList.Sum(s => s.ItemTotal);
|
|
foreach (var orderSku in OrderSkuList)
|
|
{
|
|
var quantityRatio = 1M * orderSku.ItemTotal / totalItemCount;
|
|
var currentFreightAmount = FreightAmount * quantityRatio;
|
|
orderSku.FreightAmount = currentFreightAmount;
|
|
orderSku.IsResponseFreightChanged = true;
|
|
}
|
|
isResponseFreightChanged = true;
|
|
}
|
|
|
|
private void OnFreightChanged()
|
|
{
|
|
if (!isResponseFreightChanged)
|
|
return;
|
|
|
|
}
|
|
}
|
|
}
|
|
|