// // YOUPAIHRChatRoomManageVC.m // VQU // // Created by xiaohaoran on 2021/11/8. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRChatRoomManageVC.h" #import "YOUPAIHRChatRoomManageCell.h" #import "UIScrollView+LZRefresh.h" #import "YOUPAIHRChatRoomManageModel.h" #import "YOUPAILZChatRoomPasswordWindow.h" #import "YOUPAILZChatRoomVC.h" #import "UIViewController+TFPresent.h" @interface YOUPAIHRChatRoomManageVC () @property(nonatomic,strong)UITableView *youpaiptableView; @property (nonatomic, assign) NSInteger youpaippage; @property (nonatomic, strong) NSMutableArray *youpaipdataSource; @end @implementation YOUPAIHRChatRoomManageVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"房间管理"; [self youpaiptableView]; @weakify(self); [self.youpaiptableView setRefreshHeaderWithBlock:^{ @strongify(self); [self youpaifrequestRankListWithStatus:kRefreshHeader]; }]; [self.youpaiptableView.mj_header beginRefreshing]; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.userInteractionEnabled = NO; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ cell.userInteractionEnabled = YES; }); YOUPAIHRChatRoomManageModel *model = self.youpaipdataSource[indexPath.row]; NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)]; if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqualToString:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) { [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom]; return; } [self youpaifshowPasswordWindowWithRoomId:[NSString stringWithFormat:@"%ld",(long)model.youpaiproom_id] is_comein_room_hide:0]; } - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId is_comein_room_hide:(NSInteger)is_comein_room_hide{ @weakify(self); [LCHttpHelper requestWithURLString:GetRoomStatus parameters:@{@"room_id":roomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { NSDictionary *data = [dict objectForKey:@"data"]; if ([[data objectForKey:@"pwd"] integerValue] == 1) { // 有密码 YOUPAILZChatRoomPasswordWindow *window = [[YOUPAILZChatRoomPasswordWindow alloc] init]; [window setYoupaippasswordBlock:^(NSString * _Nonnull password, YOUPAILZChatRoomPasswordWindow * _Nonnull window) { @strongify(self); [self youpaifgoChatRoomVCWithPwd:password RoomId:roomId is_comein_room_hide:is_comein_room_hide window:window]; }]; [self TFPresentVC:window completion:^{}]; }else{ [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId is_comein_room_hide:is_comein_room_hide window:nil]; } } } failure:^(NSError *error) { }]; } /// 加入语聊房 /// @param pwd 密码 /// @param roomId 房间号 /// @param is_comein_room_hide 是否悄悄进房 /// @param window 密码框 - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId is_comein_room_hide:(NSInteger)is_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{ [ZCHUDHelper show]; @weakify(self); [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(is_comein_room_hide)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { [ZCHUDHelper dismiss]; @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { if (window != nil) { [window dismissViewControllerAnimated:YES completion:^{}]; } [[YOUPAILZChatRoomManager shareManager] youpaifleaveChannel]; YOUPAILZChatRoomModel *chatroomModel = [YOUPAILZChatRoomModel mj_objectWithKeyValues:dict[@"data"]]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ YOUPAILZChatRoomVC *vc = [[YOUPAILZChatRoomVC alloc] init]; vc.youpaipchatroomModel = chatroomModel; [self.navigationController pushViewController:vc animated:YES]; [YOUPAILZChatRoomManager shareManager].chatroomModel = vc.youpaipchatroomModel; [YOUPAILZChatRoomManager shareManager].chatroomController = vc; // }); }else{ if (window != nil) { [window youpaifshowHUDWithTitle:[dict objectForKey:@"message"]]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } } failure:^(NSError *error) { [ZCHUDHelper dismiss]; }]; } /// 设置加载更多 - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{ @weakify(self); [self.youpaiptableView setRefreshFooter:hidden withBlock:^{ @strongify(self); [self youpaifrequestRankListWithStatus:kRefreshFooter]; }]; } - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{ if (status == kRefreshFooter) { self.youpaippage ++; }else{ self.youpaippage = 1; } @weakify(self); [LCHttpHelper requestWithURLString:ChatRoom_talkManage parameters:@{@"page":@(self.youpaippage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); [self.youpaiptableView endRefreshing:kRefreshAll]; NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 if (status != kRefreshFooter) { [self.youpaipdataSource removeAllObjects]; } NSDictionary *data = [dict objectForKey:@"data"]; NSArray *list = [YOUPAIHRChatRoomManageModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]]; [self.youpaipdataSource addObjectsFromArray:list]; [self.youpaiptableView reloadData]; NSInteger totalPage = [data[@"data"][@"total_page"] integerValue]; [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage]; if (self.youpaipdataSource.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } } failure:^(NSError *error) { @strongify(self); [self.youpaiptableView endRefreshing:kRefreshAll]; }]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 124; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRChatRoomManageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRChatRoomManageID" forIndexPath:indexPath];; if (cell == nil) { cell = [[YOUPAIHRChatRoomManageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRChatRoomManageID"]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.backgroundColor = LCBkgColor; YOUPAIHRChatRoomManageModel *model = self.youpaipdataSource[indexPath.row]; cell.youpaipmodel =model; return cell; } -(UITableView *)youpaiptableView{ if (_youpaiptableView == nil) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; [self.view addSubview:_youpaiptableView]; [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(NavBarHeight); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-SafeHeight); }]; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; _youpaiptableView.backgroundColor = [UIColor clearColor]; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.showsHorizontalScrollIndicator = NO; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } [_youpaiptableView registerClass:[YOUPAIHRChatRoomManageCell class] forCellReuseIdentifier:@"HRChatRoomManageID"]; } return _youpaiptableView; } -(NSMutableArray *)youpaipdataSource{ if (_youpaipdataSource == nil) { _youpaipdataSource = [NSMutableArray new]; } return _youpaipdataSource; } @end