StaffList.razor 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. @if (forecasts == null)
  8. {
  9. <center><Spin /></center>
  10. }
  11. else
  12. {
  13. <div>
  14. <Breadcrumb>
  15. <BreadcrumbItem>
  16. <Icon Type="home"></Icon>
  17. </BreadcrumbItem>
  18. <BreadcrumbItem>
  19. <a><Icon Type="user"></Icon><span>人员清单</span></a>
  20. </BreadcrumbItem>
  21. </Breadcrumb>
  22. </div>
  23. <p />
  24. <AntDesign.Table @ref="table" @bind-PageIndex="_pageIndex" @bind-PageSize="_pageSize"
  25. TItem="Staff"
  26. Loading="_loading"
  27. DataSource="@forecasts"
  28. Total="_total"
  29. @bind-SelectedRows="selectedRows"
  30. OnChange="OnChange"
  31. OnRow="OnRow" RemoteDataSource
  32. Bordered=@true
  33. Size=@TableSize.Middle>
  34. <ChildContent>
  35. <Selection Key="@(context.Name)" />
  36. <AntDesign.Column Title="序号" TData="int">
  37. @serialNumber(_pageIndex, _pageSize, context.Name)
  38. </AntDesign.Column>
  39. <AntDesign.Column Title="姓名" @bind-Field="@context.Name" Sortable Filterable />
  40. <AntDesign.Column Title="入职日期" @bind-Field="@context.EntyDate" Format="yyyy-MM-dd" Sortable Filterable />
  41. <AntDesign.Column Title="部门" @bind-Field="@context.Department" Sortable Filterable />
  42. <AntDesign.Column Title="工作地" Field="@context.WorkPlace" Sortable Filterable />
  43. <AntDesign.Column Title="备注" @bind-Field="@context.Memo" Sortable Filterable />
  44. <ActionColumn>
  45. <Space>
  46. <SpaceItem><Button Danger OnClick="()=>Delete(context.Name)">编辑</Button></SpaceItem>
  47. </Space>
  48. </ActionColumn>
  49. </ChildContent>
  50. <PaginationTemplate>
  51. <div style="display: flex; align-items: center">
  52. <Pagination Class="my-custom-pagination"
  53. Total="@_total"
  54. PageSize="@_pageSize"
  55. Current="@_pageIndex"
  56. ShowSizeChanger="@true"
  57. OnChange="HandlePageChange" />
  58. </div>
  59. </PaginationTemplate>
  60. </AntDesign.Table>
  61. }
  62. <Modal Title="修改"
  63. Visible="@_visible"
  64. OnOk="@HandleOk"
  65. OnCancel="@HandleCancel">
  66. <Form Model="EditingStaff" LabelColSpan="6"
  67. WrapperColSpan="16">
  68. <FormItem Label="姓名">
  69. <Input @bind-Value="@context.Name" />
  70. </FormItem>
  71. <FormItem Label="岗位状态">
  72. <Input @bind-Value="@context.Status" />
  73. </FormItem>
  74. <FormItem Label="是否计算绩效">
  75. <Switch @bind-Value="@context.IsCalPerformsnce" />
  76. </FormItem>
  77. <FormItem Label="工程师等级">
  78. <Input @bind-Value="@context.StaffGrade.Grade" />
  79. </FormItem>
  80. <FormItem Label="等级系数">
  81. <Input @bind-Value="@context.StaffGrade.Coefficient" />
  82. </FormItem>
  83. <FormItem Label="部门">
  84. <Input @bind-Value="@context.Department" />
  85. </FormItem>
  86. <FormItem Label="工作地">
  87. <Select Mode="default"
  88. DataSource="@_places"
  89. @bind-Value="@context.WorkPlace">
  90. </Select>
  91. </FormItem>
  92. <FormItem Label="入职时间">
  93. <DatePicker @bind-Value="@context.EntyDate" />
  94. </FormItem>
  95. <FormItem Label="备注">
  96. <TextArea @bind-Value="@context.Memo" MinRows="4" />
  97. </FormItem>
  98. </Form>
  99. </Modal>
  100. <style>
  101. .my-custom-pagination {
  102. margin: 15px 0;
  103. }
  104. .my-custom-pagination .ant-pagination-item,
  105. .my-custom-pagination .ant-pagination-item-link {
  106. border-radius: 100%;
  107. }
  108. </style>
  109. @using System.Text.Json;
  110. @code {
  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. bool _loading = false;
  118. Staff EditingStaff = null;
  119. bool _visible = false;
  120. string[] _places = new string[] { "深圳", "苏州", "南通" };
  121. protected override async Task OnInitializedAsync()
  122. {
  123. _loading = true;
  124. StaffApiResponse data = await Http.GetFromJsonAsync<StaffApiResponse>($"http://localhost:39476/api/Staff/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
  125. _loading = false;
  126. forecasts = data.Results;
  127. _total = data.TotalCount;
  128. }
  129. private void HandlePageChange(PaginationEventArgs args)
  130. {
  131. if (_pageIndex != args.Page)
  132. {
  133. _pageIndex = args.Page;
  134. }
  135. if (_pageSize != args.PageSize)
  136. {
  137. _pageSize = args.PageSize;
  138. }
  139. }
  140. public async Task OnChange(QueryModel<Staff> queryModel)
  141. {
  142. _loading = true;
  143. StaffApiResponse data = await Http.GetFromJsonAsync<StaffApiResponse>("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
  144. _loading = false;
  145. forecasts = data.Results;
  146. _total = data.TotalCount;
  147. }
  148. public int serialNumber(int pageIndex, int pageSize, string name)
  149. {
  150. int iIndex = 0;
  151. foreach (Staff sf in forecasts)
  152. {
  153. iIndex++;
  154. if (sf.Name == name)
  155. {
  156. break;
  157. }
  158. }
  159. return (pageIndex - 1) * pageSize + iIndex;
  160. }
  161. Dictionary<string, object> OnRow(RowData<Staff> row)
  162. {
  163. Dictionary<string, object> ret = new Dictionary<string, object>();
  164. ret.Add("id", row.RowIndex);
  165. ret.Add("onclick", ((Action)delegate
  166. {
  167. _message.Info($"row {row.Data.Name} was clicked");
  168. }));
  169. return ret;
  170. }
  171. public void RemoveSelection(string name)
  172. {
  173. var selected = selectedRows.Where(x => x.Name != name);
  174. selectedRows = selected;
  175. }
  176. private void Delete(string name)
  177. {
  178. var rList = forecasts.Where(x => x.Name == name).ToList();
  179. if (rList.Count() > 0)
  180. {
  181. EditingStaff = rList[0];
  182. _visible = true;
  183. }
  184. else
  185. {
  186. }
  187. //_total = forecasts.Length;
  188. }
  189. string GetRandomuserParams(QueryModel<Staff> queryModel)
  190. {
  191. List<string> query = new List<string>()
  192. {
  193. $"pageSize={queryModel.PageSize}",
  194. $"pageIndex={queryModel.PageIndex}",
  195. };
  196. queryModel.SortModel.ForEach(x =>
  197. {
  198. query.Add($"sortField={x.FieldName.ToLower()}");
  199. query.Add($"sortOrder={x.Sort}");
  200. });
  201. //queryModel.FilterModel.ForEach(filter =>
  202. //{
  203. // filter.SelectedValues.ForEach(value =>
  204. // {
  205. // query.Add($"{filter.FieldName.ToLower()}={value}");
  206. // });
  207. //});
  208. return string.Join('&', query);
  209. }
  210. private void HandleOk(MouseEventArgs e)
  211. {
  212. Console.WriteLine(e);
  213. _visible = false;
  214. }
  215. private void HandleCancel(MouseEventArgs e)
  216. {
  217. Console.WriteLine(e);
  218. _visible = false;
  219. }
  220. }