diff --git a/yy-admin-master/YY.Admin/ViewModels/RawMaterialEntry/RawMaterialEntryEditDialogViewModel.cs b/yy-admin-master/YY.Admin/ViewModels/RawMaterialEntry/RawMaterialEntryEditDialogViewModel.cs index 15b8a0c..b480b24 100644 --- a/yy-admin-master/YY.Admin/ViewModels/RawMaterialEntry/RawMaterialEntryEditDialogViewModel.cs +++ b/yy-admin-master/YY.Admin/ViewModels/RawMaterialEntry/RawMaterialEntryEditDialogViewModel.cs @@ -1,6 +1,9 @@ using HandyControl.Controls; using HandyControl.Tools.Extension; +using System.Collections.Specialized; +using System.ComponentModel; using System.Collections.ObjectModel; +using System.Globalization; using YY.Admin.Core; using YY.Admin.Core.Entity; using YY.Admin.Core.Services; @@ -117,6 +120,9 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta public ObservableCollection> StatusOptions { get; } = new(); public ObservableCollection SplitCodeDetails { get; } = new(); public double SplitCodeTableHeight => CalculateSplitCodeTableHeight(); + public string SplitTotalPortionsDisplay => JoinSplitValue(item => item.Portions?.ToString(CultureInfo.InvariantCulture), true); + public string SplitPortionWeightDisplay => JoinSplitValue(item => FormatNullableDecimal(item.PortionWeight), true); + public string SplitPortionPackagesDisplay => JoinSplitValue(item => item.PortionPackages?.ToString(CultureInfo.InvariantCulture), true); private bool _result; public bool Result { get => _result; set => SetProperty(ref _result, value); } @@ -151,7 +157,7 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta ClearMaterialCommand = new DelegateCommand(ClearMaterialSelection); OpenWeightRecordPickerCommand = new DelegateCommand(async () => await OpenWeightRecordPickerAsync()); ClearWeightRecordCommand = new DelegateCommand(ClearWeightRecordSelection); - SplitCodeDetails.CollectionChanged += (_, _) => RaisePropertyChanged(nameof(SplitCodeTableHeight)); + SplitCodeDetails.CollectionChanged += OnSplitCodeDetailsCollectionChanged; _ = LoadAllAsync(); } @@ -298,6 +304,9 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta RaisePropertyChanged(nameof(TotalWeightInput)); RaisePropertyChanged(nameof(TotalPortionsInput)); RaisePropertyChanged(nameof(IsSpecialAdoptionValue)); + RaisePropertyChanged(nameof(SplitTotalPortionsDisplay)); + RaisePropertyChanged(nameof(SplitPortionWeightDisplay)); + RaisePropertyChanged(nameof(SplitPortionPackagesDisplay)); } public void InitializeForEdit(MesXslRawMaterialEntry entry) @@ -339,6 +348,9 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta RaisePropertyChanged(nameof(TotalWeightInput)); RaisePropertyChanged(nameof(TotalPortionsInput)); RaisePropertyChanged(nameof(IsSpecialAdoptionValue)); + RaisePropertyChanged(nameof(SplitTotalPortionsDisplay)); + RaisePropertyChanged(nameof(SplitPortionWeightDisplay)); + RaisePropertyChanged(nameof(SplitPortionPackagesDisplay)); } private async Task SaveAsync() @@ -548,6 +560,71 @@ public class RawMaterialEntryEditDialogViewModel : BaseViewModel, IDialogResulta RaisePropertyChanged(nameof(SplitCodeTableHeight)); } + private void OnSplitCodeDetailsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + if (e.OldItems != null) + { + foreach (var oldItem in e.OldItems.OfType()) + { + oldItem.PropertyChanged -= OnSplitDetailItemPropertyChanged; + } + } + + if (e.NewItems != null) + { + foreach (var newItem in e.NewItems.OfType()) + { + newItem.PropertyChanged += OnSplitDetailItemPropertyChanged; + } + } + + RaiseSplitDisplayPropertyChanged(); + RaisePropertyChanged(nameof(SplitCodeTableHeight)); + } + + private void OnSplitDetailItemPropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName is nameof(RawMaterialSplitDetailItem.Portions) + or nameof(RawMaterialSplitDetailItem.PortionWeight) + or nameof(RawMaterialSplitDetailItem.PortionPackages)) + { + RaiseSplitDisplayPropertyChanged(); + } + } + + private void RaiseSplitDisplayPropertyChanged() + { + RaisePropertyChanged(nameof(SplitTotalPortionsDisplay)); + RaisePropertyChanged(nameof(SplitPortionWeightDisplay)); + RaisePropertyChanged(nameof(SplitPortionPackagesDisplay)); + } + + private string JoinSplitValue(Func selector, bool withTrailingSlash) + { + var values = SplitCodeDetails + .Select(selector) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Select(x => x!.Trim()) + .ToList(); + if (values.Count == 0) + { + return string.Empty; + } + + var joined = string.Join("/", values); + return withTrailingSlash ? $"{joined}/" : joined; + } + + private static string? FormatNullableDecimal(double? value) + { + if (!value.HasValue) + { + return null; + } + + return value.Value.ToString("0.##", CultureInfo.InvariantCulture); + } + private void ApplyFirstSplitDetailToEntry() { if (Entry == null || SplitCodeDetails.Count == 0) diff --git a/yy-admin-master/YY.Admin/Views/RawMaterialEntry/RawMaterialEntryOperationView.xaml b/yy-admin-master/YY.Admin/Views/RawMaterialEntry/RawMaterialEntryOperationView.xaml index 3cccb98..cfffc17 100644 --- a/yy-admin-master/YY.Admin/Views/RawMaterialEntry/RawMaterialEntryOperationView.xaml +++ b/yy-admin-master/YY.Admin/Views/RawMaterialEntry/RawMaterialEntryOperationView.xaml @@ -25,10 +25,15 @@ + - + @@ -76,7 +81,7 @@ hc:InfoElement.TitleWidth="80" hc:InfoElement.TitlePlacement="Left" Foreground="{DynamicResource SecondaryTextBrush}" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -88,7 +93,7 @@ hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="自动生成" hc:InfoElement.ShowClearButton="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -100,11 +105,11 @@ hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="自动生成" hc:InfoElement.ShowClearButton="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> - + @@ -116,7 +121,7 @@ - + @@ -154,7 +159,7 @@ hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="请输入供料客户" hc:InfoElement.ShowClearButton="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -166,7 +171,7 @@ hc:InfoElement.Placeholder="根据榜单自动带出" hc:InfoElement.ShowClearButton="True" IsReadOnly="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -178,7 +183,7 @@ hc:InfoElement.Placeholder="自动带出厂家别名" hc:InfoElement.ShowClearButton="True" IsReadOnly="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -190,7 +195,7 @@ hc:InfoElement.Placeholder="自动计算到期日期" hc:InfoElement.ShowClearButton="True" IsReadOnly="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -203,99 +208,40 @@ hc:InfoElement.TitleWidth="80" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="请输入总重" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> - + - + - - - - - - - - - - - - - - - - - + @@ -306,7 +252,7 @@ hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="请输入库位" hc:InfoElement.ShowClearButton="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -317,7 +263,7 @@ hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="请输入卸货人" hc:InfoElement.ShowClearButton="True" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> @@ -330,88 +276,7 @@ hc:InfoElement.TitleWidth="80" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Placeholder="请选择是否特采" - Margin="0,0,0,8"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Margin="0,0,0,4"/> @@ -426,13 +291,64 @@ HorizontalAlignment="Stretch" Height="64" VerticalScrollBarVisibility="Auto" - Margin="0,0,0,8"/> + Margin="0,0,0,4"/> + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - -