优化发票助手
This commit is contained in:
1 parent
6b36de2494
commit
a81ba26de8
9 files changed
+584
-262
No files matched your search
@@ -16,6 +16,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Work._29Tools.CefTools;
|
||||
using Work.BaseForms;
|
||||
using WxOrder.Framework.Helpers;
|
||||
|
||||
namespace _29WxOrderWpf.Ctrls.PDDInvoice.ViewModels;
|
||||
@@ -26,19 +27,11 @@ public partial class PDDInvoiceViewModel
|
||||
/// 订单列表浏览器
|
||||
/// </summary>
|
||||
public ChromiumWebBrowser Browser { get; private set; }
|
||||
/// <summary>
|
||||
/// 内容浏览器
|
||||
/// 订单详情
|
||||
/// 发票详情
|
||||
/// 申请发票
|
||||
/// </summary>
|
||||
public ChromiumWebBrowser BrowserDetail { get; private set; }
|
||||
private IFrame frame;
|
||||
|
||||
partial void InitBrowser()
|
||||
{
|
||||
BrowserZIndex = -1;
|
||||
BrowserDetailZIndex = -1;
|
||||
|
||||
Browser = WPFCEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
||||
|
||||
LocalResourceRequestHandler resourceRequestHandler = new LocalResourceRequestHandler();
|
||||
@@ -49,13 +42,7 @@ public partial class PDDInvoiceViewModel
|
||||
Browser.KeyboardHandler = new KeyboardHandler();
|
||||
Browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||
|
||||
BrowserDetail = WPFCEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
||||
LocalResourceRequestHandler detailResourceRequestHandler = new LocalResourceRequestHandler();
|
||||
detailResourceRequestHandler.ResourceLoadCompleteEvent += DetailRequestHandler_ResourceLoadComplete;
|
||||
BrowserDetail.RequestHandler = new LocalRequestHandler(resourceRequestHandler);
|
||||
BrowserDetail.LifeSpanHandler = new LocalLifeSpanHandler(PopWindowType.SelfWindow);
|
||||
BrowserDetail.KeyboardHandler = new KeyboardHandler();
|
||||
BrowserDetail.LoadingStateChanged += BrowserDetail_LoadingStateChanged;
|
||||
|
||||
}
|
||||
|
||||
private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
|
||||
@@ -65,75 +52,31 @@ public partial class PDDInvoiceViewModel
|
||||
var b = (ChromiumWebBrowser)sender;
|
||||
b.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
if (b.Address != null && b.Address.StartsWith("https://mobile.yangkeduo.com/orders.html"))
|
||||
{
|
||||
StartAutoScroll();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void BrowserDetail_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
|
||||
{
|
||||
if (e.IsLoading == false)
|
||||
{
|
||||
var b = (ChromiumWebBrowser)sender;
|
||||
b.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
if (b.Address != null && b.Address.StartsWith("https://mobile.yangkeduo.com/transac_return_compensation.html"))
|
||||
if (b.Address != null && b.Address.StartsWith("https://mobile.yangkeduo.com/orders.html"))//加载完成 加载 js
|
||||
{
|
||||
string html = await b.GetBrowser().GetSourceAsync();
|
||||
if (html.Contains("window.rawData"))
|
||||
frame = b.GetMainFrame();
|
||||
|
||||
string content = ResourceHelper.GetResourceText("/Ctrls/PDDInvoice/Resources/order.js", "29WxFindOrder");
|
||||
if (string.IsNullOrEmpty(content)) return;
|
||||
Install(frame, content);
|
||||
if (await IsInstalledAsync(frame))
|
||||
{
|
||||
await ExecuteInvoiceApplyScriptAsync(b);
|
||||
StartAutoScroll();
|
||||
//await b.EvaluateScriptAsync(frame, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 页面异常(未渲染出发票表单)时直接判定失败,避免批量开票长时间等待
|
||||
_currentInvoiceTcs?.TrySetResult(false);
|
||||
BaseMsgForm.ShowError("订单读取失败");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注入发票填写脚本并执行。
|
||||
/// 单张申请模式保持原有行为;批量开票模式下轮询脚本写入的
|
||||
/// <c>window.__invoiceApplyResult</c>,完成后通过 <see cref="_currentInvoiceTcs"/> 回传结果。
|
||||
/// </summary>
|
||||
private async Task ExecuteInvoiceApplyScriptAsync(ChromiumWebBrowser b)
|
||||
{
|
||||
string content = ResourceHelper.GetResourceText("/Ctrls/PDDInvoice/Resources/invoice.js", "29WxFindOrder");
|
||||
content = content.Replace("{公司}", Config.Title);
|
||||
content = content.Replace("{税号}", Config.TaxNo);
|
||||
if (string.IsNullOrEmpty(content)) return;
|
||||
|
||||
await b.EvaluateScriptAsync(content);
|
||||
|
||||
if (_currentInvoiceTcs == null) return; // 单张申请模式:保持原有行为
|
||||
|
||||
// 批量模式:等待异步脚本执行完成
|
||||
// 捕获当前 TCS,避免批量循环超时进入下一个订单后,迟到的轮询误触发新订单的结果
|
||||
var tcs = _currentInvoiceTcs;
|
||||
for (int i = 0; i < 120; i++)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
try
|
||||
{
|
||||
var res = await b.EvaluateScriptAsync("window.__invoiceApplyResult");
|
||||
if (res.Success && res.Result != null)
|
||||
{
|
||||
tcs.TrySetResult(Convert.ToBoolean(res.Result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
tcs.TrySetResult(false);
|
||||
}
|
||||
|
||||
public ICommand CloseInvoiceDetailCommand => new DelegateCommand(HidenOrderBrowserDetail);
|
||||
|
||||
@@ -142,11 +85,6 @@ public partial class PDDInvoiceViewModel
|
||||
get => GetValue<int>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
public int BrowserDetailZIndex
|
||||
{
|
||||
get => GetValue<int>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示主浏览器
|
||||
/// </summary>
|
||||
@@ -155,22 +93,12 @@ public partial class PDDInvoiceViewModel
|
||||
BrowserZIndex = 10;
|
||||
BrowserDetailZIndex = -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示子浏览器
|
||||
/// </summary>
|
||||
public void ShowOrderBrowserDetail()
|
||||
{
|
||||
BrowserZIndex = -1;
|
||||
BrowserDetailZIndex = 10;
|
||||
}
|
||||
|
||||
public void HidenOrderBrowser()
|
||||
{
|
||||
BrowserZIndex = -1;
|
||||
}
|
||||
public void HidenOrderBrowserDetail()
|
||||
{
|
||||
BrowserDetailZIndex = -1;
|
||||
}
|
||||
|
||||
public bool IsReadOrder
|
||||
{
|
||||
get => GetValue<bool>();
|
||||
@@ -178,31 +106,28 @@ public partial class PDDInvoiceViewModel
|
||||
}
|
||||
private int top = 0;
|
||||
private DateTime lastGetOrderDataTime = DateTime.Now;
|
||||
private string lastOrderSN = "0";
|
||||
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||||
{
|
||||
if (url.StartsWith("https://mobile.yangkeduo.com/orders.html"))
|
||||
{
|
||||
//if (isAutoScroll == false)
|
||||
//{
|
||||
// StartAutoScroll();
|
||||
//}
|
||||
|
||||
StartAutoScroll();
|
||||
}
|
||||
if (url.StartsWith("https://mobile.yangkeduo.com/proxy/api/api/aristotle/order_list_v"))
|
||||
{
|
||||
lastGetOrderDataTime = DateTime.Now;
|
||||
parserData(responseData);
|
||||
|
||||
parserData(responseData, out lastOrderSN);
|
||||
Debug.WriteLine($"LastOrder:{lastOrderSN}");
|
||||
//File.WriteAllText(@$"E:\{Guid.NewGuid().ToString()}.txt", responseData);
|
||||
}
|
||||
}
|
||||
public void StartAutoScroll()
|
||||
{
|
||||
if (frame == null)
|
||||
{
|
||||
StopAutoScroll(); return;
|
||||
}
|
||||
if (IsReadOrder) return;
|
||||
|
||||
IsReadOrder = true;
|
||||
_ = autoScroll(_cancellationTokenSource.Token);
|
||||
//_ = autoScroll(_cancellationTokenSource.Token);
|
||||
_ = autoLoadOrderData(_cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
// 停止滚动
|
||||
@@ -210,39 +135,82 @@ public partial class PDDInvoiceViewModel
|
||||
{
|
||||
IsReadOrder = false;
|
||||
_cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
private async Task autoScroll(CancellationToken token)
|
||||
|
||||
Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
BottomMsg = $"订单读取结束";
|
||||
}));
|
||||
CompleteProgress();
|
||||
|
||||
}
|
||||
private async Task autoLoadOrderData(CancellationToken token)
|
||||
{
|
||||
string templastOrderSN = "";
|
||||
while (IsReadOrder && !token.IsCancellationRequested)
|
||||
{
|
||||
if ((DateTime.Now - lastGetOrderDataTime).Seconds > 30) StopAutoScroll();
|
||||
|
||||
top += Randomx.GetId(450, 600);
|
||||
var jsStr = @"window.scroll({
|
||||
top: " + top + @",
|
||||
left: 0,
|
||||
behavior: 'smooth' // 可选,使滚动平滑
|
||||
});";
|
||||
|
||||
var client = Browser.GetDevToolsClient();
|
||||
if (client != null)
|
||||
if (lastOrderSN == templastOrderSN)
|
||||
{
|
||||
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
|
||||
result.Wait(5000);
|
||||
await Task.Delay(500);
|
||||
continue;
|
||||
}
|
||||
await Task.Delay(Randomx.GetId(100, 300));
|
||||
|
||||
string jsStr = $"PDDOrders.trigger({{offset:'MO-01-{lastOrderSN}',type:0,size:10,mode:'store'}})";
|
||||
templastOrderSN = lastOrderSN;
|
||||
|
||||
await frame.EvaluateScriptAsync(jsStr);
|
||||
|
||||
await Task.Delay(Randomx.GetId(1000, 3000));
|
||||
//Thread.Sleep();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DetailRequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||||
/// <summary>文档创建时注入(每个 document 注入一次即可,脚本本身幂等)</summary>
|
||||
public void Install(IFrame frame, string hookJs)
|
||||
{
|
||||
if (url.StartsWith("https://mobile.yangkeduo.com/transac_return_compensation.html"))
|
||||
{
|
||||
|
||||
}
|
||||
if (frame == null || string.IsNullOrEmpty(hookJs)) return;
|
||||
frame.ExecuteJavaScriptAsync(hookJs);
|
||||
}
|
||||
|
||||
/// <summary>脚本是否已就绪(注入后自检用;异步,不会卡 UI 线程)</summary>
|
||||
public async Task<bool> IsInstalledAsync(IFrame frame, int timeoutMs = 3000)
|
||||
{
|
||||
var deadline = DateTime.Now.AddMilliseconds(timeoutMs);
|
||||
while (DateTime.Now < deadline)
|
||||
{
|
||||
var r = await frame.EvaluateScriptAsync("!!(window.PDDOrders && window.PDDOrders.__installed)")
|
||||
.ConfigureAwait(false);
|
||||
if (r != null && r.Success && r.Result is bool && (bool)r.Result) return true;
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//private async Task autoScroll(CancellationToken token)
|
||||
//{
|
||||
// while (IsReadOrder && !token.IsCancellationRequested)
|
||||
// {
|
||||
// if ((DateTime.Now - lastGetOrderDataTime).Seconds > 30) StopAutoScroll();
|
||||
|
||||
// top += Randomx.GetId(450, 600);
|
||||
// var jsStr = @"window.scroll({
|
||||
// top: " + top + @",
|
||||
// left: 0,
|
||||
// behavior: 'smooth' // 可选,使滚动平滑
|
||||
// });";
|
||||
|
||||
// var client = Browser.GetDevToolsClient();
|
||||
// if (client != null)
|
||||
// {
|
||||
// var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
|
||||
// result.Wait(5000);
|
||||
// }
|
||||
// await Task.Delay(Randomx.GetId(100, 300));
|
||||
// //Thread.Sleep();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using _29WxOrderWpf.CefHelper;
|
||||
using CefSharp;
|
||||
using CefSharp.Handler;
|
||||
using CefSharp.Wpf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Work._29Tools.CefTools;
|
||||
using Work.BaseForms;
|
||||
using WxOrder.Framework.Helpers;
|
||||
|
||||
namespace _29WxOrderWpf.Ctrls.PDDInvoice.ViewModels;
|
||||
|
||||
public partial class PDDInvoiceViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 内容浏览器
|
||||
/// 订单详情
|
||||
/// 发票详情
|
||||
/// 申请发票
|
||||
/// </summary>
|
||||
public ChromiumWebBrowser BrowserDetail { get; private set; }
|
||||
partial void InitBrowserDetail()
|
||||
{
|
||||
BrowserDetailZIndex = -1;
|
||||
|
||||
BrowserDetail = WPFCEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
||||
LocalResourceRequestHandler resourceRequestHandler = new LocalResourceRequestHandler();
|
||||
|
||||
LocalResourceRequestHandler detailResourceRequestHandler = new LocalResourceRequestHandler();
|
||||
detailResourceRequestHandler.ResourceLoadCompleteEvent += DetailRequestHandler_ResourceLoadComplete;
|
||||
BrowserDetail.RequestHandler = new LocalRequestHandler(resourceRequestHandler);
|
||||
BrowserDetail.LifeSpanHandler = new LocalLifeSpanHandler(PopWindowType.SelfWindow);
|
||||
BrowserDetail.KeyboardHandler = new KeyboardHandler();
|
||||
BrowserDetail.LoadingStateChanged += BrowserDetail_LoadingStateChanged;
|
||||
}
|
||||
public int BrowserDetailZIndex
|
||||
{
|
||||
get => GetValue<int>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示子浏览器
|
||||
/// </summary>
|
||||
public void ShowOrderBrowserDetail()
|
||||
{
|
||||
BrowserZIndex = -1;
|
||||
BrowserDetailZIndex = 10;
|
||||
}
|
||||
public void HidenOrderBrowserDetail()
|
||||
{
|
||||
BrowserDetailZIndex = -1;
|
||||
}
|
||||
private void BrowserDetail_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
|
||||
{
|
||||
if (e.IsLoading == false)
|
||||
{
|
||||
var b = (ChromiumWebBrowser)sender;
|
||||
b.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
if (b.Address != null && b.Address.StartsWith("https://mobile.yangkeduo.com/transac_return_compensation.html"))
|
||||
{
|
||||
string orderSN = Regex.Match(b.Address, "order_sn=(?<sn>\\d+-\\d+)").Groups["sn"].Value;
|
||||
string html = await b.GetBrowser().GetSourceAsync();
|
||||
if (html.Contains("window.rawData"))
|
||||
{
|
||||
await ExecuteInvoiceApplyScriptAsync(b, orderSN);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 页面异常(未渲染出发票表单)时直接判定失败,避免批量开票长时间等待
|
||||
_currentInvoiceTcs?.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注入发票填写脚本并执行。
|
||||
/// 单张申请模式保持原有行为;批量开票模式下轮询脚本写入的
|
||||
/// <c>window.__invoiceApplyResult</c>,完成后通过 <see cref="_currentInvoiceTcs"/> 回传结果。
|
||||
/// </summary>
|
||||
private async Task ExecuteInvoiceApplyScriptAsync(ChromiumWebBrowser b, string orderSn)
|
||||
{
|
||||
string content = ResourceHelper.GetResourceText("/Ctrls/PDDInvoice/Resources/invoice.js", "29WxFindOrder");
|
||||
content = content.Replace("{公司}", Config.Title);
|
||||
content = content.Replace("{税号}", Config.TaxNo);
|
||||
if (string.IsNullOrEmpty(content)) return;
|
||||
|
||||
await b.EvaluateScriptAsync(content);
|
||||
|
||||
if (_currentInvoiceTcs == null)
|
||||
{
|
||||
var temp = Orders?.FirstOrDefault(a => a.order_sn == orderSn);
|
||||
if (temp != null) temp.IsInvoiced = true;
|
||||
return; // 单张申请模式:保持原有行为
|
||||
}
|
||||
|
||||
// 捕获当前 TCS,避免批量循环超时进入下一个订单后,迟到的轮询误触发新订单的结果
|
||||
var tcs = _currentInvoiceTcs;
|
||||
|
||||
// 检查是否注入成功
|
||||
if (await IsInstalledDetailAsync(b) == false)
|
||||
{
|
||||
IsBatchInvoicing = false;
|
||||
BaseMsgForm.ShowError("JS错误,开票失败");
|
||||
tcs.TrySetResult(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 120; i++)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
try
|
||||
{
|
||||
var res = await b.EvaluateScriptAsync("window.__invoiceApplyResult");
|
||||
if (res.Success && res.Result != null)
|
||||
{
|
||||
tcs.TrySetResult(Convert.ToBoolean(res.Result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
tcs.TrySetResult(false);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> IsInstalledDetailAsync(ChromiumWebBrowser frame, int timeoutMs = 3000)
|
||||
{
|
||||
var deadline = DateTime.Now.AddMilliseconds(timeoutMs);
|
||||
while (DateTime.Now < deadline)
|
||||
{
|
||||
var r = await frame.EvaluateScriptAsync("!!(window.InvoiceApply && window.InvoiceApply.__installed)")
|
||||
.ConfigureAwait(false);
|
||||
if (r != null && r.Success && r.Result is bool && (bool)r.Result) return true;
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DetailRequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||||
{
|
||||
if (url.StartsWith("https://mobile.yangkeduo.com/transac_return_compensation.html"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace _29WxOrderWpf.Ctrls.PDDInvoice.ViewModels;
|
||||
/// <summary>
|
||||
/// 拼多多发票助手 视图模型
|
||||
/// </summary>
|
||||
public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
public partial class PDDInvoiceViewModel : BindableBaseEx, IDialogAware, IDisposable
|
||||
{
|
||||
private const string ConfigPath = "./invoice.config";
|
||||
private List<OrderInvoiceInfo> OrderInvoiceInfoList = new();
|
||||
@@ -76,7 +76,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
//Orders = new ObservableCollection<PDDInvoiceOrderModel>(_allOrders);
|
||||
|
||||
|
||||
InitBrowser();
|
||||
InitBrowser(); InitBrowserDetail();
|
||||
if (Config == null) Config = new InvoiceConfig();
|
||||
|
||||
EndTime = DateTime.Now;
|
||||
@@ -106,7 +106,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
return true;
|
||||
}
|
||||
partial void InitBrowser();
|
||||
|
||||
partial void InitBrowserDetail();
|
||||
/// <summary> 列表增删时订阅/退订订单勾选状态,用于刷新表头全选状态 </summary>
|
||||
private void Orders_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
@@ -490,6 +490,8 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
}
|
||||
|
||||
public event EventHandler<int> BatchInvoiceChanged;
|
||||
public event Action<IDialogResult> RequestClose;
|
||||
|
||||
/// <summary>
|
||||
/// 后台批量开票:逐单加载开票页并自动填写提交,底部进度条实时更新,成功后更新列表状态
|
||||
/// </summary>
|
||||
@@ -556,7 +558,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
BottomMsg = $"正在批量开票:{i}/{targets.Count},当前订单:{order.order_sn}。总金额:{AmountTotal.ToString("N2")}";
|
||||
BottomRMsg = $"批量开票状态:成功 {success} 个,失败 {fail} 个。总金额:{AmountTotal.ToString("N2")}";
|
||||
StatisticsInvoiceAmount();
|
||||
await Task.Delay(1000);
|
||||
await Task.Delay(200);
|
||||
|
||||
if (Config.IsSaveData)
|
||||
{
|
||||
@@ -668,36 +670,36 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
|
||||
|
||||
#region 数据解析
|
||||
|
||||
private void parserData(string data)
|
||||
{
|
||||
parserData(data, out string _);
|
||||
}
|
||||
private void parserData(string data, out string lastOrderSN)
|
||||
{
|
||||
lastOrderSN = "0";
|
||||
List<PddBrowserOrderInvoiceViewModel> list = JsonHelper.DeserializeJsonToList<PddBrowserOrderInvoiceViewModel>(JsonHelper.JObjectParse(data)["orders"].ParseToString());
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
StopAutoScroll();
|
||||
return;
|
||||
}
|
||||
|
||||
lastOrderSN = list.Last().order_sn;
|
||||
var currentLastItem = list.Last();
|
||||
var matched = list.Where(item => item.status == 4 && item.pay_status == 2).ToList();
|
||||
if (matched.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// CEF 回调运行在后台线程,ObservableCollection 的更新需要切回 UI 线程
|
||||
var dispatcher = Application.Current?.Dispatcher;
|
||||
if (dispatcher == null || dispatcher.CheckAccess())
|
||||
Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
AddOrders(matched);
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatcher.BeginInvoke(new Action(() =>
|
||||
if (matched.Count > 0)
|
||||
{
|
||||
AddOrders(matched);
|
||||
BottomMsg = $"正在读取订单,读取日期{matched.Last().OrderTime.ToString("yyyy-MM-dd")}";
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
BottomMsg = $"正在读取订单,读取日期{currentLastItem.OrderTime.ToString("yyyy-MM-dd")}";
|
||||
|
||||
}));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -831,6 +833,9 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
get => _progressMaximum;
|
||||
set => SetValue(ref _progressMaximum, value);
|
||||
}
|
||||
|
||||
public string Title => "发票助手";
|
||||
|
||||
public void SetProgress(int value, int maxValue)
|
||||
{
|
||||
StopUnknownTotalProgressTimer();
|
||||
@@ -904,6 +909,28 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
|
||||
}
|
||||
_unknownTotalProgressTimer = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StopAutoScroll();
|
||||
Browser.Dispose();
|
||||
BrowserDetail.Dispose();
|
||||
}
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
public bool CanCloseDialog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
@@ -913,7 +940,7 @@ public class InvoiceConfig
|
||||
public string Title { get; set; }
|
||||
public string TaxNo { get; set; }
|
||||
public decimal MaxAmount { get; set; }
|
||||
public bool IsSaveData { get; set; }
|
||||
public bool IsSaveData { get; set; } = true;
|
||||
|
||||
public void Assign(InvoiceConfig config)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user