85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
|
|
using HandyControl.Tools.Extension;
|
||
|
|
using System.Collections.ObjectModel;
|
||
|
|
using YY.Admin.Core;
|
||
|
|
using YY.Admin.Core.Entity;
|
||
|
|
using YY.Admin.Core.Services;
|
||
|
|
|
||
|
|
namespace YY.Admin.ViewModels.WeightRecord;
|
||
|
|
|
||
|
|
public class SupplierPickerDialogViewModel : BaseViewModel, IDialogResultable<bool>
|
||
|
|
{
|
||
|
|
private readonly ISupplierService _supplierService;
|
||
|
|
|
||
|
|
private string? _searchText;
|
||
|
|
public string? SearchText { get => _searchText; set => SetProperty(ref _searchText, value); }
|
||
|
|
|
||
|
|
public ObservableCollection<MesXslSupplier> Suppliers { get; } = new();
|
||
|
|
|
||
|
|
private MesXslSupplier? _selectedSupplier;
|
||
|
|
public MesXslSupplier? SelectedSupplier
|
||
|
|
{
|
||
|
|
get => _selectedSupplier;
|
||
|
|
set
|
||
|
|
{
|
||
|
|
SetProperty(ref _selectedSupplier, value);
|
||
|
|
ConfirmCommand.RaiseCanExecuteChanged();
|
||
|
|
RaisePropertyChanged(nameof(SelectedSupplierDisplay));
|
||
|
|
RaisePropertyChanged(nameof(HasSelectedSupplier));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public string SelectedSupplierDisplay => _selectedSupplier != null
|
||
|
|
? $"[{_selectedSupplier.SupplierCode}] {_selectedSupplier.SupplierName}"
|
||
|
|
: "选中供应商后点击「确认选择」";
|
||
|
|
|
||
|
|
public bool HasSelectedSupplier => _selectedSupplier != null;
|
||
|
|
|
||
|
|
private bool _result;
|
||
|
|
public bool Result { get => _result; set => SetProperty(ref _result, value); }
|
||
|
|
public Action? CloseAction { get; set; }
|
||
|
|
|
||
|
|
public DelegateCommand SearchCommand { get; }
|
||
|
|
public DelegateCommand ConfirmCommand { get; }
|
||
|
|
public DelegateCommand CancelCommand { get; }
|
||
|
|
|
||
|
|
public SupplierPickerDialogViewModel(
|
||
|
|
ISupplierService supplierService,
|
||
|
|
IContainerExtension container,
|
||
|
|
IRegionManager regionManager) : base(container, regionManager)
|
||
|
|
{
|
||
|
|
_supplierService = supplierService;
|
||
|
|
SearchCommand = new DelegateCommand(async () => await LoadAsync());
|
||
|
|
ConfirmCommand = new DelegateCommand(Confirm, () => SelectedSupplier != null);
|
||
|
|
CancelCommand = new DelegateCommand(() => CloseAction?.Invoke());
|
||
|
|
_ = LoadAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task LoadAsync()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
IsLoading = true;
|
||
|
|
var keyword = SearchText?.Trim();
|
||
|
|
var result = await _supplierService.PageAsync(1, 200, supplierName: keyword);
|
||
|
|
Suppliers.Clear();
|
||
|
|
foreach (var s in result.Records)
|
||
|
|
Suppliers.Add(s);
|
||
|
|
}
|
||
|
|
catch
|
||
|
|
{
|
||
|
|
Suppliers.Clear();
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
IsLoading = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Confirm()
|
||
|
|
{
|
||
|
|
if (SelectedSupplier == null) return;
|
||
|
|
Result = true;
|
||
|
|
CloseAction?.Invoke();
|
||
|
|
}
|
||
|
|
}
|