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.
190 lines
8.0 KiB
190 lines
8.0 KiB
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 ICommand SearchOrderCommand { 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)); //点击日期查询订单
|
|
});
|
|
SearchOrderCommand = new RelayCommand(() =>
|
|
{
|
|
InitSearchParam();
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
});
|
|
OrderPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
|
|
{
|
|
Task.Factory.StartNew(() => LoadOrder(p.PageIndex));
|
|
});
|
|
PageIndex = 1;
|
|
PageSize = 10;
|
|
EndDate = DateTime.Now;
|
|
StartDate = DateTime.Now.Date;
|
|
this.globalContext = globalContext;
|
|
this.orderService = orderService;
|
|
Task.Factory.StartNew(() => LoadOrder(PageIndex));
|
|
}
|
|
|
|
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;
|
|
|
|
response.Data.Items = new List<OrderResponse>()
|
|
{
|
|
new OrderResponse()
|
|
{
|
|
Id = "3213213121",
|
|
StartTime = DateTime.Now,
|
|
OrderState = Models.OrderState.等待采购,
|
|
OrderSellerPrice=100,
|
|
OrderCost = new OrderCostResponse(){
|
|
DeliveryExpressFreight=50,
|
|
Profit=100,
|
|
TotalCost=120,
|
|
PurchaseAmount=150
|
|
},
|
|
BuyerRemark="12312fffff",
|
|
Consignee = new ConsigneeResponse(){
|
|
Mobile="18996038927",
|
|
Province="重庆",
|
|
ContactName="山鸡"
|
|
},
|
|
ItemList = new List<OrderSkuResponse>(){
|
|
new OrderSkuResponse(){
|
|
ItemTotal=2,
|
|
Logo="https://img13.360buyimg.com/n9/s80x80_jfs/t1/87954/9/35896/95921/6431716fFa3d09cae/e1f687d25af0ddf1.jpg",
|
|
Price=15,
|
|
ProductId="10023985258330",
|
|
SkuId="10072665703169", Title="特大绿色托盘熊50CM"
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|