PersonalCard.razor.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using AI.Platform.Core.Dto.CardManagement;
  2. using AI.Platform.Core.Dto.RechargeRecords;
  3. using Microsoft.AspNetCore.Components;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Globalization;
  7. using System.Linq;
  8. using static AI.Platform.Page.Pages.Report.FuelTransactionReport;
  9. namespace AI.Platform.Page.Pages.CardManagement
  10. {
  11. public partial class PersonalCard : ComponentBase
  12. {
  13. protected FilterModel Filter { get; set; } = new();
  14. protected List<TransactionItem> TransactionData { get; set; } = new();
  15. protected List<RechargeRecordDto> rechargeRecordDtos { get; set; } = new();
  16. protected List<CardInfoDto> cardInfoDtos { get; set; } = new();
  17. protected bool Loading { get; set; }
  18. protected int TotalCount { get; set; }
  19. protected int CurrentPage { get; set; } = 1;
  20. protected int PageSize { get; set; } = 20;
  21. // ========== 选项数据 ==========
  22. protected List<string> DeviceOptions { get; set; } = new();
  23. protected List<string> PlateNumberOptions { get; set; } = new();
  24. protected List<string> OilTypeOptions { get; set; } = new();
  25. protected List<string> PaymentMethodOptions { get; set; } = new();
  26. protected List<string> PaymentStatusOptions { get; set; } = new();
  27. protected List<string> OrderStatusOptions { get; set; } = new();
  28. protected List<string> DriverOptions { get; set; } = new();
  29. protected override void OnInitialized()
  30. {
  31. base.OnInitialized();
  32. InitializeData();
  33. _ = LoadDataAsync();
  34. }
  35. // ========== 初始化方法 ==========
  36. private void InitializeData()
  37. {
  38. // 初始化选项数据
  39. DeviceOptions = new List<string> { "DEV001", "DEV002", "DEV003", "DEV004" };
  40. PlateNumberOptions = new List<string> { "粤ACD0045", "粤ACD0046", "粤ACD0047", "粤ACD0048" };
  41. OilTypeOptions = new List<string> { "92#", "95#", "0#" };
  42. PaymentMethodOptions = new List<string> { "微信支付", "支付宝", "现金" };
  43. PaymentStatusOptions = new List<string> { "true", "false" };
  44. OrderStatusOptions = new List<string> { "已完成", "进行中", "已取消" };
  45. DriverOptions = new List<string> { "张三", "李四", "王五" };
  46. // 设置默认时间范围(最近7天)
  47. Filter.StartTime = DateTime.Today.AddDays(-7);
  48. Filter.EndTime = DateTime.Today;
  49. }
  50. // ========== 数据操作 ==========
  51. // 重置筛选条件
  52. protected void ResetFilter()
  53. {
  54. Filter = new FilterModel
  55. {
  56. StartTime = DateTime.Today.AddDays(-7),
  57. EndTime = DateTime.Today
  58. };
  59. CurrentPage = 1;
  60. }
  61. // 加载数据
  62. protected async Task LoadDataAsync()
  63. {
  64. Loading = true;
  65. try
  66. {
  67. // 模拟API调用延迟
  68. await Task.Delay(300);
  69. // 生成模拟数据
  70. TransactionData = GenerateMockData();
  71. TotalCount = TransactionData.Count();
  72. }
  73. finally
  74. {
  75. Loading = false;
  76. StateHasChanged();
  77. }
  78. }
  79. // 生成模拟数据
  80. private List<TransactionItem> GenerateMockData()
  81. {
  82. var data = new List<TransactionItem>();
  83. var random = new Random();
  84. var startIndex = (CurrentPage - 1) * PageSize;
  85. CardInfoDto cardInfoDto = new CardInfoDto();
  86. //cardInfoDto.StationName = "测试站点";
  87. //cardInfoDto.CompanyName = "测试公司";
  88. //cardInfoDto.CardType = "公司卡";
  89. //cardInfoDto.Mobile = "17620434492";
  90. //cardInfoDto.CardNo = "12321412412312321";
  91. //cardInfoDto.AccountBalance = 2342.2M;
  92. //cardInfoDto.IssueTime = DateTime.Now;
  93. //cardInfoDto.LossTime = DateTime.Now;
  94. //cardInfoDto.Status = "正常";
  95. cardInfoDtos.Add(cardInfoDto);
  96. return data;
  97. }
  98. // ========== 格式化方法 ==========
  99. // 格式化货币显示
  100. protected string FormatCurrency(decimal? value)
  101. {
  102. if (value == null) return "-";
  103. return value.Value.ToString("C", CultureInfo.CreateSpecificCulture("zh-CN"));
  104. }
  105. // 格式化数字显示
  106. protected string FormatNumber(decimal? value)
  107. {
  108. if (value == null) return "-";
  109. return value.Value.ToString("N2", CultureInfo.CreateSpecificCulture("zh-CN"));
  110. }
  111. // 格式化日期时间
  112. protected string FormatDateTime(DateTime? value)
  113. {
  114. if (value == null) return "-";
  115. return value.Value.ToString("yyyy-MM-dd HH:mm:ss");
  116. }
  117. // 格式化支付状态
  118. protected string FormatPaymentStatus(bool? status)
  119. {
  120. if (status == null) return "-";
  121. return status.Value ? "成功" : "失败";
  122. }
  123. // 格式化订单状态
  124. protected string FormatOrderStatus(string status)
  125. {
  126. return string.IsNullOrEmpty(status) ? "-" : status;
  127. }
  128. // ========== 事件处理方法 ==========
  129. // 查询处理
  130. protected async Task HandleQuery()
  131. {
  132. CurrentPage = 1;
  133. await LoadDataAsync();
  134. }
  135. // 重置处理
  136. protected async Task HandleReset()
  137. {
  138. ResetFilter();
  139. await LoadDataAsync();
  140. }
  141. // 页码变化
  142. protected async Task OnPageChange(int page)
  143. {
  144. CurrentPage = page;
  145. await LoadDataAsync();
  146. }
  147. // 每页大小变化
  148. protected async Task OnPageSizeChange(int pageSize)
  149. {
  150. PageSize = pageSize;
  151. CurrentPage = 1;
  152. await LoadDataAsync();
  153. }
  154. }
  155. }