|
|
|
using BBWYB.Client.APIServices;
|
|
|
|
using BBWYB.Client.Models;
|
|
|
|
using BBWYB.Client.Views.Order;
|
|
|
|
using BBWYB.Client.Views.PackPurchaseTaska;
|
|
|
|
using BBWYB.Common.Extensions;
|
|
|
|
using BBWYB.Common.Models;
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
using SJ.Controls;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
namespace BBWYB.Client.ViewModels
|
|
|
|
{
|
|
|
|
public class OrderViewModel : BaseVM, IDenpendency
|
|
|
|
{
|
|
|
|
private bool isLoading;
|
|
|
|
private DateTime startDate;
|
|
|
|
private DateTime endDate;
|
|
|
|
private int pageIndex = 1;
|
|
|
|
private int pageSize = 10;
|
|
|
|
private long orderCount;
|
|
|
|
private OrderState? orderState;
|
|
|
|
private string searchSku;
|
|
|
|
private string searchProductId;
|
|
|
|
private string searchOrderId;
|
|
|
|
private string searchPurchaseOrderId;
|
|
|
|
private string searchSourceShopName;
|
|
|
|
private string searchSourceSku;
|
|
|
|
private bool excludeCanceled;
|
|
|
|
private GlobalContext globalContext;
|
|
|
|
private OrderService orderService;
|
|
|
|
private bool isWaitConfig;
|
|
|
|
|
|
|
|
public bool IsLoading { get => isLoading; set { SetProperty(ref isLoading, value); } }
|
|
|
|
|
|
|
|
public DateTime StartDate { get => startDate; set { SetProperty(ref startDate, value); } }
|
|
|
|
|
|
|
|
public DateTime EndDate { get => endDate; set { SetProperty(ref endDate, value); } }
|
|
|
|
public int PageIndex { get => pageIndex; set { SetProperty(ref pageIndex, value); } }
|
|
|
|
public int PageSize { get => pageSize; set { SetProperty(ref pageSize, value); } }
|
|
|
|
public long OrderCount { get => orderCount; set { SetProperty(ref orderCount, value); } }
|
|
|
|
public OrderState? OrderState { get => orderState; set { SetProperty(ref orderState, value); } }
|
|
|
|
public string SearchSku { get => searchSku; set { SetProperty(ref searchSku, value); } }
|
|
|
|
public string SearchProductId { get => searchProductId; set { SetProperty(ref searchProductId, value); } }
|
|
|
|
public string SearchOrderId { get => searchOrderId; set { SetProperty(ref searchOrderId, value); } }
|
|
|
|
public string SearchPurchaseOrderId { get => searchPurchaseOrderId; set { SetProperty(ref searchPurchaseOrderId, value); } }
|
|
|
|
public string SearchSourceShopName { get => searchSourceShopName; set { SetProperty(ref searchSourceShopName, value); } }
|
|
|
|
public string SearchSourceSku { get => searchSourceSku; set { SetProperty(ref searchSourceSku, value); } }
|
|
|
|
public bool ExcludeCanceled { get => excludeCanceled; set { SetProperty(ref excludeCanceled, value); } }
|
|
|
|
public IList<Order> OrderList { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 是否为待配置
|
|
|
|
/// </summary>
|
|
|
|
public bool IsWaitConfig { get => isWaitConfig; set { SetProperty(ref isWaitConfig, value); } }
|
|
|
|
|
|
|
|
public ICommand SetSearchDateCommand { get; set; }
|
|
|
|
public ICommand SetOrderStateCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand SetWaitConfigCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand OrderPageIndexChangedCommand { get; set; }
|
|
|
|
public ICommand SearchOrderCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand OnlinePurchaseCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand CancelOrderCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand EditPriceCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand EditPackConfigCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public OrderViewModel(GlobalContext globalContext, OrderService orderService, PackPurchaseTaskService packPurchaseTaskService)
|
|
|
|
{
|
|
|
|
OrderList = new ObservableCollection<Order>();
|
|
|
|
SetOrderStateCommand = new RelayCommand<OrderState?>(SetOrderState);
|
|
|
|
SetSearchDateCommand = new RelayCommand<int>(d =>
|
|
|
|
{
|
|
|
|
EndDate = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now;
|
|
|
|
StartDate = DateTime.Now.Date.AddDays(d * -1);
|
|
|
|
PageIndex = 1;
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex)); //点击日期查询订单
|
|
|
|
});
|
|
|
|
SearchOrderCommand = new RelayCommand(() =>
|
|
|
|
{
|
|
|
|
PageIndex = 1;
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
|
|
});
|
|
|
|
OrderPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
|
|
|
|
{
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(p.PageIndex));
|
|
|
|
});
|
|
|
|
OnlinePurchaseCommand = new RelayCommand<Order>(OnlinePurchase);
|
|
|
|
CancelOrderCommand = new RelayCommand<string>(CancelOrder);
|
|
|
|
EditPriceCommand = new RelayCommand<Order>(OpenEditPrice);
|
|
|
|
EditPackConfigCommand = new RelayCommand<Object>(EditPackConfig);
|
|
|
|
SetWaitConfigCommand = new RelayCommand(SetWaitConfig);
|
|
|
|
PageIndex = 1;
|
|
|
|
PageSize = 10;
|
|
|
|
EndDate = DateTime.Now;
|
|
|
|
StartDate = DateTime.Now.Date;
|
|
|
|
this.globalContext = globalContext;
|
|
|
|
this.orderService = orderService;
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
|
|
PackPurchaseTaskService = packPurchaseTaskService;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackPurchaseTaskService PackPurchaseTaskService;
|
|
|
|
private void EditPackConfig(Object obj)
|
|
|
|
{
|
|
|
|
var objList = (object[])obj;
|
|
|
|
var OriginShopName = (string)objList[0];
|
|
|
|
OrderSku order = (OrderSku)objList[1];
|
|
|
|
var res = PackPurchaseTaskService.GetOrderTask(order.BelongSkuId, order.OrderId);
|
|
|
|
if (res == null || !res.Success)
|
|
|
|
{
|
|
|
|
MessageBox.Show("网络异常!查不到任务");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (res.Data == null)
|
|
|
|
{
|
|
|
|
MessageBox.Show("打包任务,不存在或已被删除,请重新发起任务!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UpdatePurchaseTaskWindow packTask = new();
|
|
|
|
|
|
|
|
ViewModelLocator view = new();
|
|
|
|
var updatePackTask = view.UpdatePurchaseTask;
|
|
|
|
var show = updatePackTask.SearchSku(res.Data, OriginShopName, order);
|
|
|
|
|
|
|
|
|
|
|
|
if (!show) return;
|
|
|
|
|
|
|
|
|
|
|
|
updatePackTask.ReflashWindow = () =>
|
|
|
|
{
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
packTask.ShowDialog();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pageIndex"></param>
|
|
|
|
private void LoadOrder(int pageIndex)
|
|
|
|
{
|
|
|
|
IsLoading = true;
|
|
|
|
var response = orderService.GetOrderList(SearchOrderId,
|
|
|
|
StartDate,
|
|
|
|
EndDate,
|
|
|
|
OrderState,
|
|
|
|
SearchProductId,
|
|
|
|
SearchSku,
|
|
|
|
string.Empty,
|
|
|
|
SearchPurchaseOrderId,
|
|
|
|
SearchSourceShopName,
|
|
|
|
SearchSourceSku,
|
|
|
|
pageIndex,
|
|
|
|
PageSize,
|
|
|
|
globalContext.User.Shop.ShopId,
|
|
|
|
ExcludeCanceled,
|
|
|
|
IsWaitConfig);
|
|
|
|
|
|
|
|
if (!response.Success)
|
|
|
|
{
|
|
|
|
IsLoading = false;
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
MessageBox.Show(response.Msg, "提示");
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
IsLoading = false;
|
|
|
|
OrderCount = response.Data.Count;
|
|
|
|
App.Current.Dispatcher.Invoke(() => OrderList.Clear());
|
|
|
|
if (response.Data.Items == null || response.Data.Items.Count() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var list = response.Data.Items.Map<IList<Order>>();
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
foreach (var order in list)
|
|
|
|
{
|
|
|
|
order.LocalConvert();
|
|
|
|
OrderList.Add(order);
|
|
|
|
}
|
|
|
|
WeakReferenceMessenger.Default.Send(new Message_OrderListScrollToTop(null));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 通过订单状态 筛选订单数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="orderState">订单状态</param>
|
|
|
|
private void SetOrderState(OrderState? orderState)
|
|
|
|
{
|
|
|
|
InitSearchParam(orderState == null); //初始化查询参数 orderState == null 全部
|
|
|
|
this.OrderState = orderState;
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(1)); //选择状态查询订单
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetWaitConfig()
|
|
|
|
{
|
|
|
|
this.OrderState = null;
|
|
|
|
InitSearchParam(true);
|
|
|
|
this.IsWaitConfig = true;
|
|
|
|
Task.Factory.StartNew(() => LoadOrder(1)); //选择状态查询订单
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化查询参数
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="isInitDate"></param>
|
|
|
|
private void InitSearchParam(bool isInitDate = false)
|
|
|
|
{
|
|
|
|
this.OrderState = null;
|
|
|
|
IsWaitConfig = false;
|
|
|
|
SearchOrderId = string.Empty;
|
|
|
|
SearchSku = string.Empty;
|
|
|
|
SearchProductId = string.Empty;
|
|
|
|
SearchPurchaseOrderId = string.Empty;
|
|
|
|
SearchSourceShopName = string.Empty;
|
|
|
|
SearchSourceSku = string.Empty;
|
|
|
|
if (isInitDate)
|
|
|
|
{
|
|
|
|
EndDate = DateTime.Now;
|
|
|
|
StartDate = DateTime.Now.Date;
|
|
|
|
}
|
|
|
|
PageIndex = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnlinePurchase(Order order)
|
|
|
|
{
|
|
|
|
var choosePurchaseScheme = new ChoosePurchaseScheme(order);
|
|
|
|
choosePurchaseScheme.ShowDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Refresh()
|
|
|
|
{
|
|
|
|
OrderList.Clear();
|
|
|
|
//if (ToDayOrderAchievement != null)
|
|
|
|
//{
|
|
|
|
// ToDayOrderAchievement.AdvCost = 0M;
|
|
|
|
// ToDayOrderAchievement.DeliveryExpressFreight = 0M;
|
|
|
|
// ToDayOrderAchievement.OrderCount = 0;
|
|
|
|
// ToDayOrderAchievement.Profit = 0;
|
|
|
|
// ToDayOrderAchievement.PurchaseAmount = 0;
|
|
|
|
// ToDayOrderAchievement.SaleAmount = 0;
|
|
|
|
// ToDayOrderAchievement.SaleAmount = 0M;
|
|
|
|
// ToDayOrderAchievement.EmployereCost = 0M;
|
|
|
|
// ToDayOrderAchievement.TaxCost = 0M;
|
|
|
|
// ToDayOrderAchievement.SdCost = 0M;
|
|
|
|
// ToDayOrderAchievement.PularizeEndDate = null;
|
|
|
|
// ToDayOrderAchievement.ShoppopularizeList.Clear();
|
|
|
|
//}
|
|
|
|
PageIndex = 1;
|
|
|
|
OrderCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RefreshOrder(string orderId)
|
|
|
|
{
|
|
|
|
//Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
|
|
var order = OrderList.FirstOrDefault(o => o.Id == orderId);
|
|
|
|
if (order == null)
|
|
|
|
{
|
|
|
|
IsLoading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var orderResponse = orderService.GetOrderList(orderId, StartDate, EndDate, null, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 1, 10, globalContext.User.Shop.ShopId, true, IsWaitConfig);
|
|
|
|
IsLoading = false;
|
|
|
|
if (!orderResponse.Success)
|
|
|
|
{
|
|
|
|
Application.Current.Dispatcher.Invoke(() => MessageBox.Show(orderResponse.Msg, "查询订单详情"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (orderResponse.Data.Count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var newOrder = orderResponse.Data.Items.FirstOrDefault().Map<Order>();
|
|
|
|
newOrder.LocalConvert();
|
|
|
|
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
var orderIndex = OrderList.IndexOf(order);
|
|
|
|
OrderList.Remove(order);
|
|
|
|
OrderList.Insert(orderIndex, newOrder);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CancelOrder(string orderId)
|
|
|
|
{
|
|
|
|
if (MessageBox.Show("是否确认取消订单", "提示", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IsLoading = true;
|
|
|
|
Task.Factory.StartNew(() => orderService.CancelOrder(orderId, string.Empty))
|
|
|
|
.ContinueWith(t =>
|
|
|
|
{
|
|
|
|
IsLoading = false;
|
|
|
|
var response = t.Result;
|
|
|
|
if (!response.Success)
|
|
|
|
{
|
|
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "取消订单"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefreshOrder(orderId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void OpenEditPrice(Order order)
|
|
|
|
{
|
|
|
|
var edit = new EditPrice(order);
|
|
|
|
if (edit.ShowDialog() == true)
|
|
|
|
{
|
|
|
|
RefreshOrder(order.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|