StaffGrade.razor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.Net.Http.Json;
  9. using System.Threading.Tasks;
  10. using wispro.sp.share;
  11. using wispro.sp.web.Services;
  12. namespace wispro.sp.web.Pages
  13. {
  14. public partial class StaffGrade
  15. {
  16. [Inject] public StaffGradeService _sfService { get; set; }
  17. [Inject] MessageService _message { get; set; }
  18. private List<wispro.sp.entity.StaffGrade> staffGrades;
  19. IEnumerable<wispro.sp.entity.StaffGrade> selectedRows;
  20. ITable table;
  21. int _pageIndex = 1;
  22. int _pageSize = 10;
  23. int _total = 0;
  24. bool _loading = false;
  25. wispro.sp.entity.StaffGrade EditingStaff = null;
  26. bool _visible = false;
  27. bool _isAdd = false;
  28. protected override async Task OnInitializedAsync()
  29. {
  30. _loading = true;
  31. List<wispro.sp.entity.StaffGrade> data = await _sfService.GetAll();// await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  32. _loading = false;
  33. staffGrades = data;
  34. _total = data.Count;
  35. }
  36. private void HandlePageChange(PaginationEventArgs args)
  37. {
  38. if (_pageIndex != args.Page)
  39. {
  40. _pageIndex = args.Page;
  41. }
  42. if (_pageSize != args.PageSize)
  43. {
  44. _pageSize = args.PageSize;
  45. }
  46. }
  47. Dictionary<string, object> OnRow(RowData<wispro.sp.entity.StaffGrade> row)
  48. {
  49. Dictionary<string, object> ret = new Dictionary<string, object>();
  50. ret.Add("id", row.Data.Id);
  51. ret.Add("onclick", ((Action)delegate
  52. {
  53. //_message.Info($"row {row.Data.Grade} was clicked");
  54. }));
  55. return ret;
  56. }
  57. public void RemoveSelection(int id)
  58. {
  59. //var selected = selectedRows.Where(x => x.Id != id);
  60. //selectedRows = selected;
  61. }
  62. private void Delete(int id)
  63. {
  64. var rList = staffGrades.Where(x => x.Id == id).ToList();
  65. if (rList.Count() > 0)
  66. {
  67. EditingStaff = rList[0];
  68. _isAdd = false;
  69. _visible = true;
  70. }
  71. else
  72. {
  73. }
  74. _total = staffGrades.Count;
  75. }
  76. private void Edit(int id)
  77. {
  78. var rList = staffGrades.Where(x => x.Id == id).ToList();
  79. if (rList.Count() > 0)
  80. {
  81. EditingStaff = rList[0];
  82. _isAdd = false;
  83. _visible = true;
  84. }
  85. else
  86. {
  87. }
  88. _total = staffGrades.Count;
  89. }
  90. private void AddNew()
  91. {
  92. EditingStaff = new entity.StaffGrade();
  93. _isAdd = true;
  94. _visible = true;
  95. }
  96. private async Task HandleOk(MouseEventArgs e)
  97. {
  98. ApiSaveResponse result = await _sfService.Save(EditingStaff);
  99. if (result.Success)
  100. {
  101. await _message.Success("数据已保存!");
  102. }
  103. else
  104. {
  105. await _message.Error($"{result.ErrorMessage}");
  106. }
  107. _visible = false;
  108. }
  109. private void HandleCancel(MouseEventArgs e)
  110. {
  111. _visible = false;
  112. }
  113. }
  114. }