Files
yuyin_ios/SweetParty/主类/音悦新增/酒吧厅&新人厅/YYRoomChujiaAlert.m
2025-08-08 11:05:33 +08:00

115 lines
3.6 KiB
Objective-C
Executable File

//
// YYRoomChujiaAlert.m
// YaYin
//
// Created by bj_szd on 2023/7/12.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYRoomChujiaAlert.h"
#import "YYRoomChujiaCell.h"
@interface YYRoomChujiaAlert ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) NSInteger selectedIndex;
@end
@implementation YYRoomChujiaAlert
- (void)awakeFromNib {
[super awakeFromNib];
self.selectedIndex = -1;
[self createUI];
[self fetchData];
}
- (void)fetchData {
NSDictionary *params = @{};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/new_room/get_room_auction_price_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
self.dataArray = responseDic[@"data"];
[self.collectionView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)createUI {
[self.confirmBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-32*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, 44);
layout.minimumInteritemSpacing = 15;
layout.minimumLineSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"YYRoomChujiaCell" bundle:nil] forCellWithReuseIdentifier:@"YYRoomChujiaCell"];
}
- (IBAction)onConfirm:(id)sender {
if (self.selectedIndex == -1) {
[HelpPageDefine showMessage:@"请选择价格"];
return;
}
NSDictionary *dict = self.dataArray[self.selectedIndex];
NSDictionary *params = @{@"rid":C_string(self.rid), @"price":[dict safeStringForKey:@"price"]};
NSString *urlStr = @"/api/new_room/user_auction_price";
if (self.is_ktv) {
params = @{@"rid":C_string(self.rid), @"price":[dict safeStringForKey:@"price"], @"user_id":(self.ktvCurrentUid)};
urlStr = @"/api/ktv_room/user_auction_price";
}
[[AFNetworkRequset shared] postRequestWithParams:params Path:urlStr Loading:NO 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{
YYRoomChujiaCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYRoomChujiaCell" forIndexPath:indexPath];
NSDictionary *dict = self.dataArray[indexPath.row];
cell.coinLab.text = [dict safeStringForKey:@"price"];
if (self.selectedIndex == indexPath.row) {
cell.selImgV.image = ImageNamed(@"room_chujia_sel");
cell.coinLab.textColor = kBlackColor;
}else {
cell.selImgV.image = ImageNamed(@"room_chujia_nor");
cell.coinLab.textColor = kWhiteColor;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndex = indexPath.row;
[self.collectionView reloadData];
}
@end