|
|
|
using BBWY.Client.APIServices;
|
|
|
|
using BBWY.Client.Models;
|
|
|
|
using BBWY.Common.Extensions;
|
|
|
|
using BBWY.Common.Models;
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
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 BBWY.Client.ViewModels
|
|
|
|
{
|
|
|
|
public class ServiceOrderViewModel : BaseVM, IDenpendency
|
|
|
|
{
|
|
|
|
private ServiceOrderService serviceOrderService;
|
|
|
|
|
|
|
|
private bool isLoading;
|
|
|
|
private ServiceOrderState? serviceOrderState;
|
|
|
|
private ReturnDirection? returnDirection;
|
|
|
|
private long serviceOrderCount;
|
|
|
|
private int pageIndex;
|
|
|
|
private int pageSize;
|
|
|
|
private string orderId;
|
|
|
|
private string spu;
|
|
|
|
private string sku;
|
|
|
|
private string serviceId;
|
|
|
|
private DateTime? startDate;
|
|
|
|
private DateTime? endDate;
|
|
|
|
|
|
|
|
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
|
|
|
|
|
|
|
|
public ServiceOrderState? ServiceOrderState { get => serviceOrderState; set { Set(ref serviceOrderState, value); } }
|
|
|
|
|
|
|
|
public ReturnDirection? ReturnDirection { get => returnDirection; set { Set(ref returnDirection, value); } }
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand SetServiceOrderStateCommand { get; set; }
|
|
|
|
public ICommand SetReturnDirectionCommand { get; set; }
|
|
|
|
public ICommand OnPageIndexChangedCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand CopyTextCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand SetSearchDateCommand { get; set; }
|
|
|
|
|
|
|
|
public ICommand SearchServiceOrderCommand { get; set; }
|
|
|
|
|
|
|
|
public IList<ServiceOrder> ServiceOrderList { get; set; }
|
|
|
|
|
|
|
|
public long ServiceOrderCount { get => serviceOrderCount; set { Set(ref serviceOrderCount, value); } }
|
|
|
|
|
|
|
|
public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } }
|
|
|
|
|
|
|
|
public int PageSize { get => pageSize; set { Set(ref pageSize, value); } }
|
|
|
|
|
|
|
|
public string OrderId { get => orderId; set { Set(ref orderId, value); } }
|
|
|
|
|
|
|
|
public string Spu { get => spu; set { Set(ref spu, value); } }
|
|
|
|
|
|
|
|
public string Sku { get => sku; set { Set(ref sku, value); } }
|
|
|
|
|
|
|
|
public string ServiceId { get => serviceId; set { Set(ref serviceId, value); } }
|
|
|
|
|
|
|
|
public DateTime? StartDate { get => startDate; set { Set(ref startDate, value); } }
|
|
|
|
|
|
|
|
public DateTime? EndDate { get => endDate; set { Set(ref endDate, value); } }
|
|
|
|
|
|
|
|
public GlobalContext GlobalContext { get; set; }
|
|
|
|
|
|
|
|
public ServiceOrderViewModel(ServiceOrderService serviceOrderService, GlobalContext globalContext)
|
|
|
|
{
|
|
|
|
this.serviceOrderService = serviceOrderService;
|
|
|
|
SetServiceOrderStateCommand = new RelayCommand<ServiceOrderState?>(SetServiceOrderState);
|
|
|
|
SetReturnDirectionCommand = new RelayCommand<ReturnDirection?>(SetReturnDirection);
|
|
|
|
CopyTextCommand = new RelayCommand<string>(s => { try { Clipboard.SetText(s); } catch (Exception ex) { } });
|
|
|
|
SetSearchDateCommand = new RelayCommand<int>(SetSearchDate);
|
|
|
|
SearchServiceOrderCommand = new RelayCommand(SearchServiceOrder);
|
|
|
|
ServiceOrderList = new ObservableCollection<ServiceOrder>() { new ServiceOrder(), new ServiceOrder(), new ServiceOrder() };
|
|
|
|
PageSize = 10;
|
|
|
|
GlobalContext = globalContext;
|
|
|
|
EndDate = DateTime.Now.Date;
|
|
|
|
StartDate = DateTime.Now.Date.AddDays(-15);
|
|
|
|
SearchServiceOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SearchServiceOrder()
|
|
|
|
{
|
|
|
|
PageIndex = 1;
|
|
|
|
Task.Factory.StartNew(() => QueryServiceOrder(PageIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetSearchDate(int d)
|
|
|
|
{
|
|
|
|
EndDate = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now;
|
|
|
|
StartDate = DateTime.Now.Date.AddDays(d * -1);
|
|
|
|
SearchServiceOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetServiceOrderState(ServiceOrderState? state)
|
|
|
|
{
|
|
|
|
this.ServiceOrderState = state;
|
|
|
|
//query
|
|
|
|
SearchServiceOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetReturnDirection(ReturnDirection? returnDirection)
|
|
|
|
{
|
|
|
|
this.ReturnDirection = returnDirection;
|
|
|
|
//query
|
|
|
|
SearchServiceOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void QueryServiceOrder(int pageIndex)
|
|
|
|
{
|
|
|
|
IsLoading = true;
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
this.ServiceOrderList.Clear();
|
|
|
|
ServiceOrderCount = 0;
|
|
|
|
});
|
|
|
|
var response = serviceOrderService.GetList(OrderId, Sku, Spu, ServiceId, GlobalContext.User.Shop.ShopId.ToString(), ServiceOrderState, ReturnDirection, pageIndex, PageSize, StartDate, EndDate);
|
|
|
|
if (!response.Success)
|
|
|
|
{
|
|
|
|
IsLoading = false;
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
MessageBox.Show(response.Msg, "提示");
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (response.Data.Items == null || response.Data.Items.Count() == 0)
|
|
|
|
{
|
|
|
|
IsLoading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsLoading = false;
|
|
|
|
ServiceOrderCount = response.Data.Count;
|
|
|
|
var list = response.Data.Items.Map<IList<ServiceOrder>>();
|
|
|
|
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
|
|
{
|
|
|
|
foreach (var s in list)
|
|
|
|
{
|
|
|
|
//转换ImageName
|
|
|
|
ServiceOrderList.Add(s);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|