Files
2025-08-08 11:05:33 +08:00

246 lines
8.9 KiB
Objective-C
Executable File

//
// YYRoomSettingVC.m
// SweetParty
//
// Created by bj_szd on 2023/12/20.
//
#import "YYRoomSettingVC.h"
#import "UIButton+BAKit.h"
#import "YYRoomSetPeopleCell.h"
#import "YYRoomNameAlert.h"
#import "YYRoomCoverAlert.h"
#import "YYRoomBgAlert.h"
#import "YYRoomPswAlert.h"
#import "YYRoomNoticeAlert.h"
#import "YYRoomSetBiliAlert.h"
#import "YYRoomTypeAlert.h"
@interface YYRoomSettingVC () <JXCategoryViewDelegate>
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) NSArray *btnImgsArr;
@property (nonatomic, strong) NSArray *btnTitlesArr;
@property (nonatomic, strong) YYRoomSetModel *model;
@property (nonatomic, assign) BOOL isSecondLoad;
@end
@implementation YYRoomSettingVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@"房间分成"];
[self createUI];
[self fetchRoomData];
[self fetchData];
}
- (void)fetchRoomData {
NSDictionary *params = @{@"rid":C_string(self.rid)};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room/get_room_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
self.model = [YYRoomSetModel mj_objectWithKeyValues:responseDic[@"data"]];
if (self.isSecondLoad) {
if (self.onUpdateInfoBlock) {
self.onUpdateInfoBlock(responseDic[@"data"]);
}
}
self.isSecondLoad = YES;
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)fetchData {
NSDictionary *params = @{@"rid":C_string(self.rid)};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room/get_room_host_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
[self.dataArray removeAllObjects];
[self.tableView reloadData];
NSArray *arr = [YYRoomSetPeopleModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
[self.dataArray addObjectsFromArray:arr];
[self.tableView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)createUI {
// self.titles = @[@"主持人"];
self.titles = @[@""];
///房间设置放到老的设置界面里面了,这边只保留比例设置
// self.btnImgsArr = @[@"room_set_name", @"room_set_cover", @"room_set_bg", @"room_set_psw", @"room_set_gonggao", @"room_set_type"];
// self.btnTitlesArr = @[@"房间名字", @"房间封面", @"房间背景", @"房间密码", @"房间公告", @"房间类型"];
// CGFloat btnW = ScreenWidth/5;
// CGFloat btnH = 80;
// for (NSInteger i = 0; i < self.btnTitlesArr.count; i++) {
// UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
// btn.tag = 100+i;
// [btn setTitle:self.btnTitlesArr[i] forState:UIControlStateNormal];
// btn.titleLabel.font = YBMediumFont(12);
// [btn setTitleColor:HEXCOLOR(0x333333) forState:UIControlStateNormal];
// [btn setImage:ImageNamed(self.btnImgsArr[i]) forState:UIControlStateNormal];
// [btn addTarget:self action:@selector(onBtnClick:) forControlEvents:UIControlEventTouchUpInside];
// btn.frame = CGRectMake(btnW*(i%5), yb_NavigationBar_H+17+btnH*(i/5), btnW, btnH);
// [self.view addSubview:btn];
// [btn ba_button_setButtonLayoutType:BAKit_ButtonLayoutTypeCenterImageTop padding:5];
// }
// UIView *lineV = [ControlCreator createView:self.view rect:CGRectMake(0, yb_NavigationBar_H+17+btnH*2, ScreenWidth, 4) backguoundColor:HEXCOLOR(0xF7F7F7)];
UIImageView *bgImgV = [[UIImageView alloc] initWithImage:ImageNamed(@"home_bg")];
[self.view addSubview:bgImgV];
[self.view sendSubviewToBack:bgImgV];
[bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.mas_equalTo(ScreenWidth/375*812);
}];
[self.view addSubview:self.categoryView];
[self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(lineV.mas_bottom);
make.top.mas_equalTo(yb_NavigationBar_H);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(44);
}];
[self.tableView registerNib:[UINib nibWithNibName:@"YYRoomSetPeopleCell" bundle:nil] forCellReuseIdentifier:@"YYRoomSetPeopleCell"];
self.tableView.rowHeight = 150;
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.categoryView);
make.left.right.bottom.mas_equalTo(0);
}];
}
- (void)onBtnClick:(UIButton *)btn {
if (self.model == nil) {
return;
}
NSString *title = self.btnTitlesArr[btn.tag-100];
if ([title isEqualToString:@"房间名字"]) {
YYRoomNameAlert *alert = LoadNib(@"YYRoomNameAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self fetchRoomData];
};
}else if ([title isEqualToString:@"房间封面"]) {
YYRoomCoverAlert *alert = LoadNib(@"YYRoomCoverAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self fetchRoomData];
};
}else if ([title isEqualToString:@"房间背景"]) {
YYRoomBgAlert *alert = LoadNib(@"YYRoomBgAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self fetchRoomData];
};
}else if ([title isEqualToString:@"房间密码"]) {
YYRoomPswAlert *alert = LoadNib(@"YYRoomPswAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self fetchRoomData];
};
}else if ([title isEqualToString:@"房间公告"]) {
YYRoomNoticeAlert *alert = LoadNib(@"YYRoomNoticeAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self fetchRoomData];
};
}else if ([title isEqualToString:@"房间类型"]) {
YYRoomTypeAlert *alert = LoadNib(@"YYRoomTypeAlert");
alert.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:alert];
alert.model = self.model;
alert.onCompleteBlock = ^{
[self.navigationController popViewControllerAnimated:YES];
};
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YYRoomSetPeopleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YYRoomSetPeopleCell" forIndexPath:indexPath];
cell.selectionStyle = NO;
YYRoomSetPeopleModel *model = self.dataArray[indexPath.row];
cell.model = model;
WEAK_SELF
[cell.settingBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onSettingBili:model];
} forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)onSettingBili:(YYRoomSetPeopleModel *)model {
YYRoomSetBiliAlert *view = LoadNib(@"YYRoomSetBiliAlert");
view.frame = [UIScreen mainScreen].bounds;
[KEYWINDOW addSubview:view];
view.currentRatio = model.ratio;
[view setOnCompleteBlock:^(NSInteger ratio) {
NSDictionary *params = @{@"rid":C_string(self.rid), @"uid":model.uid, @"ratio":@(ratio)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/room/update_room_host_ratio" Loading:NO Hud:YES Success:^(id _Nonnull responseDic) {
[self fetchData];
} Failure:^(id _Nonnull errorData) {
}];
}];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YYRoomSetPeopleModel *model = self.dataArray[indexPath.row];
[UIViewController goUserMainpageWith:model.uid withRid:@""];
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
}
// 分页菜单视图
- (JXCategoryTitleView *)categoryView {
if (!_categoryView) {
_categoryView = [[JXCategoryTitleView alloc] init];
_categoryView.delegate = self;
_categoryView.titleFont = YBMediumFont(14);
_categoryView.titleSelectedFont = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
_categoryView.titleColor = HEXCOLOR(0x666666);
_categoryView.titleSelectedColor = HEXCOLOR(0x333333);
_categoryView.cellSpacing = 36;
_categoryView.averageCellSpacingEnabled = NO;
_categoryView.contentEdgeInsetLeft = 15;
_categoryView.titles = self.titles;
}
return _categoryView;
}
@end