| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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<CardInfoEntity> _CardInforepository { get; set; }
- [Inject] private SqlSugarRepository<CompanyEntity> _Companyrepository { get; set; }
- [Inject] private SqlSugarRepository<ElectronicAccountEntity> _Accountrepository { get; set; }
- [Inject] private SqlSugarRepository<UserInfoEntity> _UserInforepository { get; set; }
- [Inject] private SqlSugarRepository<UserCardRelationEntity> _UserCardRelationrepository { get; set; }
- [Inject] private SqlSugarRepository<CompanyCardRuleEntity> _CompanyCardRuleRepository { get; set; }
- protected FilterModel Filter { get; set; } = new();
- protected List<CardInfoDto> TransactionData { get; set; } = new();
- protected List<RechargeRecordDto> rechargeRecordDtos { get; set; } = new();
- protected List<CardInfoDto> 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<string> DeviceOptions { get; set; } = new();
- protected List<string> PlateNumberOptions { get; set; } = new();
- protected List<string> OilTypeOptions { get; set; } = new();
- protected List<string> PaymentMethodOptions { get; set; } = new();
- protected List<string> PaymentStatusOptions { get; set; } = new();
- protected List<string> OrderStatusOptions { get; set; } = new();
- protected List<string> DriverOptions { get; set; } = new();
- protected override void OnInitialized()
- {
- base.OnInitialized();
- InitializeData();
- _ = LoadDataAsync();
- }
- // ========== 初始化方法 ==========
- private void InitializeData()
- {
- // 初始化选项数据
- DeviceOptions = new List<string> { "DEV001", "DEV002", "DEV003", "DEV004" };
- PlateNumberOptions = new List<string> { "粤ACD0045", "粤ACD0046", "粤ACD0047", "粤ACD0048" };
- OilTypeOptions = new List<string> { "92#", "95#", "0#" };
- PaymentMethodOptions = new List<string> { "微信支付", "支付宝", "现金" };
- PaymentStatusOptions = new List<string> { "true", "false" };
- OrderStatusOptions = new List<string> { "已完成", "进行中", "已取消" };
- DriverOptions = new List<string> { "张三", "李四", "王五" };
- // 设置默认时间范围(最近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<List<CardInfoDto>> GenerateMockData()
- {
- cardInfoDtos = await _CardInforepository.AsQueryable()
- .LeftJoin<BusinessUnitInfoEntity>((a, b) => a.IssueSiteId == b.Id)
- .LeftJoin<ElectronicAccountEntity>((a, b, c) => a.AccountId == c.Id)
- .LeftJoin<EmployeeCardRelationEntity>((a, b, c,d) => a.Id == d.CardId)
- .LeftJoin<DriverEntity>((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();
- }
- }
- }
|