DriverCard.razor.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using AI.Platform.Core;
  2. using AI.Platform.Core.Dto.CardManagement;
  3. using AI.Platform.Core.Dto.RechargeRecords;
  4. using AI.Platform.Core.Entity.System.VehicleTerminal.BusinessUnitInfo;
  5. using AI.Platform.Core.Entity.System.VehicleTerminal.CardInfo;
  6. using AI.Platform.Core.Entity.System.VehicleTerminal.Company;
  7. using Microsoft.AspNetCore.Components;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Globalization;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.Company;
  14. using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.Driver;
  15. using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.ElectronicAccount;
  16. using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.UserInfo;
  17. using static AI.Platform.Page.Pages.Report.FuelTransactionReport;
  18. namespace AI.Platform.Page.Pages.CardManagement
  19. {
  20. public partial class DriverCard : ComponentBase
  21. {
  22. [Inject] private SqlSugarRepository<CardInfoEntity> _CardInforepository { get; set; }
  23. [Inject] private SqlSugarRepository<CompanyEntity> _Companyrepository { get; set; }
  24. [Inject] private SqlSugarRepository<ElectronicAccountEntity> _Accountrepository { get; set; }
  25. [Inject] private SqlSugarRepository<UserInfoEntity> _UserInforepository { get; set; }
  26. [Inject] private SqlSugarRepository<UserCardRelationEntity> _UserCardRelationrepository { get; set; }
  27. [Inject] private SqlSugarRepository<CompanyCardRuleEntity> _CompanyCardRuleRepository { get; set; }
  28. protected FilterModel Filter { get; set; } = new();
  29. protected List<CardInfoDto> TransactionData { get; set; } = new();
  30. protected List<RechargeRecordDto> rechargeRecordDtos { get; set; } = new();
  31. protected List<CardInfoDto> cardInfoDtos { get; set; } = new();
  32. protected bool Loading { get; set; }
  33. protected int TotalCount { get; set; }
  34. protected int CurrentPage { get; set; } = 1;
  35. protected int PageSize { get; set; } = 20;
  36. public string CardNo { get; set; }
  37. public string Mobile { get; set; }
  38. // ========== 选项数据 ==========
  39. protected List<string> DeviceOptions { get; set; } = new();
  40. protected List<string> PlateNumberOptions { get; set; } = new();
  41. protected List<string> OilTypeOptions { get; set; } = new();
  42. protected List<string> PaymentMethodOptions { get; set; } = new();
  43. protected List<string> PaymentStatusOptions { get; set; } = new();
  44. protected List<string> OrderStatusOptions { get; set; } = new();
  45. protected List<string> DriverOptions { get; set; } = new();
  46. protected override void OnInitialized()
  47. {
  48. base.OnInitialized();
  49. InitializeData();
  50. _ = LoadDataAsync();
  51. }
  52. // ========== 初始化方法 ==========
  53. private void InitializeData()
  54. {
  55. // 初始化选项数据
  56. DeviceOptions = new List<string> { "DEV001", "DEV002", "DEV003", "DEV004" };
  57. PlateNumberOptions = new List<string> { "粤ACD0045", "粤ACD0046", "粤ACD0047", "粤ACD0048" };
  58. OilTypeOptions = new List<string> { "92#", "95#", "0#" };
  59. PaymentMethodOptions = new List<string> { "微信支付", "支付宝", "现金" };
  60. PaymentStatusOptions = new List<string> { "true", "false" };
  61. OrderStatusOptions = new List<string> { "已完成", "进行中", "已取消" };
  62. DriverOptions = new List<string> { "张三", "李四", "王五" };
  63. // 设置默认时间范围(最近7天)
  64. Filter.StartTime = DateTime.Today.AddDays(-7);
  65. Filter.EndTime = DateTime.Today;
  66. }
  67. // ========== 数据操作 ==========
  68. // 重置筛选条件
  69. protected void ResetFilter()
  70. {
  71. Filter = new FilterModel
  72. {
  73. StartTime = DateTime.Today.AddDays(-7),
  74. EndTime = DateTime.Today
  75. };
  76. CurrentPage = 1;
  77. }
  78. // 加载数据
  79. protected async Task LoadDataAsync()
  80. {
  81. Loading = true;
  82. try
  83. {
  84. // 模拟API调用延迟
  85. await Task.Delay(300);
  86. // 生成模拟数据
  87. TransactionData = await GenerateMockData();
  88. TotalCount = TransactionData.Count(); // 模拟总记录数
  89. }
  90. finally
  91. {
  92. Loading = false;
  93. StateHasChanged();
  94. }
  95. }
  96. // 生成数据
  97. private async Task<List<CardInfoDto>> GenerateMockData()
  98. {
  99. cardInfoDtos = await _CardInforepository.AsQueryable()
  100. .LeftJoin<BusinessUnitInfoEntity>((a, b) => a.IssueSiteId == b.Id)
  101. .LeftJoin<ElectronicAccountEntity>((a, b, c) => a.AccountId == c.Id)
  102. .LeftJoin<EmployeeCardRelationEntity>((a, b, c,d) => a.Id == d.CardId)
  103. .LeftJoin<DriverEntity>((a, b, c, d,e) => d.DriverId == e.Id)
  104. .Where((a, b, c, d, e) => a.CardType == 3
  105. && (!string.IsNullOrEmpty(CardNo) ? a.CardNo == CardNo : true)
  106. && (!string.IsNullOrEmpty(Mobile) ? e.Phone == Mobile : true))
  107. .Select((a, b, c, d, e) => new CardInfoDto {
  108. StationName = b.Name,
  109. CardNo =a.CardNo,
  110. CardType = "司机卡",
  111. Mobile = e.Phone,
  112. AccountBalance = c.Balance,
  113. IssueTime = a.IssueTime,
  114. Name = e.Name,
  115. Status = a.Status == 1 ? "正常" : a.Status == 2 ? "挂失" : a.Status == 3 ? "注销" : a.Status == 4 ? "冻结" : "未知"
  116. })
  117. .ToListAsync();
  118. return cardInfoDtos;
  119. }
  120. // ========== 格式化方法 ==========
  121. // 格式化货币显示
  122. protected string FormatCurrency(decimal? value)
  123. {
  124. if (value == null) return "-";
  125. return value.Value.ToString("C", CultureInfo.CreateSpecificCulture("zh-CN"));
  126. }
  127. // 格式化数字显示
  128. protected string FormatNumber(decimal? value)
  129. {
  130. if (value == null) return "-";
  131. return value.Value.ToString("N2", CultureInfo.CreateSpecificCulture("zh-CN"));
  132. }
  133. // 格式化日期时间
  134. protected string FormatDateTime(DateTime? value)
  135. {
  136. if (value == null) return "-";
  137. return value.Value.ToString("yyyy-MM-dd HH:mm:ss");
  138. }
  139. // 格式化支付状态
  140. protected string FormatPaymentStatus(bool? status)
  141. {
  142. if (status == null) return "-";
  143. return status.Value ? "成功" : "失败";
  144. }
  145. // 格式化订单状态
  146. protected string FormatOrderStatus(string status)
  147. {
  148. return string.IsNullOrEmpty(status) ? "-" : status;
  149. }
  150. // ========== 事件处理方法 ==========
  151. // 查询处理
  152. protected async Task HandleQuery()
  153. {
  154. CurrentPage = 1;
  155. await LoadDataAsync();
  156. }
  157. // 重置处理
  158. protected async Task HandleReset()
  159. {
  160. ResetFilter();
  161. await LoadDataAsync();
  162. }
  163. // 页码变化
  164. protected async Task OnPageChange(int page)
  165. {
  166. CurrentPage = page;
  167. await LoadDataAsync();
  168. }
  169. // 每页大小变化
  170. protected async Task OnPageSizeChange(int pageSize)
  171. {
  172. PageSize = pageSize;
  173. CurrentPage = 1;
  174. await LoadDataAsync();
  175. }
  176. }
  177. }