140 lines
4.8 KiB
C#
140 lines
4.8 KiB
C#
using HandyControl.Controls;
|
|
using Prism.Events;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using YY.Admin.Core;
|
|
using YY.Admin.Core.Entity;
|
|
using YY.Admin.Core.Events;
|
|
using YY.Admin.Core.Helper;
|
|
using YY.Admin.Core.Services;
|
|
using YY.Admin.Services.Service;
|
|
|
|
namespace YY.Admin.ViewModels.MixingProductionPlan;
|
|
|
|
public class MixingProductionPlanListViewModel : BaseViewModel
|
|
{
|
|
private readonly IMixingProductionPlanService _planService;
|
|
private SubscriptionToken? _changedToken;
|
|
|
|
private ObservableCollection<MesXslMixingProductionPlan> _items = new();
|
|
public ObservableCollection<MesXslMixingProductionPlan> Items
|
|
{
|
|
get => _items;
|
|
set => SetProperty(ref _items, value);
|
|
}
|
|
|
|
private long _total;
|
|
public long Total { get => _total; set => SetProperty(ref _total, value); }
|
|
|
|
private int _pageNo = 1;
|
|
public int PageNo { get => _pageNo; set => SetProperty(ref _pageNo, value); }
|
|
|
|
private int _pageSize = 20;
|
|
public int PageSize { get => _pageSize; set => SetProperty(ref _pageSize, value); }
|
|
|
|
private DateTime? _filterPlanDateFrom;
|
|
public DateTime? FilterPlanDateFrom { get => _filterPlanDateFrom; set => SetProperty(ref _filterPlanDateFrom, value); }
|
|
|
|
private DateTime? _filterPlanDateTo;
|
|
public DateTime? FilterPlanDateTo { get => _filterPlanDateTo; set => SetProperty(ref _filterPlanDateTo, value); }
|
|
|
|
private string? _filterMachineName;
|
|
public string? FilterMachineName { get => _filterMachineName; set => SetProperty(ref _filterMachineName, value); }
|
|
|
|
private int? _filterShiftFlag;
|
|
public int? FilterShiftFlag { get => _filterShiftFlag; set => SetProperty(ref _filterShiftFlag, value); }
|
|
|
|
private string? _filterPlanNo;
|
|
public string? FilterPlanNo { get => _filterPlanNo; set => SetProperty(ref _filterPlanNo, value); }
|
|
|
|
private string? _filterMaterialName;
|
|
public string? FilterMaterialName { get => _filterMaterialName; set => SetProperty(ref _filterMaterialName, value); }
|
|
|
|
public ObservableCollection<KeyValuePair<string, int?>> ShiftOptions { get; } = new()
|
|
{
|
|
new KeyValuePair<string, int?>("全部", null),
|
|
new KeyValuePair<string, int?>("早班", 1),
|
|
new KeyValuePair<string, int?>("中班", 2),
|
|
new KeyValuePair<string, int?>("晚班", 3)
|
|
};
|
|
|
|
public DelegateCommand SearchCommand { get; }
|
|
public DelegateCommand ResetCommand { get; }
|
|
public DelegateCommand PrevPageCommand { get; }
|
|
public DelegateCommand NextPageCommand { get; }
|
|
|
|
public MixingProductionPlanListViewModel(
|
|
IMixingProductionPlanService planService,
|
|
IContainerExtension container,
|
|
IRegionManager regionManager) : base(container, regionManager)
|
|
{
|
|
_planService = planService;
|
|
|
|
SearchCommand = new DelegateCommand(async () => { PageNo = 1; await LoadAsync(); });
|
|
ResetCommand = new DelegateCommand(async () =>
|
|
{
|
|
FilterPlanDateFrom = null;
|
|
FilterPlanDateTo = null;
|
|
FilterMachineName = null;
|
|
FilterShiftFlag = null;
|
|
FilterPlanNo = null;
|
|
FilterMaterialName = null;
|
|
PageNo = 1;
|
|
await LoadAsync();
|
|
});
|
|
PrevPageCommand = new DelegateCommand(async () => { if (PageNo > 1) { PageNo--; await LoadAsync(); } });
|
|
NextPageCommand = new DelegateCommand(async () => { if ((long)PageNo * PageSize < Total) { PageNo++; await LoadAsync(); } });
|
|
|
|
_changedToken = _eventAggregator.GetEvent<MixingProductionPlanChangedEvent>()
|
|
.Subscribe(async _ => await LoadAsync(), ThreadOption.UIThread);
|
|
|
|
_ = InitializeAsync();
|
|
}
|
|
|
|
private async Task InitializeAsync()
|
|
{
|
|
try
|
|
{
|
|
await UIHelper.WaitForRenderAsync();
|
|
await LoadAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine($"密炼计划列表初始化失败: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public async Task LoadAsync()
|
|
{
|
|
try
|
|
{
|
|
IsLoading = true;
|
|
var result = await _planService.PageAsync(
|
|
PageNo, PageSize,
|
|
FilterPlanDateFrom, FilterPlanDateTo,
|
|
FilterMachineName, FilterShiftFlag,
|
|
FilterPlanNo, FilterMaterialName);
|
|
Items = new ObservableCollection<MesXslMixingProductionPlan>(result.Records);
|
|
Total = result.Total;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Growl.Error($"加载密炼计划失败:{ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
IsLoading = false;
|
|
}
|
|
}
|
|
|
|
protected override void CleanUp()
|
|
{
|
|
base.CleanUp();
|
|
if (_changedToken != null)
|
|
{
|
|
_eventAggregator.GetEvent<MixingProductionPlanChangedEvent>().Unsubscribe(_changedToken);
|
|
_changedToken = null;
|
|
}
|
|
}
|
|
}
|