Department.razor.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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();
  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. _total = data.TotalCount;
  86. _loading = false;
  87. }
  88. private List<wispro.sp.entity.Department> GetChildren(wispro.sp.entity.Department dept)
  89. {
  90. if(dept == null)
  91. {
  92. var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == null).OrderBy(x=>x.order_num).ToList();
  93. return retList;
  94. }
  95. else
  96. {
  97. var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == dept.Id).OrderBy(x => x.order_num).ToList();
  98. return retList;
  99. }
  100. }
  101. #region 职员操作
  102. private List<Staff> forecasts;
  103. IEnumerable<Staff> selectedRows;
  104. ITable table;
  105. int _pageIndex = 1;
  106. int _pageSize = 10;
  107. int _total = 0;
  108. Staff EditingStaff = null;
  109. bool _isAdd = false;
  110. List<wispro.sp.entity.StaffGrade> _StaffGrade;
  111. string[] _places = new string[] { "深圳", "苏州", "南通", "西安", "北京", "杭州", "武汉" };
  112. bool _newUserModal = false;
  113. private void AddNewUser()
  114. {
  115. if (_editDepartment == null)
  116. {
  117. }
  118. else
  119. {
  120. EditingStaff = new Staff();
  121. _isAdd = true;
  122. _newUserModal = true;
  123. }
  124. }
  125. private int serialNumber(int pageIndex, int pageSize, string name)
  126. {
  127. int iIndex = 0;
  128. foreach (Staff sf in forecasts)
  129. {
  130. iIndex++;
  131. if (sf.Name == name)
  132. {
  133. break;
  134. }
  135. }
  136. return (pageIndex - 1) * pageSize + iIndex;
  137. }
  138. private async Task Edit(Staff staff)
  139. {
  140. EditingStaff = staff;
  141. selectPosition = await orgService.getPosition(staff, _editDepartment);
  142. if(selectPosition == null)
  143. {
  144. selectPosition = new Position();
  145. }
  146. Console.WriteLine($"Edit:{JsonSerializer.Serialize(selectPosition)}");
  147. PositionId = selectPosition.Id;
  148. _isAdd = false;
  149. _newUserModal = true;
  150. }
  151. private void Delete(Staff staff)
  152. {
  153. }
  154. Dictionary<string, object> OnRow(RowData<Staff> row)
  155. {
  156. Dictionary<string, object> ret = new Dictionary<string, object>();
  157. ret.Add("id", row.RowIndex);
  158. ret.Add("onclick", ((Action)delegate
  159. {
  160. //_message.Info($"row {row.Data.Name} was clicked");
  161. }));
  162. return ret;
  163. }
  164. public async System.Threading.Tasks.Task OnChange(QueryModel<Staff> queryModel)
  165. {
  166. if (!_loading)
  167. {
  168. _loading = true;
  169. ListApiResponse<Staff> data = await orgService.GetStaffs(_editDepartment, queryModel); //Http.GetFromJsonAsync<ListApiResponse<Staff>>("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
  170. forecasts = data.Results;
  171. _total = data.TotalCount;
  172. _loading = false;
  173. }
  174. }
  175. private void HandlePageChange(PaginationEventArgs args)
  176. {
  177. if (_pageIndex != args.Page)
  178. {
  179. _pageIndex = args.Page;
  180. }
  181. if (_pageSize != args.PageSize)
  182. {
  183. _pageSize = args.PageSize;
  184. }
  185. }
  186. private List<Position> _allPositions;
  187. Position selectPosition= new Position();
  188. int PositionId;
  189. private async System.Threading.Tasks.Task HandleOk(MouseEventArgs e)
  190. {
  191. //selectPosition = new Position() { Id = PositionId };
  192. var data = await orgService.SaveUser(_editDepartment, selectPosition, EditingStaff); // Http.PostAsJsonAsync<wispro.sp.entity.Staff>($"http://localhost:39476/api/Staff/Save", EditingStaff);
  193. if (data.Success)
  194. {
  195. await _message.Success("数据已保存!");
  196. _newUserModal = false;
  197. _loading = true;
  198. var data1 = await orgService.GetStaffs(_editDepartment, 1, 1000);
  199. forecasts = data1.Results;
  200. _total = data1.TotalCount;
  201. _loading = false;
  202. }
  203. else
  204. {
  205. await _message.Error($"{data.ErrorMessage}");
  206. }
  207. //_newUserModal = false;
  208. }
  209. private void HandleCancel(MouseEventArgs e)
  210. {
  211. _newUserModal = false;
  212. }
  213. private void OnSelectedItemChangedHandler(Position value)
  214. {
  215. selectPosition = value;
  216. //PositionIdChanged.InvokeAsync(_SelectedItem.Id);
  217. }
  218. void UserSelected(Staff staff)
  219. {
  220. EditingStaff = staff;
  221. }
  222. #endregion
  223. }
  224. }