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.
283 lines
11 KiB
283 lines
11 KiB
using BBWY.Client.APIServices;
|
|
using BBWY.Client.Helpers;
|
|
using BBWY.Client.Models;
|
|
using BBWY.Client.Views.ServiceOrder;
|
|
using BBWY.Common.Extensions;
|
|
using BBWY.Common.Http;
|
|
using BBWY.Common.Models;
|
|
using BBWY.Controls;
|
|
using GalaSoft.MvvmLight.Command;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace BBWY.Client.ViewModels
|
|
{
|
|
public class ServiceOrderViewModel : BaseVM, IDenpendency
|
|
{
|
|
private ServiceOrderService serviceOrderService;
|
|
private IHttpClientFactory httpClientFactory;
|
|
|
|
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 SetSearchDateCommand { get; set; }
|
|
|
|
public ICommand SearchServiceOrderCommand { get; set; }
|
|
|
|
public ICommand NavigateToDetailCommand { get; set; }
|
|
|
|
public ICommand PreviewImgCommand { get; set; }
|
|
|
|
public ICommand EditServiceOrderCommand { 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, IHttpClientFactory httpClientFactory)
|
|
{
|
|
this.httpClientFactory = httpClientFactory;
|
|
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(InitQueryServiceOrder);
|
|
NavigateToDetailCommand = new RelayCommand<string>(NavigateToDetail);
|
|
OnPageIndexChangedCommand = new RelayCommand<PageArgs>(OnPageIndexChanged);
|
|
PreviewImgCommand = new RelayCommand<string>(PreviewImg);
|
|
EditServiceOrderCommand = new RelayCommand<ServiceOrder>(OpenEditServiceOrder);
|
|
ServiceOrderList = new ObservableCollection<ServiceOrder>() { new ServiceOrder(), new ServiceOrder(), new ServiceOrder() };
|
|
PageSize = 10;
|
|
GlobalContext = globalContext;
|
|
EndDate = DateTime.Now.Date;
|
|
StartDate = DateTime.Now.Date.AddDays(-15);
|
|
InitQueryServiceOrder();
|
|
}
|
|
|
|
private void InitQueryServiceOrder()
|
|
{
|
|
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);
|
|
InitQueryServiceOrder();
|
|
}
|
|
|
|
private void SetServiceOrderState(ServiceOrderState? state)
|
|
{
|
|
this.ServiceOrderState = state;
|
|
//query
|
|
InitQueryServiceOrder();
|
|
}
|
|
|
|
private void SetReturnDirection(ReturnDirection? returnDirection)
|
|
{
|
|
this.ReturnDirection = returnDirection;
|
|
//query
|
|
InitQueryServiceOrder();
|
|
}
|
|
|
|
private void QueryServiceOrder(int pageIndex)
|
|
{
|
|
IsLoading = true;
|
|
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;
|
|
});
|
|
}
|
|
|
|
IsLoading = false;
|
|
ServiceOrderCount = response.Data.Count;
|
|
App.Current.Dispatcher.Invoke(() => ServiceOrderList.Clear());
|
|
|
|
if (response.Data.Items == null || response.Data.Items.Count() == 0)
|
|
return;
|
|
|
|
var list = response.Data.Items.Map<IList<ServiceOrder>>();
|
|
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
foreach (var s in list)
|
|
{
|
|
#region Test
|
|
//转换ImageName
|
|
//if (int.Parse(s.ServiceId) % 2 == 0)
|
|
//{
|
|
// s.ProductPackage = ProductPackage.新; s.ImageName = "20230317071208762563,8d58b491-7859-4187-9f43-4fd177a0f25f,b0df0763-9cf4-40ca-a1fc-57695e4b8d33";
|
|
//}
|
|
#endregion
|
|
|
|
s.Init();
|
|
ServiceOrderList.Add(s);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void NavigateToDetail(string serviceId)
|
|
{
|
|
var url = $"https://sh.shop.jd.com/afs/detail/waitReceive?afsApplyId=undefined&afsServiceId={serviceId}";
|
|
try
|
|
{
|
|
//System.Diagnostics.Process.Start("explorer.exe", url);
|
|
ShellExecuteHelper.ShellExecute(IntPtr.Zero, "open", url, string.Empty, string.Empty, ShellExecuteHelper.ShowCommands.SW_SHOWNORMAL);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Clipboard.SetText(url);
|
|
MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
|
|
}
|
|
}
|
|
|
|
private void OnPageIndexChanged(PageArgs pageArgs)
|
|
{
|
|
Task.Factory.StartNew(() => QueryServiceOrder(pageArgs.PageIndex));
|
|
}
|
|
|
|
private void PreviewImg(string thumbnailImg)
|
|
{
|
|
var fullUrl = thumbnailImg.Substring(0, thumbnailImg.IndexOf("?"));
|
|
var fileName = fullUrl.Substring(fullUrl.LastIndexOf("/") + 1);
|
|
var localPath = Path.Combine(Path.GetTempPath(), fileName);
|
|
if (!File.Exists(localPath))
|
|
{
|
|
IsLoading = true;
|
|
var downloader = new HttpDownloader(httpClientFactory);
|
|
downloader.OnDownloadComplated += (s, e) =>
|
|
{
|
|
IsLoading = false;
|
|
if (e.Error != null)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(e.Error.Message));
|
|
return;
|
|
}
|
|
CallWindowsPhoto(localPath);
|
|
};
|
|
Task.Factory.StartNew(() => downloader.DownloadFile(fullUrl, Path.GetTempPath(), fileName, null));
|
|
}
|
|
else
|
|
{
|
|
CallWindowsPhoto(localPath);
|
|
}
|
|
}
|
|
|
|
private void CallWindowsPhoto(string path)
|
|
{
|
|
//建立新的系统进程
|
|
try
|
|
{
|
|
System.Diagnostics.Process process = new System.Diagnostics.Process();
|
|
|
|
//设置图片的真实路径和文件名
|
|
process.StartInfo.FileName = path;
|
|
|
|
//设置进程运行参数,这里以最大化窗口方法显示图片。
|
|
process.StartInfo.Arguments = "rundl132.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen";
|
|
|
|
//此项为是否使用Shell执行程序,因系统默认为true,此项也可不设,但若设置必须为true
|
|
process.StartInfo.UseShellExecute = true;
|
|
|
|
//此处可以更改进程所打开窗体的显示样式,可以不设
|
|
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
|
|
process.Start();
|
|
process.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show($"打开照片查看器失败 {ex.Message}"));
|
|
}
|
|
}
|
|
|
|
private void OpenEditServiceOrder(ServiceOrder serviceOrder)
|
|
{
|
|
var w = new EditServiceOrder(serviceOrder);
|
|
var r = w.ShowDialog();
|
|
if (r == true)
|
|
{
|
|
IsLoading = true;
|
|
Task.Factory.StartNew(() => RefreshServiceOrder(serviceOrder));
|
|
}
|
|
}
|
|
|
|
private void RefreshServiceOrder(long servicePId)
|
|
{
|
|
var order = ServiceOrderList.FirstOrDefault(s => s.Id == servicePId);
|
|
RefreshServiceOrder(order);
|
|
}
|
|
|
|
private void RefreshServiceOrder(ServiceOrder serviceOrder)
|
|
{
|
|
var serviceOrderResponse = serviceOrderService.GetList(string.Empty, string.Empty, string.Empty, serviceOrder.ServiceId, serviceOrder.ShopId, null, null, 1, 1, null, null);
|
|
IsLoading = false;
|
|
if (!serviceOrderResponse.Success)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() => MessageBox.Show(serviceOrderResponse.Msg, "刷新服务单"));
|
|
return;
|
|
}
|
|
|
|
var newServiceOrder = serviceOrderResponse.Data.Items.FirstOrDefault().Map<ServiceOrder>();
|
|
newServiceOrder.Init();
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
var orderIndex = ServiceOrderList.IndexOf(serviceOrder);
|
|
ServiceOrderList.Remove(serviceOrder);
|
|
ServiceOrderList.Insert(orderIndex, newServiceOrder);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|