Files
yuyin_ios/SweetParty/主类/音悦新增/申请上麦/YYApplyUpGiftAlert.m

122 lines
3.7 KiB
Mathematica
Raw Normal View History

2025-08-08 11:05:33 +08:00
//
// YYApplyUpGiftAlert.m
// YaYin
//
// Created by bj_szd on 2023/7/12.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYApplyUpGiftAlert.h"
#import "BJGiftItemCell.h"
#import "HLHorizontalPageLayout.h"
#import "BJRoomGiftModel.h"
@interface YYApplyUpGiftAlert ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, copy) NSString *rid;
@end
@implementation YYApplyUpGiftAlert
- (void)awakeFromNib {
[super awakeFromNib];
self.selectedIndex = -1;
[self createUI];
[self fetchGiftData];
}
- (void)fetchGiftData {
NSDictionary *params = @{@"page":@"1", @"page_limit":@"1000"};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/room_micro/get_help_gift_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
NSArray *arr = [BJRoomGiftModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
self.dataArray = arr;
[self.collectionView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)createUI {
[self.confirmBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-30*2, 44)];
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-15*2-15*2)/3;
layout.itemSize = CGSizeMake(itemW, 126);
layout.minimumInteritemSpacing = 15;
layout.minimumLineSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[BJGiftItemCell class] forCellWithReuseIdentifier:@"BJGiftItemCell"];
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.pagingEnabled = YES;
_collectionView.multipleTouchEnabled = NO;
}
- (void)onShowWith:(NSString *)rid {
self.rid = rid;
[KEYWINDOW addSubview:self];
}
- (IBAction)onConfirm:(id)sender {
if (self.selectedIndex == -1) {
[HelpPageDefine showMessage:@"请选择礼物"];
return;
}
BJRoomGiftModel *model = self.dataArray[self.selectedIndex];
NSDictionary *params = @{@"rid":C_string(self.rid), @"gid":model.gid};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/room_micro/operate_room_help_gift" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
[self removeFromSuperview];
} Failure:^(id _Nonnull errorData) {
}];
}
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
BJGiftItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BJGiftItemCell" forIndexPath:indexPath];
BJRoomGiftModel *model = self.dataArray[indexPath.row];
// cell.model = model;
[cell configApplyupMicModel:model];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
BJRoomGiftModel *model = self.dataArray[indexPath.row];
self.selectedIndex = indexPath.row;
for (BJRoomGiftModel *model in self.dataArray) {
model.isItemSelected = NO;
}
model.isItemSelected = YES;
[self.collectionView reloadData];
}
@end