using AI.Platform.Core; using AI.Platform.Core.Dto.CardManagement; using AI.Platform.Core.Dto.RechargeRecords; using AI.Platform.Core.Entity.System.VehicleTerminal.BusinessUnitInfo; using AI.Platform.Core.Entity.System.VehicleTerminal.CardInfo; using AI.Platform.Core.Entity.System.VehicleTerminal.Company; using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.Company; using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.Driver; using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.ElectronicAccount; using ZhonTai.Admin.Contracts.Domain.VehicleTerminal.UserInfo; using static AI.Platform.Page.Pages.Report.FuelTransactionReport; namespace AI.Platform.Page.Pages.CardManagement { public partial class DriverCard : ComponentBase { [Inject] private SqlSugarRepository _CardInforepository { get; set; } [Inject] private SqlSugarRepository _Companyrepository { get; set; } [Inject] private SqlSugarRepository _Accountrepository { get; set; } [Inject] private SqlSugarRepository _UserInforepository { get; set; } [Inject] private SqlSugarRepository _UserCardRelationrepository { get; set; } [Inject] private SqlSugarRepository _CompanyCardRuleRepository { get; set; } protected FilterModel Filter { get; set; } = new(); protected List TransactionData { get; set; } = new(); protected List rechargeRecordDtos { get; set; } = new(); protected List cardInfoDtos { get; set; } = new(); protected bool Loading { get; set; } protected int TotalCount { get; set; } protected int CurrentPage { get; set; } = 1; protected int PageSize { get; set; } = 20; public string CardNo { get; set; } public string Mobile { get; set; } // ========== 选项数据 ========== protected List DeviceOptions { get; set; } = new(); protected List PlateNumberOptions { get; set; } = new(); protected List OilTypeOptions { get; set; } = new(); protected List PaymentMethodOptions { get; set; } = new(); protected List PaymentStatusOptions { get; set; } = new(); protected List OrderStatusOptions { get; set; } = new(); protected List DriverOptions { get; set; } = new(); protected override void OnInitialized() { base.OnInitialized(); InitializeData(); _ = LoadDataAsync(); } // ========== 初始化方法 ========== private void InitializeData() { // 初始化选项数据 DeviceOptions = new List { "DEV001", "DEV002", "DEV003", "DEV004" }; PlateNumberOptions = new List { "粤ACD0045", "粤ACD0046", "粤ACD0047", "粤ACD0048" }; OilTypeOptions = new List { "92#", "95#", "0#" }; PaymentMethodOptions = new List { "微信支付", "支付宝", "现金" }; PaymentStatusOptions = new List { "true", "false" }; OrderStatusOptions = new List { "已完成", "进行中", "已取消" }; DriverOptions = new List { "张三", "李四", "王五" }; // 设置默认时间范围(最近7天) Filter.StartTime = DateTime.Today.AddDays(-7); Filter.EndTime = DateTime.Today; } // ========== 数据操作 ========== // 重置筛选条件 protected void ResetFilter() { Filter = new FilterModel { StartTime = DateTime.Today.AddDays(-7), EndTime = DateTime.Today }; CurrentPage = 1; } // 加载数据 protected async Task LoadDataAsync() { Loading = true; try { // 模拟API调用延迟 await Task.Delay(300); // 生成模拟数据 TransactionData = await GenerateMockData(); TotalCount = TransactionData.Count(); // 模拟总记录数 } finally { Loading = false; StateHasChanged(); } } // 生成数据 private async Task> GenerateMockData() { cardInfoDtos = await _CardInforepository.AsQueryable() .LeftJoin((a, b) => a.IssueSiteId == b.Id) .LeftJoin((a, b, c) => a.AccountId == c.Id) .LeftJoin((a, b, c,d) => a.Id == d.CardId) .LeftJoin((a, b, c, d,e) => d.DriverId == e.Id) .Where((a, b, c, d, e) => a.CardType == 3 && (!string.IsNullOrEmpty(CardNo) ? a.CardNo == CardNo : true) && (!string.IsNullOrEmpty(Mobile) ? e.Phone == Mobile : true)) .Select((a, b, c, d, e) => new CardInfoDto { StationName = b.Name, CardNo =a.CardNo, CardType = "司机卡", Mobile = e.Phone, AccountBalance = c.Balance, IssueTime = a.IssueTime, Name = e.Name, Status = a.Status == 1 ? "正常" : a.Status == 2 ? "挂失" : a.Status == 3 ? "注销" : a.Status == 4 ? "冻结" : "未知" }) .ToListAsync(); return cardInfoDtos; } // ========== 格式化方法 ========== // 格式化货币显示 protected string FormatCurrency(decimal? value) { if (value == null) return "-"; return value.Value.ToString("C", CultureInfo.CreateSpecificCulture("zh-CN")); } // 格式化数字显示 protected string FormatNumber(decimal? value) { if (value == null) return "-"; return value.Value.ToString("N2", CultureInfo.CreateSpecificCulture("zh-CN")); } // 格式化日期时间 protected string FormatDateTime(DateTime? value) { if (value == null) return "-"; return value.Value.ToString("yyyy-MM-dd HH:mm:ss"); } // 格式化支付状态 protected string FormatPaymentStatus(bool? status) { if (status == null) return "-"; return status.Value ? "成功" : "失败"; } // 格式化订单状态 protected string FormatOrderStatus(string status) { return string.IsNullOrEmpty(status) ? "-" : status; } // ========== 事件处理方法 ========== // 查询处理 protected async Task HandleQuery() { CurrentPage = 1; await LoadDataAsync(); } // 重置处理 protected async Task HandleReset() { ResetFilter(); await LoadDataAsync(); } // 页码变化 protected async Task OnPageChange(int page) { CurrentPage = page; await LoadDataAsync(); } // 每页大小变化 protected async Task OnPageSizeChange(int pageSize) { PageSize = pageSize; CurrentPage = 1; await LoadDataAsync(); } } }