StaffGrade.razor 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. @page "/StaffGrade"
  2. @inject HttpClient Http
  3. @using AntDesign.TableModels
  4. @inject MessageService _message
  5. @using System.ComponentModel
  6. @using wispro.sp.share
  7. @if (staffGrades == 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"
  25. TItem="wispro.sp.entity.StaffGrade"
  26. Loading="_loading"
  27. DataSource="@staffGrades"
  28. Total="_total"
  29. @bind-SelectedRows="selectedRows"
  30. OnRow="OnRow"
  31. Bordered=@true
  32. Size=@TableSize.Middle>
  33. <ChildContent>
  34. <Selection Key="@(context.Id.ToString())" />
  35. <AntDesign.Column Title="序号" TData="int" @bind-Field="@context.Id">
  36. </AntDesign.Column>
  37. <AntDesign.Column Title="代理人等级" @bind-Field="@context.Grade" Sortable Filterable />
  38. <AntDesign.Column Title="代理人系数" @bind-Field="@context.Coefficient" Sortable Filterable />
  39. <ActionColumn>
  40. <Space>
  41. <SpaceItem><Button Danger OnClick="()=>Edit(context.Id)">编辑</Button></SpaceItem>
  42. </Space>
  43. </ActionColumn>
  44. </ChildContent>
  45. </AntDesign.Table>
  46. }
  47. <Modal Title="修改"
  48. Visible="@_visible"
  49. OnOk="@HandleOk"
  50. OnCancel="@HandleCancel">
  51. <Form Model="EditingStaff" LabelColSpan="6"
  52. WrapperColSpan="16">
  53. @if (_isAdd) {
  54. <FormItem Label="代理人等级">
  55. <Input @bind-Value="@context.Grade" />
  56. </FormItem>
  57. }
  58. else
  59. {
  60. <FormItem Label="代理人等级">
  61. <span>@context.Grade</span>
  62. </FormItem>
  63. }
  64. <FormItem Label="等级系数">
  65. <Input @bind-Value="@context.Coefficient" />
  66. </FormItem>
  67. </Form>
  68. </Modal>
  69. <style>
  70. .my-custom-pagination {
  71. margin: 15px 0;
  72. }
  73. .my-custom-pagination .ant-pagination-item,
  74. .my-custom-pagination .ant-pagination-item-link {
  75. border-radius: 100%;
  76. }
  77. </style>
  78. @using System.Text.Json;
  79. @code {
  80. private List<wispro.sp.entity.StaffGrade> staffGrades;
  81. IEnumerable<wispro.sp.entity.StaffGrade> selectedRows;
  82. ITable table;
  83. int _pageIndex = 1;
  84. int _pageSize = 10;
  85. int _total = 0;
  86. bool _loading = false;
  87. wispro.sp.entity.StaffGrade EditingStaff = null;
  88. bool _visible = false;
  89. bool _isAdd = false;
  90. protected override async Task OnInitializedAsync()
  91. {
  92. _loading = true;
  93. List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  94. _loading = false;
  95. staffGrades = data;
  96. _total = data.Count;
  97. }
  98. private void HandlePageChange(PaginationEventArgs args)
  99. {
  100. if (_pageIndex != args.Page)
  101. {
  102. _pageIndex = args.Page;
  103. }
  104. if (_pageSize != args.PageSize)
  105. {
  106. _pageSize = args.PageSize;
  107. }
  108. }
  109. Dictionary<string, object> OnRow(RowData<wispro.sp.entity.StaffGrade> row)
  110. {
  111. Dictionary<string, object> ret = new Dictionary<string, object>();
  112. ret.Add("id", row.Data.Id);
  113. ret.Add("onclick", ((Action)delegate
  114. {
  115. //_message.Info($"row {row.Data.Grade} was clicked");
  116. }));
  117. return ret;
  118. }
  119. public void RemoveSelection(int id)
  120. {
  121. //var selected = selectedRows.Where(x => x.Id != id);
  122. //selectedRows = selected;
  123. }
  124. private void Delete(int id)
  125. {
  126. var rList = staffGrades.Where(x => x.Id == id).ToList();
  127. if (rList.Count() > 0)
  128. {
  129. EditingStaff = rList[0];
  130. _visible = true;
  131. }
  132. else
  133. {
  134. }
  135. _total = staffGrades.Count;
  136. }
  137. private void Edit(int id)
  138. {
  139. var rList = staffGrades.Where(x => x.Id == id).ToList();
  140. if (rList.Count() > 0)
  141. {
  142. EditingStaff = rList[0];
  143. _visible = true;
  144. }
  145. else
  146. {
  147. }
  148. _total = staffGrades.Count;
  149. }
  150. private async Task HandleOk(MouseEventArgs e)
  151. {
  152. var data = await Http.PostAsJsonAsync<wispro.sp.entity.StaffGrade>($"http://localhost:39476/api/StaffGrade/Save", EditingStaff);
  153. if (data.IsSuccessStatusCode)
  154. {
  155. ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  156. await Task.Delay(1000);
  157. if (result.Success)
  158. {
  159. _message.Success("数据已保存!");
  160. }
  161. else
  162. {
  163. _message.Error($"{result.ErrorMessage}");
  164. }
  165. }
  166. else
  167. {
  168. _message.Error($"请求发生错误 {data.StatusCode}");
  169. }
  170. _visible = false;
  171. }
  172. private void HandleCancel(MouseEventArgs e)
  173. {
  174. Console.WriteLine(e);
  175. _visible = false;
  176. }
  177. }