CustomerList.razor.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using AntDesign;
  2. using AntDesign.TableModels;
  3. using Blazor.ECharts.Options.Enum;
  4. using Microsoft.AspNetCore.Components;
  5. using Microsoft.AspNetCore.Components.Web;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using wispro.sp.entity;
  11. using wispro.sp.web.Services;
  12. namespace wispro.sp.web.Pages
  13. {
  14. public partial class CustomerList
  15. {
  16. private List<entity.Customer> _Customers =new List<entity.Customer>();
  17. private List<entity.Staff> _Staffs = new List<entity.Staff>();
  18. IEnumerable<entity.Customer> selectedRows;
  19. ITable table;
  20. int _pageIndex = 1;
  21. int _pageSize = 10;
  22. int _total = 0;
  23. bool _loading = false;
  24. entity.Customer Editing = null;
  25. bool _visible = false;
  26. bool _isAdd = false;
  27. [Inject]OrganizationService orgService { get; set; }
  28. [Inject] protected IAuthService _authService { get; set; }
  29. [Inject] IUserService _UserService { get; set; }
  30. protected override async System.Threading.Tasks.Task OnInitializedAsync()
  31. {
  32. await _authService.CanVisitResource();
  33. _loading = true;
  34. _Customers = await orgService.GetAllCustomer();
  35. _Staffs = await _UserService.GetAll();
  36. //await System.Threading.Thread.Sleep();
  37. //List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");
  38. _loading = false;
  39. _total = _Customers.Count;
  40. }
  41. private void HandlePageChange(PaginationEventArgs args)
  42. {
  43. if (_pageIndex != args.Page)
  44. {
  45. _pageIndex = args.Page;
  46. }
  47. if (_pageSize != args.PageSize)
  48. {
  49. _pageSize = args.PageSize;
  50. }
  51. }
  52. Dictionary<string, object> OnRow(RowData<entity.Customer> row)
  53. {
  54. Dictionary<string, object> ret = new Dictionary<string, object>();
  55. ret.Add("id", row.Data.Id);
  56. ret.Add("onclick", ((Action)delegate
  57. {
  58. //_message.Info($"row {row.Data.Grade} was clicked");
  59. }));
  60. return ret;
  61. }
  62. public void RemoveSelection(int id)
  63. {
  64. //var selected = selectedRows.Where(x => x.Id != id);
  65. //selectedRows = selected;
  66. }
  67. private void Delete(int id)
  68. {
  69. var DelCustumer = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  70. if (DelCustumer != null)
  71. {
  72. Editing = DelCustumer;
  73. _isAdd = false;
  74. _visible = true;
  75. }
  76. else
  77. {
  78. }
  79. _total = _Customers.Count;
  80. }
  81. private void Edit(int id)
  82. {
  83. Editing = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();
  84. if (Editing != null)
  85. {
  86. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(Editing));
  87. _isAdd = false;
  88. _visible = true;
  89. }
  90. else
  91. {
  92. }
  93. _total = _Customers.Count;
  94. }
  95. private void AddNew()
  96. {
  97. Editing = new entity.Customer();
  98. //_isAdd = true;
  99. _visible = true;
  100. }
  101. private async Task HandleOk(MouseEventArgs e)
  102. {
  103. var data = await orgService.SaveCustomer(Editing); // Http.PostAsJsonAsync<wispro.sp.entity.Staff>($"http://localhost:39476/api/Staff/Save", EditingStaff);
  104. if (data.Success)
  105. {
  106. if (_isAdd)
  107. {
  108. _Customers = await orgService.GetAllCustomer();
  109. //table.ReloadData();
  110. StateHasChanged();
  111. }
  112. await _message.Success("数据已保存!");
  113. }
  114. else
  115. {
  116. await _message.Error($"{data.ErrorMessage}");
  117. }
  118. _visible = false;
  119. }
  120. private void HandleCancel(MouseEventArgs e)
  121. {
  122. _visible = false;
  123. }
  124. }
  125. }