|
|
@ -1,12 +1,17 @@ |
|
|
|
using BBWY.Client.APIServices; |
|
|
|
using BBWY.Client.Helpers; |
|
|
|
using BBWY.Client.Models; |
|
|
|
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; |
|
|
@ -16,6 +21,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
public class ServiceOrderViewModel : BaseVM, IDenpendency |
|
|
|
{ |
|
|
|
private ServiceOrderService serviceOrderService; |
|
|
|
private IHttpClientFactory httpClientFactory; |
|
|
|
|
|
|
|
private bool isLoading; |
|
|
|
private ServiceOrderState? serviceOrderState; |
|
|
@ -47,6 +53,10 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
public ICommand SearchServiceOrderCommand { get; set; } |
|
|
|
|
|
|
|
public ICommand NavigateToDetailCommand { get; set; } |
|
|
|
|
|
|
|
public ICommand PreviewImgCommand { get; set; } |
|
|
|
|
|
|
|
public IList<ServiceOrder> ServiceOrderList { get; set; } |
|
|
|
|
|
|
|
public long ServiceOrderCount { get => serviceOrderCount; set { Set(ref serviceOrderCount, value); } } |
|
|
@ -69,23 +79,27 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
public GlobalContext GlobalContext { get; set; } |
|
|
|
|
|
|
|
public ServiceOrderViewModel(ServiceOrderService serviceOrderService, GlobalContext globalContext) |
|
|
|
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(SearchServiceOrder); |
|
|
|
SearchServiceOrderCommand = new RelayCommand(InitQueryServiceOrder); |
|
|
|
NavigateToDetailCommand = new RelayCommand<string>(NavigateToDetail); |
|
|
|
OnPageIndexChangedCommand = new RelayCommand<PageArgs>(OnPageIndexChanged); |
|
|
|
PreviewImgCommand = new RelayCommand<string>(PreviewImg); |
|
|
|
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(); |
|
|
|
InitQueryServiceOrder(); |
|
|
|
} |
|
|
|
|
|
|
|
private void SearchServiceOrder() |
|
|
|
private void InitQueryServiceOrder() |
|
|
|
{ |
|
|
|
PageIndex = 1; |
|
|
|
Task.Factory.StartNew(() => QueryServiceOrder(PageIndex)); |
|
|
@ -95,31 +109,26 @@ namespace BBWY.Client.ViewModels |
|
|
|
{ |
|
|
|
EndDate = d == 1 ? DateTime.Now.Date.AddDays(-1) : DateTime.Now; |
|
|
|
StartDate = DateTime.Now.Date.AddDays(d * -1); |
|
|
|
SearchServiceOrder(); |
|
|
|
InitQueryServiceOrder(); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetServiceOrderState(ServiceOrderState? state) |
|
|
|
{ |
|
|
|
this.ServiceOrderState = state; |
|
|
|
//query
|
|
|
|
SearchServiceOrder(); |
|
|
|
InitQueryServiceOrder(); |
|
|
|
} |
|
|
|
|
|
|
|
private void SetReturnDirection(ReturnDirection? returnDirection) |
|
|
|
{ |
|
|
|
this.ReturnDirection = returnDirection; |
|
|
|
//query
|
|
|
|
SearchServiceOrder(); |
|
|
|
InitQueryServiceOrder(); |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
@ -130,24 +139,107 @@ namespace BBWY.Client.ViewModels |
|
|
|
return; |
|
|
|
}); |
|
|
|
} |
|
|
|
if (response.Data.Items == null || response.Data.Items.Count() == 0) |
|
|
|
{ |
|
|
|
IsLoading = false; |
|
|
|
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"; |
|
|
|
} |
|
|
|
|
|
|
|
s.Init(); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
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}")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|