using OrderSupportTicket.Models; using OrderSupportTicket.Services; using OrderSupportTicket.ViewModels; using System.Windows.Controls; namespace OrderSupportTicket.Views; /// /// 工单对话页面。页面生命周期只负责激活/停用 ViewModel,业务交互均在 ViewModel 中。 /// public partial class OrderSupportTicketView : UserControl { private bool _active; public OrderSupportTicketView() : this( new TicketApiService(), new EventSourceTicketRealtimeService(), TicketClientOptions.FromApplicationSettings()) { } public OrderSupportTicketView( ITicketApiService api, ITicketRealtimeService realtime, TicketClientOptions options = null) { InitializeComponent(); options = new TicketClientOptions { UserName="18990991234", AppIds = ["wx316b1291351558aa", "wx7999743c3d64c05c"], Orders = [ new TicketOrderOption { Amount=109m, AppId="wx316b1291351558aa", GoodsName="梵客隆收腹内裤女新款高腰无痕磨毛暖融收小肚子提臀塑身平角裤", OrderId="9000000000000000001", OrderedAt=new DateTime(2020, 1, 1), }, new TicketOrderOption { Amount=109m, AppId="wx7999743c3d64c05c", GoodsName="洁柔抽纸粉Face家用实惠装批发纸巾大包面纸餐巾纸抽整箱可湿水纸", OrderId="9000000000000000002", OrderedAt=new DateTime(2020, 1, 1), } ] }; ViewModel = new OrderSupportTicketViewModel(api, realtime, options); DataContext = ViewModel; Loaded += OnLoaded; Unloaded += OnUnloaded; } /// /// 当前页面对应的工单 ViewModel。 /// public OrderSupportTicketViewModel ViewModel { get; } /// /// 宿主可在页面加载前注入账号、APPID 与本地订单数据。 /// public void Configure(TicketClientOptions options) { ViewModel.Configure(options); } /// /// 从订单页直接打开新工单草稿。 /// public void OpenNewTicket(TicketOrderOption order) { ViewModel.OpenNewTicket(order); } private async void OnLoaded(object sender, System.Windows.RoutedEventArgs e) { if (_active) return; _active = true; await ViewModel.InitializeAsync(); } private async void OnUnloaded(object sender, System.Windows.RoutedEventArgs e) { if (!_active) return; _active = false; await ViewModel.DeactivateAsync(); } }