新增磅单管理功能,支持免密接口和数据同步,更新相关控制器、实体和服务,优化权限管理,确保系统的灵活性和可扩展性。
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
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 CustomerPickerDialogViewModel : BaseViewModel, IDialogResultable<bool>
|
||||
{
|
||||
private readonly ICustomerService _customerService;
|
||||
|
||||
private string? _searchText;
|
||||
public string? SearchText { get => _searchText; set => SetProperty(ref _searchText, value); }
|
||||
|
||||
public ObservableCollection<MesXslCustomer> Customers { get; } = new();
|
||||
|
||||
private MesXslCustomer? _selectedCustomer;
|
||||
public MesXslCustomer? SelectedCustomer
|
||||
{
|
||||
get => _selectedCustomer;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedCustomer, value);
|
||||
ConfirmCommand.RaiseCanExecuteChanged();
|
||||
RaisePropertyChanged(nameof(SelectedCustomerDisplay));
|
||||
RaisePropertyChanged(nameof(HasSelectedCustomer));
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedCustomerDisplay => _selectedCustomer != null
|
||||
? $"[{_selectedCustomer.CustomerCode}] {_selectedCustomer.CustomerName}"
|
||||
: "选中客户后点击「确认选择」";
|
||||
|
||||
public bool HasSelectedCustomer => _selectedCustomer != 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 CustomerPickerDialogViewModel(
|
||||
ICustomerService customerService,
|
||||
IContainerExtension container,
|
||||
IRegionManager regionManager) : base(container, regionManager)
|
||||
{
|
||||
_customerService = customerService;
|
||||
SearchCommand = new DelegateCommand(async () => await LoadAsync());
|
||||
ConfirmCommand = new DelegateCommand(Confirm, () => SelectedCustomer != null);
|
||||
CancelCommand = new DelegateCommand(() => CloseAction?.Invoke());
|
||||
_ = LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
var keyword = SearchText?.Trim();
|
||||
var result = await _customerService.PageAsync(1, 200, customerName: keyword);
|
||||
Customers.Clear();
|
||||
foreach (var c in result.Records)
|
||||
Customers.Add(c);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Customers.Clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
if (SelectedCustomer == null) return;
|
||||
Result = true;
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user