1
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user