using AIK.Common.Language; using AIK.Models.ApiModels.Integral; using AIK.Models.ApiModels.Record; using AIK.Service.IService; using AIK.ViewModels.UserKeyRecord; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace AIK.ViewModels.Integral { public partial class IntegralViewModel : ObservableObject { private readonly IAikDataService _aikDataService; private readonly IDataCacheService _dataCacheService; private readonly ILogger _logger; [ObservableProperty] private ObservableCollection _records = new(); [ObservableProperty] private bool isShowLoadMore = true; [ObservableProperty] private string notMoreTip = "没有更多记录了~"; public IntegralViewModel(IAikDataService aikDataService, IDataCacheService dataCacheService, ILogger logger) { _aikDataService = aikDataService; _dataCacheService = dataCacheService; _logger = logger; _ = LoadRecordsAsync(); } private async Task LoadRecordsAsync() { var token = await _dataCacheService.GetLatestUserTokenAsync(); if (!string.IsNullOrEmpty(token)) { var result = await _aikDataService.GetUserIntegralHistroy(token); if (result != null) { if (result.Total == result.Records.Count) { IsShowLoadMore = false; NotMoreTip = AiKLanguage.LanguageKey.GetValueOrDefault("NotMoreTips"); } Records = new ObservableCollection(result.Records); } } } } }