CustomerList.razor.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  26. {
  27. _loading = true;
  28. _Customers = await orgService.GetAllCustomer();
  29. //await System.Threading.Thread.Sleep();
  30. //List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  31. _loading = false;
  32. _total = _Customers.Count;
  33. }
  34. private void HandlePageChange(PaginationEventArgs args)
  35. {
  36. if (_pageIndex != args.Page)
  37. {
  38. _pageIndex = args.Page;
  39. }
  40. if (_pageSize != args.PageSize)
  41. {
  42. _pageSize = args.PageSize;
  43. }
  44. }
  45. Dictionary<string, object> OnRow(RowData<entity.Customer> row)
  46. {
  47. Dictionary<string, object> ret = new Dictionary<string, object>();
  48. ret.Add("id", row.Data.Id);
  49. ret.Add("onclick", ((Action)delegate
  50. {
  51. //_message.Info($"row {row.Data.Grade} was clicked");
  52. }));
  53. return ret;
  54. }
  55. public void RemoveSelection(int id)
  56. {
  57. //var selected = selectedRows.Where(x => x.Id != id);
  58. //selectedRows = selected;
  59. }
  60. private void Delete(int id)
  61. {
  62. var DelCustumer = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  63. if (DelCustumer != null)
  64. {
  65. Editing = DelCustumer;
  66. _isAdd = false;
  67. _visible = true;
  68. }
  69. else
  70. {
  71. }
  72. _total = _Customers.Count;
  73. }
  74. private void Edit(int id)
  75. {
  76. Editing = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  77. if (Editing != null)
  78. {
  79. _isAdd = false;
  80. _visible = true;
  81. }
  82. else
  83. {
  84. }
  85. _total = _Customers.Count;
  86. }
  87. private void AddNew()
  88. {
  89. Editing = new entity.Customer();
  90. //_isAdd = true;
  91. _visible = true;
  92. }
  93. private async Task HandleOk(MouseEventArgs e)
  94. {
  95. //var data = await Http.PostAsJsonAsync<wispro.sp.entity.StaffGrade>($"http://localhost:39476/api/StaffGrade/Save", EditingStaff);
  96. //if (data.IsSuccessStatusCode)
  97. //{
  98. // ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  99. // await Task.Delay(1000);
  100. // if (result.Success)
  101. // {
  102. // await _message.Success("数据已保存!");
  103. // }
  104. // else
  105. // {
  106. // await _message.Error($"{result.ErrorMessage}");
  107. // }
  108. //}
  109. //else
  110. //{
  111. // await _message.Error($"请求发生错误 {data.StatusCode}");
  112. //}
  113. _visible = false;
  114. }
  115. private void HandleCancel(MouseEventArgs e)
  116. {
  117. _visible = false;
  118. }
  119. }
  120. }