Department.razor.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using AntDesign;
  2. using AntDesign.TableModels;
  3. using Microsoft.AspNetCore.Components;
  4. using Microsoft.AspNetCore.Components.Web;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. using wispro.sp.share;
  12. using wispro.sp.web.Services;
  13. namespace wispro.sp.web.Pages.Organization
  14. {
  15. public partial class Department
  16. {
  17. private List<wispro.sp.entity.Department> departments;
  18. Tree<wispro.sp.entity.Department> tree;
  19. bool _loading = false;
  20. entity.Department _editDepartment;
  21. [Inject] OrganizationService orgService { get; set; }
  22. [Inject] MessageService _message { get; set; }
  23. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  24. {
  25. //await orgService.Init();
  26. _loading = true;
  27. departments =await orgService.GetDepartments();
  28. var data = await orgService.GetStaffs(null, 1, 10);
  29. _loading = false;
  30. forecasts = data.Results;
  31. _total = data.TotalCount;
  32. _StaffGrade = await orgService.GetStaffGrades();
  33. _allPositions = await orgService.getPositions(null);
  34. _loading = false;
  35. }
  36. #region 部门操作
  37. bool newModal = false;
  38. private void AddNew(entity.Department parentDept)
  39. {
  40. _editDepartment = new entity.Department();
  41. if (parentDept != null)
  42. {
  43. _editDepartment.parentId = parentDept.Id;
  44. //if(!string.IsNullOrEmpty(parentDept.ancestors))
  45. //{
  46. // _editDepartment.ancestors = $"{parentDept.ancestors},{parentDept.Id}";
  47. //}
  48. //else
  49. //{
  50. // _editDepartment.ancestors = parentDept.Id.ToString();
  51. //}
  52. //_editDepartment.order_num = GetChildren(parentDept).Count + 1;
  53. }
  54. newModal = true;
  55. }
  56. private void EditDept(entity.Department department)
  57. {
  58. _editDepartment = department;
  59. newModal = true;
  60. }
  61. private async Task DeleteDept(entity.Department department)
  62. {
  63. var result = await orgService.DeleteDept(department.Id);
  64. departments = await orgService.GetDepartments();
  65. StateHasChanged();
  66. }
  67. private async System.Threading.Tasks.Task NewOk(MouseEventArgs e)
  68. {
  69. newModal = false;
  70. var retObj = await orgService.SaveDept(_editDepartment);
  71. departments = await orgService.GetDepartments();
  72. StateHasChanged();
  73. }
  74. private void NewCancel(MouseEventArgs e)
  75. {
  76. newModal = false;
  77. }
  78. #endregion
  79. async Task OnSelect(TreeEventArgs<entity.Department> e)
  80. {
  81. _editDepartment = e.Node.DataItem;
  82. _loading = true;
  83. var data = await orgService.GetStaffs(_editDepartment, 1, 1000);
  84. forecasts = data.Results;
  85. _pageIndex = 1;
  86. _total = data.TotalCount;
  87. _loading = false;
  88. StateHasChanged();
  89. }
  90. private List<wispro.sp.entity.Department> GetChildren(wispro.sp.entity.Department dept)
  91. {
  92. if(dept == null)
  93. {
  94. var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == null).OrderBy(x=>x.order_num).ToList();
  95. return retList;
  96. }
  97. else
  98. {
  99. var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == dept.Id).OrderBy(x => x.order_num).ToList();
  100. return retList;
  101. }
  102. }
  103. #region 职员操作
  104. private List<Staff> forecasts;
  105. IEnumerable<Staff> selectedRows;
  106. ITable table;
  107. int _pageIndex = 1;
  108. int _pageSize = 10;
  109. int _total = 0;
  110. Staff EditingStaff = null;
  111. bool _isAdd = false;
  112. List<wispro.sp.entity.StaffGrade> _StaffGrade;
  113. string[] _places = new string[] { "深圳", "苏州", "南通", "西安", "北京", "杭州", "武汉" };
  114. bool _newUserModal = false;
  115. private void AddNewUser()
  116. {
  117. if (_editDepartment == null)
  118. {
  119. }
  120. else
  121. {
  122. EditingStaff = new Staff();
  123. _isAdd = true;
  124. _newUserModal = true;
  125. }
  126. }
  127. private int serialNumber(int pageIndex, int pageSize, string name)
  128. {
  129. int iIndex = 0;
  130. foreach (Staff sf in forecasts)
  131. {
  132. iIndex++;
  133. if (sf.Name == name)
  134. {
  135. break;
  136. }
  137. }
  138. return iIndex;
  139. }
  140. private async Task Edit(Staff staff)
  141. {
  142. EditingStaff = staff;
  143. selectPosition = await orgService.getPosition(staff, _editDepartment);
  144. if(selectPosition == null)
  145. {
  146. selectPosition = new Position();
  147. }
  148. //Console.WriteLine($"Edit:{JsonSerializer.Serialize(selectPosition)}");
  149. PositionId = selectPosition.Id;
  150. _isAdd = false;
  151. _newUserModal = true;
  152. }
  153. private void Delete(Staff staff)
  154. {
  155. }
  156. Dictionary<string, object> OnRow(RowData<Staff> row)
  157. {
  158. Dictionary<string, object> ret = new Dictionary<string, object>();
  159. ret.Add("id", row.RowIndex);
  160. ret.Add("onclick", ((Action)delegate
  161. {
  162. //_message.Info($"row {row.Data.Name} was clicked");
  163. }));
  164. return ret;
  165. }
  166. public async System.Threading.Tasks.Task OnChange(QueryModel<Staff> queryModel)
  167. {
  168. if (!_loading)
  169. {
  170. _loading = true;
  171. ListApiResponse<Staff> data = await orgService.GetStaffs(_editDepartment, queryModel); //Http.GetFromJsonAsync<ListApiResponse<Staff>>("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
  172. forecasts = data.Results;
  173. _total = data.TotalCount;
  174. _loading = false;
  175. }
  176. }
  177. private void HandlePageChange(PaginationEventArgs args)
  178. {
  179. if (_pageIndex != args.Page)
  180. {
  181. _pageIndex = args.Page;
  182. }
  183. if (_pageSize != args.PageSize)
  184. {
  185. _pageSize = args.PageSize;
  186. }
  187. }
  188. private List<Position> _allPositions;
  189. Position selectPosition= new Position();
  190. int PositionId;
  191. private async System.Threading.Tasks.Task HandleOk(MouseEventArgs e)
  192. {
  193. //selectPosition = new Position() { Id = PositionId };
  194. var data = await orgService.SaveUser(_editDepartment, selectPosition, EditingStaff); // Http.PostAsJsonAsync<wispro.sp.entity.Staff>($"http://localhost:39476/api/Staff/Save", EditingStaff);
  195. if (data.Success)
  196. {
  197. await _message.Success("数据已保存!");
  198. _newUserModal = false;
  199. _loading = true;
  200. var data1 = await orgService.GetStaffs(_editDepartment, 1, 1000);
  201. forecasts = data1.Results;
  202. _total = data1.TotalCount;
  203. _loading = false;
  204. }
  205. else
  206. {
  207. await _message.Error($"{data.ErrorMessage}");
  208. }
  209. //_newUserModal = false;
  210. }
  211. private void HandleCancel(MouseEventArgs e)
  212. {
  213. _newUserModal = false;
  214. }
  215. private void OnSelectedItemChangedHandler(Position value)
  216. {
  217. selectPosition = value;
  218. //PositionIdChanged.InvokeAsync(_SelectedItem.Id);
  219. }
  220. void UserSelected(Staff staff)
  221. {
  222. EditingStaff = staff;
  223. }
  224. #endregion
  225. }
  226. }