Department.razor.cs 8.9 KB

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