This commit is contained in:
2025-12-11 17:51:00 +08:00
parent 58da905ade
commit 111fe42782
5 changed files with 71 additions and 25 deletions

View File

@@ -279,7 +279,7 @@ static const CGFloat JXheightForHeaderInSection = 50;
[KBHUD show];
}
__weak typeof(self) weakSelf = self;
[self.shopVM fetchWalletBalanceWithCompletion:^(NSNumber * _Nullable balance, NSError * _Nullable error) {
[self.shopVM fetchWalletBalanceWithCompletion:^(NSString * _Nullable balance, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (showHUD) {
[KBHUD dismiss];
@@ -289,9 +289,9 @@ static const CGFloat JXheightForHeaderInSection = 50;
[KBHUD showInfo:msg];
return;
}
double amountValue = balance.doubleValue;
NSString *amountString = [NSString stringWithFormat:@"%.2f", amountValue];
[weakSelf.userHeaderView updatePoints:amountString];
// double amountValue = balance.doubleValue;
// NSString *amountString = [NSString stringWithFormat:@"%.2f", amountValue];
[weakSelf.userHeaderView updatePoints:balance];
});
}];
}

View File

@@ -13,6 +13,7 @@
#import "KBSkinBottomActionView.h"
#import "KBShopVM.h"
#import "KBShopThemeTagModel.h"
#import "KBShopThemeModel.h"
#import "KBHUD.h"
#import "KBSkinService.h"
@@ -33,7 +34,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
@property (nonatomic, strong) UICollectionView *collectionView; //
@property (nonatomic, strong) KBSkinBottomActionView *bottomBar; //
@property (nonatomic, copy) NSArray<NSString *> *tags; //
@property (nonatomic, copy) NSArray<NSDictionary *> *gridData; //
@property (nonatomic, copy) NSArray<KBShopThemeModel *> *recommendedThemes; //
@property (nonatomic, strong) KBShopVM *shopVM;
@property (nonatomic, strong, nullable) KBShopThemeDetailModel *detailModel;
//@property (nonatomic, assign) BOOL isProcessingAction;
@@ -46,11 +47,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
self.view.backgroundColor = [UIColor whiteColor];
self.tags = @[];
self.gridData = @[
@{ @"title": @"Dopamine" }, @{ @"title": @"Dopamine" },
@{ @"title": @"Dopamine" }, @{ @"title": @"Dopamine" },
@{ @"title": @"Dopamine" }, @{ @"title": @"Dopamine" },
];
self.recommendedThemes = @[];
// 1.
[self.view addSubview:self.collectionView];
@@ -74,6 +71,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
[self updateBottomBarAppearance];
[self fetchThemeDetailIfNeeded];
[self fetchRecommendedThemes];
}
#pragma mark - UICollectionView DataSource
@@ -87,7 +85,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
case KBSkinDetailSectionHeader: return 1; //
case KBSkinDetailSectionTags: return self.tags.count > 0 ? 1 : 0;
case KBSkinDetailSectionTitle: return 1; //
case KBSkinDetailSectionGrid: return self.gridData.count; // 2
case KBSkinDetailSectionGrid: return self.recommendedThemes.count; // 2
}
return 0;
}
@@ -111,8 +109,11 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
}
case KBSkinDetailSectionGrid: {
KBSkinCardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kGridCellId forIndexPath:indexPath];
NSDictionary *d = self.gridData[indexPath.item];
[cell configWithTitle:d[@"title"] imageURL:nil price:@"20"];
KBShopThemeModel *model = self.recommendedThemes[indexPath.item];
NSString *priceText = [self priceTextForTheme:model];
[cell configWithTitle:model.themeName ?: @""
imageURL:model.themePreviewImageUrl
price:priceText];
return cell;
}
}
@@ -330,4 +331,31 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
return _shopVM;
}
#pragma mark - Data
- (void)fetchRecommendedThemes {
__weak typeof(self) weakSelf = self;
[self.shopVM fetchRecommendedThemesWithCompletion:^(NSArray<KBShopThemeModel *> * _Nullable themes, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"[KBSkinDetailVC] fetch recommended failed: %@", error);
return;
}
weakSelf.recommendedThemes = themes ?: @[];
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:KBSkinDetailSectionGrid];
[weakSelf.collectionView reloadSections:sections];
});
}];
}
- (NSString *)priceTextForTheme:(KBShopThemeModel *)model {
// if (model.isFree) {
// return KBLocalized(@"Free");
// }
if (model.themePrice > 0.0) {
return [NSString stringWithFormat:@"%.2f", model.themePrice];
}
return @"0";
}
@end

View File

@@ -19,7 +19,7 @@ typedef void(^KBShopStylesCompletion)(NSArray<KBShopStyleModel *> *_Nullable sty
NSError *_Nullable error);
typedef void(^KBShopThemesCompletion)(NSArray<KBShopThemeModel *> *_Nullable themes,
NSError *_Nullable error);
typedef void(^KBShopBalanceCompletion)(NSNumber *_Nullable balance,
typedef void(^KBShopBalanceCompletion)(NSString *_Nullable balance,
NSError *_Nullable error);
typedef void(^KBShopDetailCompletion)(KBShopThemeDetailModel *_Nullable detail,
NSError *_Nullable error);
@@ -53,6 +53,9 @@ typedef void(^KBShopDownloadInfoCompletion)(NSDictionary *_Nullable info,
- (void)fetchThemeDownloadInfoWithId:(nullable NSString *)themeId
completion:(KBShopDownloadInfoCompletion)completion;
/// 推荐主题列表(用于皮肤详情页底部网格)
- (void)fetchRecommendedThemesWithCompletion:(KBShopThemesCompletion)completion;
@end
NS_ASSUME_NONNULL_END

View File

@@ -100,17 +100,9 @@
if (completion) completion(nil, [self kb_invalidResponseError]);
return;
}
id balanceValue = dataObj[@"balance"];
NSNumber *balanceNumber = nil;
if ([balanceValue isKindOfClass:[NSNumber class]]) {
balanceNumber = balanceValue;
} else if ([balanceValue isKindOfClass:[NSString class]]) {
balanceNumber = @([(NSString *)balanceValue doubleValue]);
}
if (!balanceNumber) {
balanceNumber = @(0);
}
if (completion) completion(balanceNumber, nil);
NSString * balanceValue = dataObj[@"balanceDisplay"];
if (completion) completion(balanceValue, nil);
}];
}
@@ -187,6 +179,28 @@
}];
}
- (void)fetchRecommendedThemesWithCompletion:(KBShopThemesCompletion)completion {
[[KBNetworkManager shared] GET:API_THEME_RECOMMENDED
parameters:nil
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary * _Nullable json,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
if (error) {
if (completion) completion(nil, error);
return;
}
id dataObj = json[KBData] ?: json[@"data"];
if (![dataObj isKindOfClass:[NSArray class]]) {
if (completion) completion(nil, [self kb_invalidResponseError]);
return;
}
NSArray<KBShopThemeModel *> *list = [KBShopThemeModel mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
if (completion) completion(list, nil);
}];
}
- (id)kb_themeIdParamFromString:(NSString *)themeId {
if (themeId.length == 0) { return @""; }
NSNumberFormatter *formatter = [NSNumberFormatter new];