Files
yuyin_ios/SweetParty/主类/音悦新增/麦位弹框子列表/YYMicAlertGiftView.m
2025-08-08 11:05:33 +08:00

189 lines
6.3 KiB
Objective-C
Executable File

//
// YYMicAlertGiftView.m
// SweetParty
//
// Created by bj_szd on 2023/12/25.
//
#import "YYMicAlertGiftView.h"
#import "SPHomepageGiftCell.h"
@interface YYMicAlertGiftView () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, JXCategoryViewDelegate>
@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 YYMicAlertGiftView
- (void)awakeFromNib {
[super awakeFromNib];
self.titles = @[@"已点亮", @"未点亮"];
self.dataArray = [NSMutableArray arrayWithCapacity:0];
self.page = 1;
[self createUI];
}
- (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 {
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
[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);
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-15*2-15*2)/3;
layout.itemSize = CGSizeMake(itemW, 131);
layout.minimumInteritemSpacing = 15;
layout.minimumLineSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 34, 15);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"SPHomepageGiftCell" bundle:nil] forCellWithReuseIdentifier:@"SPHomepageGiftCell"];
//刷新加载
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];
}
}
- (void)setModel:(BJOperationAlertUserModel *)model {
_model = model;
[self.avatarImgV sd_setImageWithURL:[NSURL URLWithString:model.head_pic] placeholderImage:kDefaultUserIcon];
self.nicknameLab.text = model.nick_name;
[self fetchData];
}
- (IBAction)onDismiss:(id)sender {
[self removeFromSuperview];
}
#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];
cell.nameLab.textColor = cell.priceLab.textColor = kWhiteColor;
SPHomepageGiftModel *model = self.dataArray[indexPath.row];
cell.model = model;
if (0 == self.currentIndex) {
cell.bgImgV.image = ImageNamed(@"");
cell.bgImgV.backgroundColor = HEXCOLORA(0xFFFFFF, 0.06);
cell.numBgView.hidden = cell.maxHeadImgV.hidden = NO;
cell.contentView.alpha = 1;
}else {
cell.bgImgV.image = ImageNamed(@"");
cell.bgImgV.backgroundColor = HEXCOLORA(0xFFFFFF, 0.06);
cell.numBgView.hidden = cell.maxHeadImgV.hidden = YES;
cell.contentView.alpha = 0.6;
}
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(0xCCCCCC);
_categoryView.titleSelectedColor = HEXCOLOR(0x333333);
_categoryView.cellSpacing = 64;
_categoryView.averageCellSpacingEnabled = NO;
_categoryView.contentEdgeInsetLeft = 32;
_categoryView.contentEdgeInsetRight = 32;
_categoryView.backgroundColor = HEXCOLORA(0xFFFFFF, 0.1);
_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