Files

135 lines
3.4 KiB
C#

using _29WxOrderWpf.BaseWindows;
using WxOrder.Framework.Commons;
using AllBase;
using AllBase.Model.DBModel;
using AllBase.Model.MvvmBaseClasses;
using AllBase.Model.Result;
using NaiBa.Util.Extension;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Work;
using Work._29Tools.BLL;
using Work._29Tools.Forms.ShopForms;
using Work.BaseForms;
namespace _29WxOrderWpf.ViewModels
{
/// <summary>
/// 更改运单号ViewModel
/// </summary>
public class EWaybillPathViewModel : PropertyNotifyObject
{
public oms_wei_order_info Order
{
get { return this.GetValue(x => x.Order); }
set { this.SetValue(x => x.Order, value); }
}
public string OrderId
{
get { return this.GetValue(x => x.OrderId); }
set { this.SetValue(x => x.OrderId, value); }
}
public string ExpressName
{
get { return this.GetValue(x => x.ExpressName); }
set { this.SetValue(x => x.ExpressName, value); }
}
public string WaybillId
{
get { return this.GetValue(x => x.WaybillId); }
set { this.SetValue(x => x.WaybillId, value); }
}
public bool IsGetWaybillPath
{
get { return this.GetValue(x => x.IsGetWaybillPath); }
set { this.SetValue(x => x.IsGetWaybillPath, value); }
}
public ObservableCollection<oms_wei_ewaybill_path> WaybillPathInfos
{
get { return this.GetValue(x => x.WaybillPathInfos); }
set { this.SetValue(x => x.WaybillPathInfos, value); }
}
/// <summary>
/// 请求关闭窗口
/// </summary>
public event Action RequestClose;
#region 命令
public ICommand GetEWaybillPathCommand { get; }
#endregion
private volatile bool _isWindowLoaded = false;
public EWaybillPathViewModel(oms_wei_order_info _order, string _waybillId, string _expressName)
{
Order = _order;
OrderId = Order?.order_id;
ExpressName = _expressName;
WaybillId = _waybillId;
IsGetWaybillPath = false;
GetEWaybillPathCommand = new DelegateCommand(GetEWaybillPath);
}
/// <summary>
/// 窗口加载完成时调用
/// </summary>
public void Start()
{
_isWindowLoaded = true;
GetEWaybillPath();
}
/// <summary>
/// 窗口关闭时调用,停止后台任务
/// </summary>
public void Stop()
{
_isWindowLoaded = false;
}
public void GetEWaybillPath()
{
string orderId = Order.order_id;
ShopLoginInfo shop = Order.Shop;
Task.Run(async () =>
{
IsGetWaybillPath = true;
var url = BaseClass.Build29WxObjString("order/wx_get_erp_ewaybill_path_list");
//var url = BaseClass.Build29WxObjString("order/wx_get_erp_ewaybill_path_latest_list");
var data = UserLogin.GetSignaturex();
//data += "&erp_order_id_in=" + order_id;
data += "&waybill_id_in=" + WaybillId;
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
{
BaseMsgWindow.ShowError("查询失败请重试");
return;
}
this.WaybillPathInfos = new ObservableCollection<oms_wei_ewaybill_path>(
JsonHelper.DeserializeJsonToList<oms_wei_ewaybill_path>(JObject.Parse(html)["data"].ParseToString()).OrderByDescending(p => p.update_time).ToList());
IsGetWaybillPath = false;
});
}
}
}