From 064bd1f142a698e7844fe75b7e98f9a06a7a91a1 Mon Sep 17 00:00:00 2001 From: chfei Date: Mon, 12 Oct 2026 18:44:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E7=A5=A8=20?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=87=BA=E7=8E=B0=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ctrls/PDDInvoice/PDDInvoiceDialog.xaml.cs | 41 +++++++++++++---- .../ViewModels/PDDInvoiceViewModel.cs | 45 ++++++++++++++----- 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceDialog.xaml.cs b/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceDialog.xaml.cs index 3d4c862..4aa6a26 100644 --- a/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceDialog.xaml.cs +++ b/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceDialog.xaml.cs @@ -1,5 +1,7 @@ using _29WxOrderWpf.Commands; +using _29WxOrderWpf.Common; using _29WxOrderWpf.Ctrls.PDDInvoice.ViewModels; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; @@ -22,18 +24,25 @@ namespace _29WxOrderWpf.Ctrls.PDDInvoice; /// /// PDDInvoiceDialog.xaml 的交互逻辑 /// -public partial class PDDInvoiceDialog : UserControl +public partial class PDDInvoiceDialog : UserControl, IDialogAware { - public PDDInvoiceDialog() + public PDDInvoiceDialog(InvoiceConfig config) { InitializeComponent(); DataContext = this; - Config = NaiBa.Util.Helper.ConfigHelper.LoadConfig(ConfigPath); + Config = new InvoiceConfig(); + Config.Assign(config); } + public string Title { get; set; } + public event Action RequestClose; private void PDDInvoiceDialog_Loaded(object sender, RoutedEventArgs e) { - + + } + public void OnDialogOpened(IDialogParameters parameters) + { + Title = "设置"; } private void ViewModel_RequestClose() @@ -44,21 +53,35 @@ public partial class PDDInvoiceDialog : UserControl } - private const string ConfigPath = "./invoice.config"; public InvoiceConfig Config { get; } - + public ICommand ConfirmCommand => new DelegateCommand(Confirm); private void Confirm() { - NaiBa.Util.Helper.ConfigHelper.SaveConfig(ConfigPath, Config); - ViewModel_RequestClose(); + RequestClose?.Invoke(new DialogResult(ButtonResult.OK, new DialogParameters + { + { "config",Config} + })); } public ICommand CancelCommand => new DelegateCommand(Cancel); + private void Cancel() { - ViewModel_RequestClose(); + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); } + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + } diff --git a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs index 42550a5..003e427 100644 --- a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs +++ b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs @@ -15,6 +15,7 @@ using MAX.Core.Helpers; using NaiBa.Util.Extension; using Newtonsoft.Json; using NPOI.SS.Formula.Functions; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -475,13 +476,17 @@ public partial class PDDInvoiceViewModel : BindableBaseEx private void ShowSettingDialog() { - var view = new PDDInvoiceDialog(); - new DialogWindow + var view = new PDDInvoiceDialog(Config); + DialogService.ShowDialog(view, null, result => { - Title = "设置", - Content = view, - }.ShowDialog(); - Config = view.Config; + if (result.Result == ButtonResult.OK) + { + Config.Assign(view.Config); + NaiBa.Util.Helper.ConfigHelper.SaveConfig(ConfigPath, Config); + } + + }); + } public event EventHandler BatchInvoiceChanged; @@ -506,7 +511,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx BottomMsg = "已取消批量开票"; return; } - + if (AmountTotal >= Config.MaxAmount) { return; @@ -537,6 +542,11 @@ public partial class PDDInvoiceViewModel : BindableBaseEx order.IsSelected = false; success++; AmountTotal += order.order_amount / 100m; + if (Config.IsSaveData) + { + var temp = OrderInvoiceInfoList?.FirstOrDefault(a => a.order_sn == order.order_sn); + if (temp != null) temp.IsInvoiced = true; + } } else { @@ -547,6 +557,12 @@ public partial class PDDInvoiceViewModel : BindableBaseEx BottomRMsg = $"批量开票状态:成功 {success} 个,失败 {fail} 个。总金额:{AmountTotal.ToString("N2")}"; StatisticsInvoiceAmount(); await Task.Delay(1000); + + if (Config.IsSaveData) + { + SaveOrderInvoiceInfo(); + } + } } catch (Exception ex) @@ -716,9 +732,10 @@ public partial class PDDInvoiceViewModel : BindableBaseEx } } StatisticsInvoiceAmount(); - - - SaveOrderInvoiceInfo(); + if (Config.IsSaveData) + { + SaveOrderInvoiceInfo(); + } } #endregion @@ -897,4 +914,12 @@ public class InvoiceConfig public string TaxNo { get; set; } public decimal MaxAmount { get; set; } public bool IsSaveData { get; set; } + + public void Assign(InvoiceConfig config) + { + Title = config.Title; + TaxNo = config.TaxNo; + MaxAmount = config.MaxAmount; + IsSaveData = config.IsSaveData; + } } \ No newline at end of file