YOUPAIHRSearchResultVC.m 9.1 KB

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