You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.4 KiB
C#
121 lines
4.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq.Expressions;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Sln.Wcs.Model.Domain;
|
|
using Sln.Wcs.Repository.service;
|
|
using Sln.Wcs.UI.ViewModels.Base;
|
|
using Sln.Wcs.UI.Views.Base;
|
|
|
|
namespace Sln.Wcs.UI.ViewModels.Path;
|
|
|
|
public partial class PathInfoViewModel : CrudPageViewModel<BasePathInfo>
|
|
{
|
|
private readonly IBasePathDetailsService _detailService;
|
|
private BasePathInfo? _currentPath;
|
|
|
|
[ObservableProperty]
|
|
private bool _isPanelOpen;
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<BasePathDetails> _detailItems = new();
|
|
|
|
[ObservableProperty]
|
|
private string _slidePanelTitle = string.Empty;
|
|
|
|
public PathInfoViewModel(IBasePathInfoService service, IBasePathDetailsService detailService) : base(service)
|
|
{
|
|
_detailService = detailService;
|
|
PageTitle = "路径信息管理";
|
|
}
|
|
|
|
public override List<FieldConfig> FieldConfigs => new()
|
|
{
|
|
new() { PropertyName = "pathCode", DisplayName = "路径编号" },
|
|
new() { PropertyName = "pathName", DisplayName = "路径名称" },
|
|
new() { PropertyName = "pathType", DisplayName = "路径类型", FieldType = FieldType.Number },
|
|
new() { PropertyName = "pathCategory", DisplayName = "路径类别", FieldType = FieldType.Number },
|
|
new() { PropertyName = "startPoint", DisplayName = "起点" },
|
|
new() { PropertyName = "endPoint", DisplayName = "终点" },
|
|
new() { PropertyName = "isFlag", DisplayName = "启用", FieldType = FieldType.CheckBox },
|
|
new() { PropertyName = "remark", DisplayName = "备注" },
|
|
};
|
|
|
|
protected override Expression<Func<BasePathInfo, bool>>? BuildSearchExpression(string search)
|
|
=> x => (x.pathCode != null && x.pathCode.Contains(search))
|
|
|| (x.pathName != null && x.pathName.Contains(search));
|
|
|
|
public override Avalonia.Controls.Control CreateView() => new Sln.Wcs.UI.Views.Path.PathInfoListView();
|
|
|
|
public void LoadDetailsData(BasePathInfo path)
|
|
{
|
|
_currentPath = path;
|
|
LoadDetails();
|
|
SlidePanelTitle = $"路径明细 - {path.pathCode}";
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void ClosePanel()
|
|
{
|
|
IsPanelOpen = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async System.Threading.Tasks.Task AddDetail()
|
|
{
|
|
if (_currentPath is null) return;
|
|
var entity = new BasePathDetails { pathCode = _currentPath.pathCode };
|
|
var editor = new EntityEditWindow();
|
|
var result = await editor.ShowDialog(entity, DetailFieldConfigs, false, GetMainWindow());
|
|
if (result)
|
|
{
|
|
_detailService.Insert(entity);
|
|
LoadDetails();
|
|
}
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task EditDetailAsync(BasePathDetails detail)
|
|
{
|
|
var editor = new EntityEditWindow();
|
|
var result = await editor.ShowDialog(detail, DetailFieldConfigs, true, GetMainWindow());
|
|
if (result)
|
|
{
|
|
_detailService.Update(detail);
|
|
LoadDetails();
|
|
}
|
|
}
|
|
|
|
public void DeleteDetail(BasePathDetails detail)
|
|
{
|
|
_detailService.DeleteById(detail.objId);
|
|
LoadDetails();
|
|
}
|
|
|
|
private void LoadDetails()
|
|
{
|
|
if (_currentPath is null) return;
|
|
var list = _detailService.Query(x => x.pathCode == _currentPath.pathCode);
|
|
DetailItems = new ObservableCollection<BasePathDetails>(list);
|
|
}
|
|
|
|
public List<FieldConfig> DetailFieldConfigs => new()
|
|
{
|
|
new() { PropertyName = "pathCode", DisplayName = "路径编号", IsRequired = true, IsReadOnly = true },
|
|
new() { PropertyName = "pathName", DisplayName = "路径名称" },
|
|
new() { PropertyName = "startPoint", DisplayName = "起点", IsRequired = true },
|
|
new() { PropertyName = "endPoint", DisplayName = "终点", IsRequired = true },
|
|
new() { PropertyName = "deviceType", DisplayName = "设备类型", FieldType = FieldType.Number },
|
|
new() { PropertyName = "isFlag", DisplayName = "启用", FieldType = FieldType.CheckBox },
|
|
new() { PropertyName = "remark", DisplayName = "备注" },
|
|
};
|
|
|
|
private Avalonia.Controls.Window GetMainWindow()
|
|
{
|
|
return (Avalonia.Controls.Window)Avalonia.Application.Current!
|
|
.ApplicationLifetime!.GetType()
|
|
.GetProperty("MainWindow")!
|
|
.GetValue(Avalonia.Application.Current.ApplicationLifetime)!;
|
|
}
|
|
}
|