新增密炼物料皮重策略功能,包括相关实体、服务、控制器及接口,支持桌面端免密CRUD操作,优化打印记录与原料入场记录的衍生字段填充逻辑,提升用户体验。
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using HandyControl.Tools.Extension;
|
||||
using System.Collections.ObjectModel;
|
||||
using YY.Admin.Core;
|
||||
using YY.Admin.Core.Entity;
|
||||
using YY.Admin.Core.Services;
|
||||
using YY.Admin.Services.Service.MixerMaterialTareStrategy;
|
||||
|
||||
namespace YY.Admin.ViewModels.RawMaterialEntry;
|
||||
|
||||
/// <summary>
|
||||
/// 拆码明细手动选择「密炼物料皮重策略」弹窗。
|
||||
/// </summary>
|
||||
public class TareStrategyPickerDialogViewModel : BaseViewModel, IDialogResultable<bool>
|
||||
{
|
||||
private readonly IMixerMaterialTareStrategyService _tareStrategyService;
|
||||
|
||||
private string? _materialId;
|
||||
private string? _supplierId;
|
||||
private DateTime? _entryDate;
|
||||
private double? _portionWeight;
|
||||
|
||||
public ObservableCollection<MesXslMixerMaterialTareStrategy> Records { get; } = new();
|
||||
|
||||
private MesXslMixerMaterialTareStrategy? _selectedStrategy;
|
||||
public MesXslMixerMaterialTareStrategy? SelectedStrategy
|
||||
{
|
||||
get => _selectedStrategy;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedStrategy, value);
|
||||
ConfirmCommand.RaiseCanExecuteChanged();
|
||||
RaisePropertyChanged(nameof(SelectedStrategyDisplay));
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedStrategyDisplay => _selectedStrategy == null
|
||||
? "请选中一条策略后确认,或点「使用自动匹配」"
|
||||
: $"规格:{_selectedStrategy.MaterialSpec ?? "-"} 包装物:{_selectedStrategy.TareWeight:0.###} 托盘:{_selectedStrategy.PalletWeight:0.###}";
|
||||
|
||||
private bool _result;
|
||||
public bool Result { get => _result; set => SetProperty(ref _result, value); }
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
public DelegateCommand ConfirmCommand { get; }
|
||||
public DelegateCommand UseAutoMatchCommand { get; }
|
||||
public DelegateCommand CancelCommand { get; }
|
||||
|
||||
public TareStrategyPickerDialogViewModel(
|
||||
IMixerMaterialTareStrategyService tareStrategyService,
|
||||
IContainerExtension container,
|
||||
IRegionManager regionManager) : base(container, regionManager)
|
||||
{
|
||||
_tareStrategyService = tareStrategyService;
|
||||
ConfirmCommand = new DelegateCommand(ConfirmSelection, () => SelectedStrategy != null);
|
||||
UseAutoMatchCommand = new DelegateCommand(UseAutoMatch);
|
||||
CancelCommand = new DelegateCommand(() => CloseAction?.Invoke());
|
||||
}
|
||||
|
||||
public void Initialize(
|
||||
string? materialId,
|
||||
string? supplierId,
|
||||
DateTime? entryDate,
|
||||
double? portionWeight,
|
||||
string? currentStrategyId)
|
||||
{
|
||||
_materialId = materialId;
|
||||
_supplierId = supplierId;
|
||||
_entryDate = entryDate;
|
||||
_portionWeight = portionWeight;
|
||||
_ = LoadAsync(currentStrategyId);
|
||||
}
|
||||
|
||||
private async Task LoadAsync(string? currentStrategyId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var all = await _tareStrategyService.GetAllForMatchAsync();
|
||||
var filtered = MixerMaterialTareStrategyMatcher.FilterCandidates(
|
||||
all, _materialId, _supplierId, _entryDate, _portionWeight);
|
||||
|
||||
Records.Clear();
|
||||
foreach (var item in filtered)
|
||||
Records.Add(item);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(currentStrategyId))
|
||||
{
|
||||
SelectedStrategy = Records.FirstOrDefault(r =>
|
||||
string.Equals(r.Id, currentStrategyId, StringComparison.OrdinalIgnoreCase))
|
||||
?? all.FirstOrDefault(r => string.Equals(r.Id, currentStrategyId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Records.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfirmSelection()
|
||||
{
|
||||
Result = true;
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
|
||||
private void UseAutoMatch()
|
||||
{
|
||||
SelectedStrategy = null;
|
||||
Result = true;
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user