StaffList.razor 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. @page "/StaffList"
  2. @inject HttpClient Http
  3. @using AntDesign.TableModels
  4. @inject MessageService _message
  5. @using System.ComponentModel
  6. @using wispro.sp.share;
  7. @attribute [Authorize(Roles ="Admin")]
  8. <PageContainer>
  9. <Breadcrumb>
  10. <Breadcrumb>
  11. <BreadcrumbItem>
  12. <a href="/Home"><Icon Type="home"></Icon></a>
  13. </BreadcrumbItem>
  14. <BreadcrumbItem>
  15. <Icon Type="setting"></Icon><span>基本信息管理</span>
  16. </BreadcrumbItem>
  17. <BreadcrumbItem>
  18. <Icon Type="user"></Icon><span>账号管理</span>
  19. </BreadcrumbItem>
  20. </Breadcrumb>
  21. </Breadcrumb>
  22. <Content>
  23. <Button Type="primary" Icon="plus" OnClick="AddNew" Style="float:right">添加</Button>
  24. </Content>
  25. <ChildContent>
  26. @if (forecasts == null)
  27. {
  28. <center><Spin /></center>
  29. }
  30. else
  31. {
  32. <AntDesign.Table @ref="table" @bind-PageIndex="_pageIndex" @bind-PageSize="_pageSize"
  33. TItem="Staff"
  34. Loading="_loading"
  35. DataSource="@forecasts"
  36. Total="_total"
  37. @bind-SelectedRows="selectedRows"
  38. OnChange="OnChange"
  39. OnRow="OnRow" RemoteDataSource
  40. Bordered=@true
  41. Size=@TableSize.Middle>
  42. <ChildContent>
  43. <Selection Key="@(context.Name)" />
  44. <AntDesign.Column Title="序号" TData="int">
  45. @serialNumber(_pageIndex, _pageSize, context.Name)
  46. </AntDesign.Column>
  47. <AntDesign.Column Title="姓名" @bind-Field="@context.Name" Sortable Filterable />
  48. <AntDesign.Column Title="入职日期" @bind-Field="@context.EntyDate" Format="yyyy-MM-dd" Sortable Filterable />
  49. <AntDesign.Column Title="部门" @bind-Field="@context.Department" Sortable Filterable />
  50. <AntDesign.Column Title="工作地" Field="@context.WorkPlace" Sortable Filterable />
  51. <AntDesign.Column Title="备注" @bind-Field="@context.Memo" Sortable Filterable />
  52. <ActionColumn>
  53. <Space>
  54. <SpaceItem><Button Danger OnClick="()=>Delete(context.Name)">编辑</Button></SpaceItem>
  55. </Space>
  56. </ActionColumn>
  57. </ChildContent>
  58. <PaginationTemplate>
  59. <div style="display: flex; align-items: center">
  60. <Pagination Class="my-custom-pagination"
  61. Total="@_total"
  62. PageSize="@_pageSize"
  63. Current="@_pageIndex"
  64. ShowSizeChanger="@true"
  65. OnChange="HandlePageChange" />
  66. </div>
  67. </PaginationTemplate>
  68. </AntDesign.Table>
  69. }
  70. </ChildContent>
  71. </PageContainer>
  72. <Modal Title="修改"
  73. Visible="@_visible"
  74. OnOk="@HandleOk"
  75. OnCancel="@HandleCancel">
  76. <Form Model="EditingStaff" LabelColSpan="6"
  77. WrapperColSpan="16">
  78. <FormItem Label="姓名">
  79. <Input @bind-Value="@context.Name" />
  80. </FormItem>
  81. <FormItem Label="岗位状态">
  82. <Input @bind-Value="@context.Status" />
  83. </FormItem>
  84. <FormItem Label="是否计算绩效">
  85. <Switch @bind-Value="@context.IsCalPerformsnce" />
  86. </FormItem>
  87. <FormItem Label="工程师等级">
  88. <wispro.sp.web.Components.UserGradeSelect @bind-StaffGradeId="@EditingStaff.StaffGradeId" />
  89. </FormItem>
  90. <FormItem Label="部门">
  91. <Input @bind-Value="@context.Department" />
  92. </FormItem>
  93. <FormItem Label="工作地">
  94. <Select Mode="default"
  95. DataSource="@_places"
  96. @bind-Value="@context.WorkPlace">
  97. </Select>
  98. </FormItem>
  99. <FormItem Label="入职时间">
  100. <DatePicker @bind-Value="@context.EntyDate" />
  101. </FormItem>
  102. <FormItem Label="备注">
  103. <TextArea @bind-Value="@context.Memo" MinRows="4" />
  104. </FormItem>
  105. @if (_isAdd)
  106. {
  107. <FormItem Label="账号">
  108. <Input @bind-Value="@context.Account" />
  109. </FormItem>
  110. <FormItem Label="账号">
  111. <Input @bind-Value="@context.Password" Type="password" />
  112. </FormItem>
  113. }
  114. </Form>
  115. </Modal>
  116. <style>
  117. .my-custom-pagination {
  118. margin: 15px 0;
  119. }
  120. .my-custom-pagination .ant-pagination-item,
  121. .my-custom-pagination .ant-pagination-item-link {
  122. border-radius: 100%;
  123. }
  124. </style>
  125. @using System.Text.Json;
  126. @code {
  127. private List<Staff> forecasts;
  128. IEnumerable<Staff> selectedRows;
  129. ITable table;
  130. int _pageIndex = 1;
  131. int _pageSize = 10;
  132. int _total = 0;
  133. bool _loading = false;
  134. Staff EditingStaff = null;
  135. bool _visible = false;
  136. bool _isAdd = false;
  137. List<wispro.sp.entity.StaffGrade> _StaffGrade;
  138. string[] _places = new string[] { "深圳", "苏州", "南通", "西安", "北京", "杭州", "武汉", "重庆", "昆山", "成都" };
  139. int _SelectGradeId;
  140. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  141. {
  142. _loading = true;
  143. ListApiResponse<Staff> data = await Http.GetFromJsonAsync<ListApiResponse<Staff>>($"http://localhost:39476/api/Staff/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
  144. _loading = false;
  145. forecasts = data.Results;
  146. _total = data.TotalCount;
  147. _StaffGrade = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  148. }
  149. private void HandlePageChange(PaginationEventArgs args)
  150. {
  151. if (_pageIndex != args.Page)
  152. {
  153. _pageIndex = args.Page;
  154. }
  155. if (_pageSize != args.PageSize)
  156. {
  157. _pageSize = args.PageSize;
  158. }
  159. }
  160. public async System.Threading.Tasks.Task OnChange(QueryModel<Staff> queryModel)
  161. {
  162. _loading = true;
  163. ListApiResponse<Staff> data = await Http.GetFromJsonAsync<ListApiResponse<Staff>>("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
  164. _loading = false;
  165. forecasts = data.Results;
  166. _total = data.TotalCount;
  167. }
  168. public int serialNumber(int pageIndex, int pageSize, string name)
  169. {
  170. int iIndex = 0;
  171. foreach (Staff sf in forecasts)
  172. {
  173. iIndex++;
  174. if (sf.Name == name)
  175. {
  176. break;
  177. }
  178. }
  179. return (pageIndex - 1) * pageSize + iIndex;
  180. }
  181. Dictionary<string, object> OnRow(RowData<Staff> row)
  182. {
  183. Dictionary<string, object> ret = new Dictionary<string, object>();
  184. ret.Add("id", row.RowIndex);
  185. ret.Add("onclick", ((Action)delegate
  186. {
  187. //_message.Info($"row {row.Data.Name} was clicked");
  188. }));
  189. return ret;
  190. }
  191. private void AddNew()
  192. {
  193. EditingStaff = new entity.Staff();
  194. _isAdd = true;
  195. _visible = true;
  196. }
  197. public void RemoveSelection(string name)
  198. {
  199. var selected = selectedRows.Where(x => x.Name != name);
  200. selectedRows = selected;
  201. }
  202. private void Delete(string name)
  203. {
  204. var rList = forecasts.Where(x => x.Name == name).ToList();
  205. if (rList.Count() > 0)
  206. {
  207. EditingStaff = rList[0];
  208. _isAdd = false;
  209. _visible = true;
  210. }
  211. else
  212. {
  213. }
  214. //_total = forecasts.Length;
  215. }
  216. string GetRandomuserParams(QueryModel<Staff> queryModel)
  217. {
  218. List<string> query = new List<string>()
  219. {
  220. $"pageSize={queryModel.PageSize}",
  221. $"pageIndex={queryModel.PageIndex}",
  222. };
  223. queryModel.SortModel.ForEach(x =>
  224. {
  225. if (x.Sort != null)
  226. {
  227. query.Add($"sortField={x.FieldName.ToLower()}");
  228. query.Add($"sortOrder={x.Sort}");
  229. }
  230. });
  231. queryModel.FilterModel.ForEach(filter =>
  232. {
  233. filter.SelectedValues.ForEach(value =>
  234. {
  235. query.Add($"{filter.FieldName.ToLower()}={value}");
  236. });
  237. });
  238. return string.Join('&', query);
  239. }
  240. private async System.Threading.Tasks.Task HandleOk(MouseEventArgs e)
  241. {
  242. var data = await Http.PostAsJsonAsync<wispro.sp.entity.Staff>($"http://localhost:39476/api/Staff/Save", EditingStaff);
  243. if (data.IsSuccessStatusCode)
  244. {
  245. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  246. //await Task.Delay(1000);
  247. if (result.Success)
  248. {
  249. await _message.Success("数据已保存!");
  250. _visible = false;
  251. await OnChange((QueryModel<Staff>)table.GetQueryModel());
  252. }
  253. else
  254. {
  255. await _message.Error($"{result.ErrorMessage}");
  256. }
  257. }
  258. else
  259. {
  260. await _message.Error($"请求发生错误 {data.StatusCode}");
  261. }
  262. }
  263. private void HandleCancel(MouseEventArgs e)
  264. {
  265. _visible = false;
  266. }
  267. }