ResponseManCondition.razor.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. using wispro.sp.entity.workflowDefine;
  9. using wispro.sp.web.Services;
  10. namespace wispro.sp.web.Components
  11. {
  12. public partial class ResponseManCondition
  13. {
  14. UserConditionInput UserConditionInput;
  15. UserConditionType userConditionType;
  16. UserType _userType;
  17. List<Department> departments;
  18. List<Position> lstPosition;
  19. int SelectPositionsId;
  20. internal class UserConditionTpyeItem
  21. {
  22. public UserConditionType Type { get; set; }
  23. public string Description
  24. {
  25. get
  26. {
  27. return EnumHelper.GetDescription<UserConditionType>(Type);
  28. }
  29. }
  30. }
  31. List<UserConditionTpyeItem> uctItems = new List<UserConditionTpyeItem>();
  32. List<CascaderNode> optoins = new List<CascaderNode>();
  33. private List<CascaderNode> GetFromDepartment(List<Department> _departments)
  34. {
  35. List<CascaderNode> retList = new List<CascaderNode>();
  36. foreach(var dept in _departments)
  37. {
  38. CascaderNode node = new CascaderNode() { Label = dept.Name, Value = dept.Id.ToString() };
  39. retList.Add(node);
  40. }
  41. foreach(var dept in _departments)
  42. {
  43. if(dept.parentId != null)
  44. {
  45. var parentNode = FindNode(dept.parentId.Value.ToString(),retList);
  46. var currentNode = FindNode(dept.Id.ToString(), retList);
  47. //Console.WriteLine($"Find:{dept.parentId},return:{System.Text.Json.JsonSerializer.Serialize(parentNode)}");
  48. //Console.WriteLine($"Find:{dept.Id},return:{System.Text.Json.JsonSerializer.Serialize(currentNode)}");
  49. if (parentNode != null)
  50. {
  51. if (parentNode.Children == null)
  52. {
  53. parentNode.Children = new List<CascaderNode>();
  54. }
  55. ((List<CascaderNode>)parentNode.Children).Add(currentNode);
  56. retList.Remove(currentNode);
  57. }
  58. }
  59. }
  60. return retList;
  61. }
  62. private CascaderNode FindNode(string deptId,List<CascaderNode> retList)
  63. {
  64. foreach(var node in retList)
  65. {
  66. if (node.Value == deptId)
  67. {
  68. //Console.WriteLine($"Founded:{System.Text.Json.JsonSerializer.Serialize(node)}");
  69. return node;
  70. }
  71. else
  72. {
  73. if (node.Children != null)
  74. {
  75. var temNode = FindNode(deptId, (List<CascaderNode>)node.Children);
  76. if (temNode != null)
  77. {
  78. return temNode;
  79. }
  80. }
  81. }
  82. }
  83. return null;
  84. }
  85. [Inject] OrganizationService _orgService { get; set; }
  86. [Parameter]
  87. public Workflow Workflow { get; set; }
  88. [Parameter]
  89. public UserField UserField { get; set; }
  90. protected async override Task OnInitializedAsync()
  91. {
  92. departments =await _orgService.GetDepartments();
  93. lstPosition = await _orgService.getPositions(null);
  94. optoins = GetFromDepartment(departments);
  95. uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.Department });
  96. uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.DepartmentPosition });
  97. uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.Staff });
  98. uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.UserDepartment });
  99. uctItems.Add(new UserConditionTpyeItem() { Type = UserConditionType.UserDepartmentPosition });
  100. if (UserField != null)
  101. {
  102. if (!string.IsNullOrEmpty(UserField.Positon))
  103. {
  104. SelectPositionsId = int.Parse(UserField.Positon);
  105. }
  106. }
  107. await base.OnInitializedAsync();
  108. }
  109. private void OnUCTItemChangedHandler(UserConditionTpyeItem value)
  110. {
  111. userConditionType = value.Type;
  112. }
  113. private async Task OnDeptChange(CascaderNode[] selectedNodes)
  114. {
  115. int deptId = int.Parse(selectedNodes[0].Value);
  116. if(userConditionType == UserConditionType.DepartmentPosition || userConditionType == UserConditionType.DepartmentPosition)
  117. {
  118. lstPosition =await _orgService.getPositions(deptId);
  119. }
  120. }
  121. void OnPositionChangedHandler(Position position)
  122. {
  123. UserField.Positon = position.Id.ToString();
  124. }
  125. void OnUserValueChange(UserItem userItem)
  126. {
  127. UserField.UserValue = userItem.Value;
  128. UserField.UserType = userItem.UserType;
  129. }
  130. }
  131. }