188 lines
6.5 KiB
Objective-C
Executable File
188 lines
6.5 KiB
Objective-C
Executable File
//
|
|
// YYHomepageGiftVC.m
|
|
// SweetParty
|
|
//
|
|
// Created by bj_szd on 2023/12/21.
|
|
//
|
|
|
|
#import "YYHomepageGiftVC.h"
|
|
#import "SPHomepageGiftCell.h"
|
|
|
|
@interface YYHomepageGiftVC () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, JXCategoryViewDelegate>
|
|
|
|
@property (weak, nonatomic) IBOutlet UIImageView *avatarImgV;
|
|
@property (weak, nonatomic) IBOutlet UILabel *nicknameLab;
|
|
@property (weak, nonatomic) IBOutlet UIView *titleBgView;
|
|
@property (weak, nonatomic) IBOutlet UIView *bottomBgView;
|
|
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
|
|
|
|
@property (nonatomic, strong) NSArray *titles;
|
|
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
@property (nonatomic, assign) NSInteger page;
|
|
|
|
@property (nonatomic, assign) NSInteger currentIndex;
|
|
|
|
@end
|
|
|
|
@implementation YYHomepageGiftVC
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
// [self showNaviBarWithTitle:@"礼物墙"];
|
|
// self.naviView.backgroundColor = kClearColor;
|
|
|
|
self.titles = @[@"已点亮", @"未点亮"];
|
|
|
|
self.dataArray = [NSMutableArray arrayWithCapacity:0];
|
|
self.page = 1;
|
|
|
|
[self createUI];
|
|
|
|
[self fetchData];
|
|
}
|
|
|
|
- (void)fetchData {
|
|
NSString *urlStr = @"";
|
|
if (0 == self.currentIndex) {
|
|
urlStr = @"/api/user/get_user_illume_gift_wall";
|
|
}else {
|
|
urlStr = @"/api/user/get_user_unillume_gift_wall";
|
|
}
|
|
NSDictionary *params = @{@"user_id":C_string(self.model.uid), @"page":@(self.page), @"page_limit":@"1000"};
|
|
[AFNetworkRequset.shared postRequestWithParams:params Path:urlStr Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
|
|
if (self.page == 1) {
|
|
[self.dataArray removeAllObjects];
|
|
[self.collectionView reloadData];
|
|
}
|
|
[self endRefresh];
|
|
|
|
NSArray *arr = [SPHomepageGiftModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
|
|
[self.dataArray addObjectsFromArray:arr];
|
|
[self.collectionView reloadData];
|
|
|
|
} Failure:^(id _Nonnull errorData) {
|
|
[self endRefresh];
|
|
}];
|
|
}
|
|
|
|
- (void)createUI {
|
|
self.view.backgroundColor = kClearColor;
|
|
|
|
[self.titleBgView addSubview:self.categoryView];
|
|
|
|
[self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.centerY.mas_equalTo(0);
|
|
make.width.mas_equalTo(215);
|
|
make.height.mas_equalTo(32);
|
|
}];
|
|
|
|
[self.bottomBgView styleShadowWithRedius:10];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
CGFloat itemW = (ScreenWidth-30*2-15*2)/3;
|
|
layout.itemSize = CGSizeMake(itemW, 130);
|
|
layout.minimumInteritemSpacing = 0;
|
|
layout.minimumLineSpacing = 10;
|
|
layout.sectionInset = UIEdgeInsetsMake(15, 15, 0, 15);
|
|
|
|
_collectionView.collectionViewLayout = layout;
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"SPHomepageGiftCell" bundle:nil] forCellWithReuseIdentifier:@"SPHomepageGiftCell"];
|
|
|
|
[self.avatarImgV sd_setImageWithURL:[NSURL URLWithString:self.model.head_pic] placeholderImage:kDefaultUserIcon];
|
|
self.nicknameLab.text = self.model.nick_name;
|
|
|
|
//刷新加载
|
|
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshFetchData)];
|
|
self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(fetchMoreData)];
|
|
}
|
|
|
|
- (void)refreshFetchData {
|
|
self.page = 1;
|
|
[self fetchData];
|
|
}
|
|
|
|
- (void)fetchMoreData {
|
|
self.page ++;
|
|
[self fetchData];
|
|
}
|
|
|
|
- (void)endRefresh {
|
|
if ([self.collectionView.mj_header isRefreshing]) {
|
|
[self.collectionView.mj_header endRefreshing];
|
|
} else if ([self.collectionView.mj_footer isRefreshing]) {
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
}
|
|
}
|
|
|
|
#pragma mark -------- collectionView代理方法 ------
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
SPHomepageGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPHomepageGiftCell" forIndexPath:indexPath];
|
|
SPHomepageGiftModel *model = self.dataArray[indexPath.row];
|
|
cell.model = model;
|
|
|
|
if (0 == self.currentIndex) {
|
|
// cell.bgImgV.image = ImageNamed(@"homepage_gift_bg");
|
|
// cell.bgImgV.backgroundColor = HEXCOLOR(0xECD4FF);
|
|
cell.numBgView.hidden = cell.maxHeadImgV.hidden = NO;
|
|
cell.contentView.alpha = 1;
|
|
}else {
|
|
// cell.bgImgV.image = ImageNamed(@"homepage_gift_bg_gray");
|
|
// cell.bgImgV.backgroundColor = HEXCOLOR(0xFFFFFF);
|
|
cell.numBgView.hidden = cell.maxHeadImgV.hidden = YES;
|
|
cell.contentView.alpha = 1;
|
|
}
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
self.currentIndex = index;
|
|
[self refreshFetchData];
|
|
}
|
|
|
|
// 分页菜单视图
|
|
- (JXCategoryTitleView *)categoryView {
|
|
if (!_categoryView) {
|
|
_categoryView = [[JXCategoryTitleView alloc] init];
|
|
_categoryView.delegate = self;
|
|
_categoryView.titleFont = YBBoldFont(14);
|
|
_categoryView.titleSelectedFont = YBBoldFont(14);
|
|
_categoryView.titleColor = HEXCOLOR(0x999999);
|
|
_categoryView.titleSelectedColor = HEXCOLOR(0x333333);
|
|
_categoryView.cellSpacing = 64;
|
|
_categoryView.averageCellSpacingEnabled = NO;
|
|
_categoryView.contentEdgeInsetLeft = 32;
|
|
_categoryView.contentEdgeInsetRight = 32;
|
|
_categoryView.backgroundColor = HEXCOLORA(0xFFFFFF, 0.5);
|
|
_categoryView.layer.cornerRadius = 16;
|
|
_categoryView.layer.masksToBounds = YES;
|
|
|
|
_categoryView.titles = self.titles;
|
|
|
|
JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
|
|
backgroundView.indicatorWidth = 95;
|
|
backgroundView.indicatorHeight = 28;
|
|
backgroundView.indicatorCornerRadius = 14;
|
|
backgroundView.indicatorColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(120, 28) direction:FXGradientChangeDirectionHorizontal startColor:mainLightColor endColor:mainDeepColor];
|
|
_categoryView.indicators = @[backgroundView];
|
|
}
|
|
return _categoryView;
|
|
}
|
|
|
|
|
|
@end
|