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

146 lines
4.9 KiB
Objective-C
Executable File

//
// YYSetHostView.m
// SweetParty
//
// Created by bj_szd on 2023/12/25.
//
#import "YYSetHostView.h"
#import "YYSetHostCell.h"
@interface YYSetHostView () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSArray *hostArray;
@property (nonatomic, strong) NSArray *onlineArray;
@end
@implementation YYSetHostView
- (void)awakeFromNib {
[super awakeFromNib];
[self createUI];
}
- (void)createUI {
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
self.tableView.separatorStyle = NO;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerNib:[UINib nibWithNibName:@"YYSetHostCell" bundle:nil] forCellReuseIdentifier:@"YYSetHostCell"];
self.tableView.rowHeight = 72;
}
- (void)setViewModel:(RCMicRoomViewModel *)viewModel {
_viewModel = viewModel;
[self fetchData];
}
- (void)fetchData {
NSDictionary *params = @{@"rid":C_string(self.viewModel.roomInfo.roomId)};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room/get_room_host_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
NSDictionary *dataDict = responseDic[@"data"];
self.hostArray = [SPFocusFansModel mj_objectArrayWithKeyValuesArray:dataDict[@"room_host_list"]];
self.onlineArray = [SPFocusFansModel mj_objectArrayWithKeyValuesArray:dataDict[@"room_visitor_list"]];
[self.tableView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onDismiss:(id)sender {
[self removeFromSuperview];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
return self.hostArray.count;
}else {
return self.onlineArray.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YYSetHostCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YYSetHostCell" forIndexPath:indexPath];
cell.selectionStyle = NO;
WEAK_SELF
if (indexPath.section == 0) {
SPFocusFansModel *model = self.hostArray[indexPath.row];
cell.model = model;
// [cell.focusBtn setTitle:@"取消主持" forState:UIControlStateNormal];
// [cell.focusBtn setTitleColor:HEXCOLOR(0x999999) forState:UIControlStateNormal];
// cell.focusBtn.backgroundColor = HEXCOLORA(0xFFFFFF, 0.2);
[cell.focusBtn setImage:ImageNamed(@"room_alert_host_cancel") forState:(UIControlStateNormal)];
[cell.focusBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onHost:model isSet:NO];
} forControlEvents:UIControlEventTouchUpInside];
}else {
SPFocusFansModel *model = self.onlineArray[indexPath.row];
cell.model = model;
// [cell.focusBtn setTitle:@"添加主持" forState:UIControlStateNormal];
// [cell.focusBtn setTitleColor:HEXCOLOR(0xFFFFFF) forState:UIControlStateNormal];
// [cell.focusBtn styleGradiBlueColor];
[cell.focusBtn setImage:ImageNamed(@"room_alert_host_set") forState:(UIControlStateNormal)];
[cell.focusBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onHost:model isSet:YES];
} forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
- (void)onHost:(SPFocusFansModel *)model isSet:(BOOL)isSet {
NSDictionary *params = @{@"rid":C_string(self.viewModel.roomInfo.roomId), @"uid":model.uid};
NSString *urlStr = isSet ? @"/api/room/set_room_host" : @"/api/room/unset_room_host";
[[AFNetworkRequset shared] postRequestWithParams:params Path:urlStr Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
[self fetchData];
//设置主持人消息
[self.viewModel bj_sendHostChangeMessageTo:model.uid isAdmin:isSet];
} Failure:^(id _Nonnull errorData) {
}];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [ControlCreator createView:nil rect:CGRectMake(0, 0, ScreenViewWidth, 40) backguoundColor:nil];
UILabel *headerLB = [ControlCreator createLabel:headerView rect:CGRectMake(15, 10, ScreenViewWidth, 20) text:@"" font:YBMediumFont(14) color:kWhiteColor backguoundColor:[UIColor clearColor] align:NSTextAlignmentLeft lines:1];
if (section == 0) {
headerLB.text = @"已有主持";
}else {
headerLB.text = @"添加主持";
}
return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.00001;
}
@end