using AntDesign; using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using wispro.sp.entity; using wispro.sp.entity.workflowDefine; using wispro.sp.web.Services; namespace wispro.sp.web.Components { public partial class ResponseManCondition { UserConditionType userConditionType; UserType _userType; List departments; List lstPosition; int SelectPositionsId; internal class UserConditionTpyeItem { public UserConditionType Type { get; set; } public string Description { get { return EnumHelper.GetDescription(Type); } } } List uctItems = new List(); List optoins = new List(); private List GetFromDepartment(List _departments) { List retList = new List(); foreach(var dept in _departments) { CascaderNode node = new CascaderNode() { Label = dept.Name, Value = dept.Id.ToString() }; retList.Add(node); } foreach(var dept in _departments) { if(dept.parentId != null) { var parentNode = FindNode(dept.parentId.Value.ToString(),retList); var currentNode = FindNode(dept.Id.ToString(), retList); Console.WriteLine($"Find:{dept.parentId},return:{System.Text.Json.JsonSerializer.Serialize(parentNode)}"); Console.WriteLine($"Find:{dept.Id},return:{System.Text.Json.JsonSerializer.Serialize(currentNode)}"); if (parentNode != null) { if (parentNode.Children == null) { parentNode.Children = new List(); } ((List)parentNode.Children).Add(currentNode); retList.Remove(currentNode); } } } return retList; } private CascaderNode FindNode(string deptId,List retList) { foreach(var node in retList) { if (node.Value == deptId) { Console.WriteLine($"Founded:{System.Text.Json.JsonSerializer.Serialize(node)}"); return node; } else { if (node.Children != null) { var temNode = FindNode(deptId, (List)node.Children); if (temNode != null) { return temNode; } } } } return null; } [Inject] OrganizationService _orgService { get; set; } [Parameter] public Workflow Workflow { get; set; } [Parameter] public UserField UserField { get; set; } protected async override Task OnInitializedAsync() { departments =await _orgService.GetDepartments(); lstPosition = await _orgService.getPositions(null); optoins = GetFromDepartment(departments); uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.Department }); uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.DepartmentPosition }); uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.Staff }); uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.UserDepartment }); uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.UserDepartmentPosition }); await base.OnInitializedAsync(); } private void OnUCTItemChangedHandler(UserConditionTpyeItem value) { userConditionType = value.Type; } private async Task OnDeptChange(CascaderNode[] selectedNodes) { int deptId = int.Parse(selectedNodes[0].Value); if(userConditionType == UserConditionType.DepartmentPosition || userConditionType == UserConditionType.DepartmentPosition) { lstPosition =await _orgService.getPositions(deptId); } } void OnPositionChangedHandler(Position position) { UserField.Positon = position.Id.ToString(); } } }