新增MES模块,包含供应商、客户、车辆和地磅数据记录管理功能,支持免密接口和数据同步。更新相关控制器、实体、服务和数据库配置,优化权限管理和数据字典支持,确保系统的灵活性和可扩展性。
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
using HandyControl.Controls;
|
||||
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;
|
||||
|
||||
namespace YY.Admin.ViewModels.Customer;
|
||||
|
||||
public class CustomerEditDialogViewModel : BaseViewModel, IDialogResultable<bool>
|
||||
{
|
||||
private readonly ICustomerService _customerService;
|
||||
private readonly IJeecgDictSyncService _dictSyncService;
|
||||
|
||||
private MesXslCustomer? _customer;
|
||||
public MesXslCustomer? Customer
|
||||
{
|
||||
get => _customer;
|
||||
set => SetProperty(ref _customer, value);
|
||||
}
|
||||
|
||||
public bool IsAddMode => string.IsNullOrWhiteSpace(Customer?.Id) || (Customer?.Id?.StartsWith("local-") ?? false);
|
||||
public string DialogTitle => IsAddMode ? "新增客户" : "编辑客户";
|
||||
|
||||
public ObservableCollection<KeyValuePair<string, string>> StatusOptions { get; } = new();
|
||||
public ObservableCollection<KeyValuePair<string, string>> CustomerRegionOptions { get; } = new();
|
||||
|
||||
private bool _result;
|
||||
public bool Result { get => _result; set => SetProperty(ref _result, value); }
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
public DelegateCommand SaveCommand { get; }
|
||||
public DelegateCommand CancelCommand { get; }
|
||||
|
||||
public CustomerEditDialogViewModel(
|
||||
ICustomerService customerService,
|
||||
IJeecgDictSyncService dictSyncService,
|
||||
IContainerExtension container,
|
||||
IRegionManager regionManager) : base(container, regionManager)
|
||||
{
|
||||
_customerService = customerService;
|
||||
_dictSyncService = dictSyncService;
|
||||
SaveCommand = new DelegateCommand(async () => await SaveAsync());
|
||||
CancelCommand = new DelegateCommand(() => CloseAction?.Invoke());
|
||||
_ = LoadDictOptionsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadDictOptionsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var statusOpts = await _dictSyncService.GetDictOptionsAsync("xslmes_customer_status");
|
||||
var regionOpts = await _dictSyncService.GetDictOptionsAsync("xslmes_customer_region");
|
||||
|
||||
StatusOptions.Clear();
|
||||
foreach (var item in statusOpts) StatusOptions.Add(item);
|
||||
CustomerRegionOptions.Clear();
|
||||
foreach (var item in regionOpts) CustomerRegionOptions.Add(item);
|
||||
|
||||
if (StatusOptions.Count == 0)
|
||||
{
|
||||
StatusOptions.Add(new KeyValuePair<string, string>("启用", "0"));
|
||||
StatusOptions.Add(new KeyValuePair<string, string>("停用", "1"));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
StatusOptions.Clear();
|
||||
StatusOptions.Add(new KeyValuePair<string, string>("启用", "0"));
|
||||
StatusOptions.Add(new KeyValuePair<string, string>("停用", "1"));
|
||||
CustomerRegionOptions.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeForAdd()
|
||||
{
|
||||
Customer = new MesXslCustomer { Status = "0" };
|
||||
RaisePropertyChanged(nameof(IsAddMode));
|
||||
RaisePropertyChanged(nameof(DialogTitle));
|
||||
}
|
||||
|
||||
public void InitializeForEdit(MesXslCustomer customer)
|
||||
{
|
||||
Customer = new MesXslCustomer
|
||||
{
|
||||
Id = customer.Id,
|
||||
CustomerCode = customer.CustomerCode,
|
||||
CustomerName = customer.CustomerName,
|
||||
CustomerShortName = customer.CustomerShortName,
|
||||
CustomerRegion = customer.CustomerRegion,
|
||||
ErpCode = customer.ErpCode,
|
||||
Status = customer.Status,
|
||||
IzEnable = customer.IzEnable,
|
||||
CustomerDesc = customer.CustomerDesc,
|
||||
TenantId = customer.TenantId,
|
||||
};
|
||||
RaisePropertyChanged(nameof(IsAddMode));
|
||||
RaisePropertyChanged(nameof(DialogTitle));
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (Customer == null) return;
|
||||
if (string.IsNullOrWhiteSpace(Customer.CustomerCode))
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Warning("客户编码不能为空!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(Customer.CustomerName))
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Warning("客户名称不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bool ok;
|
||||
if (IsAddMode)
|
||||
{
|
||||
ok = await _customerService.AddAsync(Customer);
|
||||
if (ok) HandyControl.Controls.MessageBox.Success("新增客户成功!");
|
||||
else { HandyControl.Controls.MessageBox.Error("新增客户失败!"); return; }
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = await _customerService.EditAsync(Customer);
|
||||
if (!ok) { HandyControl.Controls.MessageBox.Error("编辑客户失败!"); return; }
|
||||
}
|
||||
Result = ok;
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Error($"操作失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user