优化发票助手

This commit is contained in:
chfei committed 2026-10-15 13:33:08 +08:00
1 parent 6b36de2494
commit a81ba26de8
9 files changed
+584 -262

No files matched your search

@@ -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)
{