YOUPAIHRChatRoomManageVC.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // YOUPAIHRChatRoomManageVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/8.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomManageVC.h"
  9. #import "YOUPAIHRChatRoomManageCell.h"
  10. #import "UIScrollView+LZRefresh.h"
  11. #import "YOUPAIHRChatRoomManageModel.h"
  12. #import "YOUPAILZChatRoomPasswordWindow.h"
  13. #import "YOUPAILZChatRoomVC.h"
  14. #import "UIViewController+TFPresent.h"
  15. @interface YOUPAIHRChatRoomManageVC ()<UITableViewDelegate,UITableViewDataSource>
  16. @property(nonatomic,strong)UITableView *youpaiptableView;
  17. @property (nonatomic, assign) NSInteger youpaippage;
  18. @property (nonatomic, strong) NSMutableArray *youpaipdataSource;
  19. @end
  20. @implementation YOUPAIHRChatRoomManageVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.title = @"房间管理";
  24. [self youpaiptableView];
  25. @weakify(self);
  26. [self.youpaiptableView setRefreshHeaderWithBlock:^{
  27. @strongify(self);
  28. [self youpaifrequestRankListWithStatus:kRefreshHeader];
  29. }];
  30. [self.youpaiptableView.mj_header beginRefreshing];
  31. }
  32. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  33. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  34. cell.userInteractionEnabled = NO;
  35. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  36. cell.userInteractionEnabled = YES;
  37. });
  38. YOUPAIHRChatRoomManageModel *model = self.youpaipdataSource[indexPath.row];
  39. NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
  40. if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqualToString:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
  41. [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
  42. return;
  43. }
  44. [self youpaifshowPasswordWindowWithRoomId:[NSString stringWithFormat:@"%ld",(long)model.youpaiproom_id] is_comein_room_hide:0];
  45. }
  46. - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId is_comein_room_hide:(NSInteger)is_comein_room_hide{
  47. @weakify(self);
  48. [LCHttpHelper requestWithURLString:GetRoomStatus parameters:@{@"room_id":roomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  49. @strongify(self);
  50. NSDictionary* dict = (NSDictionary*)responseObject;
  51. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  52. if (code==0) {
  53. NSDictionary *data = [dict objectForKey:@"data"];
  54. if ([[data objectForKey:@"pwd"] integerValue] == 1) { // 有密码
  55. YOUPAILZChatRoomPasswordWindow *window = [[YOUPAILZChatRoomPasswordWindow alloc] init];
  56. [window setYoupaippasswordBlock:^(NSString * _Nonnull password, YOUPAILZChatRoomPasswordWindow * _Nonnull window) {
  57. @strongify(self);
  58. [self youpaifgoChatRoomVCWithPwd:password RoomId:roomId is_comein_room_hide:is_comein_room_hide window:window];
  59. }];
  60. [self TFPresentVC:window completion:^{}];
  61. }else{
  62. [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId is_comein_room_hide:is_comein_room_hide window:nil];
  63. }
  64. }
  65. } failure:^(NSError *error) {
  66. }];
  67. }
  68. /// 加入语聊房
  69. /// @param pwd 密码
  70. /// @param roomId 房间号
  71. /// @param is_comein_room_hide 是否悄悄进房
  72. /// @param window 密码框
  73. - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId is_comein_room_hide:(NSInteger)is_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{
  74. [ZCHUDHelper show];
  75. @weakify(self);
  76. [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(is_comein_room_hide)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  77. [ZCHUDHelper dismiss];
  78. @strongify(self);
  79. NSDictionary* dict = (NSDictionary*)responseObject;
  80. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  81. if (code==0) {
  82. if (window != nil) {
  83. [window dismissViewControllerAnimated:YES completion:^{}];
  84. }
  85. [[YOUPAILZChatRoomManager shareManager] youpaifleaveChannel];
  86. YOUPAILZChatRoomModel *chatroomModel = [YOUPAILZChatRoomModel mj_objectWithKeyValues:dict[@"data"]];
  87. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  88. YOUPAILZChatRoomVC *vc = [[YOUPAILZChatRoomVC alloc] init];
  89. vc.youpaipchatroomModel = chatroomModel;
  90. [self.navigationController pushViewController:vc animated:YES];
  91. [YOUPAILZChatRoomManager shareManager].chatroomModel = vc.youpaipchatroomModel;
  92. [YOUPAILZChatRoomManager shareManager].chatroomController = vc;
  93. // });
  94. }else{
  95. if (window != nil) {
  96. [window youpaifshowHUDWithTitle:[dict objectForKey:@"message"]];
  97. }else{
  98. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  99. }
  100. }
  101. } failure:^(NSError *error) {
  102. [ZCHUDHelper dismiss];
  103. }];
  104. }
  105. /// 设置加载更多
  106. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  107. @weakify(self);
  108. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  109. @strongify(self);
  110. [self youpaifrequestRankListWithStatus:kRefreshFooter];
  111. }];
  112. }
  113. - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{
  114. if (status == kRefreshFooter) {
  115. self.youpaippage ++;
  116. }else{
  117. self.youpaippage = 1;
  118. }
  119. @weakify(self);
  120. [LCHttpHelper requestWithURLString:ChatRoom_talkManage parameters:@{@"page":@(self.youpaippage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  121. @strongify(self);
  122. [self.youpaiptableView endRefreshing:kRefreshAll];
  123. NSDictionary* dict = (NSDictionary*)responseObject;
  124. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  125. if (code == 0) {//成功
  126. if (status != kRefreshFooter) {
  127. [self.youpaipdataSource removeAllObjects];
  128. }
  129. NSDictionary *data = [dict objectForKey:@"data"];
  130. NSArray <YOUPAIHRChatRoomManageModel *>*list = [YOUPAIHRChatRoomManageModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  131. [self.youpaipdataSource addObjectsFromArray:list];
  132. [self.youpaiptableView reloadData];
  133. NSInteger totalPage = [data[@"data"][@"total_page"] integerValue];
  134. [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage];
  135. if (self.youpaipdataSource.count != 0) {
  136. [self.youpaiptableView lz_hideEmptyView];
  137. }else{
  138. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"];
  139. }
  140. }
  141. } failure:^(NSError *error) {
  142. @strongify(self);
  143. [self.youpaiptableView endRefreshing:kRefreshAll];
  144. }];
  145. }
  146. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  147. return 124;
  148. }
  149. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  150. return self.youpaipdataSource.count;
  151. }
  152. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  153. YOUPAIHRChatRoomManageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRChatRoomManageID" forIndexPath:indexPath];;
  154. if (cell == nil) {
  155. cell = [[YOUPAIHRChatRoomManageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRChatRoomManageID"];
  156. }
  157. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  158. cell.backgroundColor = LCBkgColor;
  159. YOUPAIHRChatRoomManageModel *model = self.youpaipdataSource[indexPath.row];
  160. cell.youpaipmodel =model;
  161. return cell;
  162. }
  163. -(UITableView *)youpaiptableView{
  164. if (_youpaiptableView == nil) {
  165. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  166. [self.view addSubview:_youpaiptableView];
  167. [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  168. make.top.mas_equalTo(NavBarHeight);
  169. make.left.mas_equalTo(0);
  170. make.right.mas_equalTo(0);
  171. make.bottom.mas_equalTo(-SafeHeight);
  172. }];
  173. _youpaiptableView.delegate = self;
  174. _youpaiptableView.dataSource = self;
  175. _youpaiptableView.backgroundColor = [UIColor clearColor];
  176. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  177. _youpaiptableView.showsVerticalScrollIndicator = NO;
  178. _youpaiptableView.showsHorizontalScrollIndicator = NO;
  179. if (@available(iOS 15.0, *)) {
  180. _youpaiptableView.sectionHeaderTopPadding = 0;
  181. }
  182. [_youpaiptableView registerClass:[YOUPAIHRChatRoomManageCell class] forCellReuseIdentifier:@"HRChatRoomManageID"];
  183. }
  184. return _youpaiptableView;
  185. }
  186. -(NSMutableArray *)youpaipdataSource{
  187. if (_youpaipdataSource == nil) {
  188. _youpaipdataSource = [NSMutableArray new];
  189. }
  190. return _youpaipdataSource;
  191. }
  192. @end