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.
151 lines
6.2 KiB
151 lines
6.2 KiB
2 years ago
|
using BBWYB.Client.APIServices;
|
||
|
using BBWYB.Client.Models;
|
||
|
using BBWYB.Client.Views.Order;
|
||
|
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.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 searchClientOrderId;
|
||
|
private string searchSourceShopName;
|
||
|
private string searchSourceSku;
|
||
|
private bool excludeCanceled;
|
||
|
private GlobalContext globalContext;
|
||
|
private OrderService orderService;
|
||
|
|
||
|
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 SearchClientOrderId { get => searchClientOrderId; set { SetProperty(ref searchClientOrderId, 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; }
|
||
|
|
||
|
public ICommand SetSearchDateCommand { get; set; }
|
||
|
public ICommand SetOrderStateCommand { get; set; }
|
||
|
public ICommand OrderPageIndexChangedCommand { get; set; }
|
||
|
|
||
|
public OrderViewModel(GlobalContext globalContext, OrderService orderService)
|
||
|
{
|
||
|
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)); //点击日期查询订单
|
||
|
});
|
||
|
OrderPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
|
||
|
{
|
||
|
Task.Factory.StartNew(() => LoadOrder(p.PageIndex));
|
||
|
});
|
||
|
PageSize = 10;
|
||
|
EndDate = DateTime.Now;
|
||
|
StartDate = DateTime.Now.Date;
|
||
|
this.globalContext = globalContext;
|
||
|
this.orderService = orderService;
|
||
|
}
|
||
|
|
||
|
private void LoadOrder(int pageIndex)
|
||
|
{
|
||
|
IsLoading = true;
|
||
|
var response = orderService.GetOrderList(SearchOrderId, StartDate, EndDate, OrderState, SearchProductId, SearchSku, SearchClientOrderId, SearchSourceShopName, SearchSourceSku, PageIndex, PageSize, globalContext.User.Shop.ShopId, ExcludeCanceled);
|
||
|
|
||
|
if (!response.Success)
|
||
|
{
|
||
|
IsLoading = false;
|
||
|
App.Current.Dispatcher.Invoke(() =>
|
||
|
{
|
||
|
MessageBox.Show(response.Msg, "提示");
|
||
|
return;
|
||
|
});
|
||
|
}
|
||
|
IsLoading = false;
|
||
|
OrderCount = response.Data.Count;
|
||
|
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 o in list)
|
||
|
{
|
||
|
OrderList.Clear();
|
||
|
foreach (var order in list)
|
||
|
{
|
||
|
order.LocalConvert();
|
||
|
OrderList.Add(order);
|
||
|
}
|
||
|
WeakReferenceMessenger.Default.Send(new Message_OrderListScrollToTop(null));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 通过订单状态 筛选订单数据
|
||
|
/// </summary>
|
||
|
/// <param name="orderState">订单状态</param>
|
||
|
public void SetOrderState(OrderState? orderState)
|
||
|
{
|
||
|
InitSearchParam(orderState == null); //初始化查询参数 orderState == null 全部
|
||
|
this.OrderState = orderState;
|
||
|
Task.Factory.StartNew(() => LoadOrder(1)); //选择状态查询订单
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 初始化查询参数
|
||
|
/// </summary>
|
||
|
/// <param name="isInitDate"></param>
|
||
|
private void InitSearchParam(bool isInitDate = false)
|
||
|
{
|
||
|
this.OrderState = null;
|
||
|
SearchOrderId = string.Empty;
|
||
|
SearchSku = string.Empty;
|
||
|
SearchProductId = string.Empty;
|
||
|
SearchClientOrderId = string.Empty;
|
||
|
SearchSourceShopName = string.Empty;
|
||
|
SearchSourceSku = string.Empty;
|
||
|
if (isInitDate)
|
||
|
{
|
||
|
EndDate = DateTime.Now;
|
||
|
StartDate = DateTime.Now.Date;
|
||
|
}
|
||
|
PageIndex = 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|