CustomerList.razor.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.Threading.Tasks;
  9. using wispro.sp.web.Services;
  10. namespace wispro.sp.web.Pages
  11. {
  12. public partial class CustomerList
  13. {
  14. private List<entity.Customer> _Customers =new List<entity.Customer>();
  15. IEnumerable<entity.Customer> selectedRows;
  16. ITable table;
  17. int _pageIndex = 1;
  18. int _pageSize = 10;
  19. int _total = 0;
  20. bool _loading = false;
  21. entity.Customer Editing = null;
  22. bool _visible = false;
  23. bool _isAdd = false;
  24. [Inject]OrganizationService orgService { get; set; }
  25. [Inject] protected IAuthService _authService { get; set; }
  26. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  27. {
  28. await _authService.CanVisitResource();
  29. _loading = true;
  30. _Customers = await orgService.GetAllCustomer();
  31. //await System.Threading.Thread.Sleep();
  32. //List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  33. _loading = false;
  34. _total = _Customers.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<entity.Customer> 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 DelCustumer = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  65. if (DelCustumer != null)
  66. {
  67. Editing = DelCustumer;
  68. _isAdd = false;
  69. _visible = true;
  70. }
  71. else
  72. {
  73. }
  74. _total = _Customers.Count;
  75. }
  76. private void Edit(int id)
  77. {
  78. Editing = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  79. if (Editing != null)
  80. {
  81. _isAdd = false;
  82. _visible = true;
  83. }
  84. else
  85. {
  86. }
  87. _total = _Customers.Count;
  88. }
  89. private void AddNew()
  90. {
  91. Editing = new entity.Customer();
  92. //_isAdd = true;
  93. _visible = true;
  94. }
  95. private async Task HandleOk(MouseEventArgs e)
  96. {
  97. //var data = await Http.PostAsJsonAsync<wispro.sp.entity.StaffGrade>($"http://localhost:39476/api/StaffGrade/Save", EditingStaff);
  98. //if (data.IsSuccessStatusCode)
  99. //{
  100. // ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  101. // await Task.Delay(1000);
  102. // if (result.Success)
  103. // {
  104. // await _message.Success("数据已保存!");
  105. // }
  106. // else
  107. // {
  108. // await _message.Error($"{result.ErrorMessage}");
  109. // }
  110. //}
  111. //else
  112. //{
  113. // await _message.Error($"请求发生错误 {data.StatusCode}");
  114. //}
  115. _visible = false;
  116. }
  117. private void HandleCancel(MouseEventArgs e)
  118. {
  119. _visible = false;
  120. }
  121. }
  122. }