123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- //
- // YOUPAIHRSearchResultVC.m
- // VQU
- //
- // Created by xiaohaoran on 2021/11/16.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIHRSearchResultVC.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAIHRSearchLiveRoomCell.h"
- #import "YOUPAIHRSearchModel.h"
- #import "YOUPAILZChatRoomPasswordWindow.h"
- #import "YOUPAILZChatRoomVC.h"
- #import "UIViewController+TFPresent.h"
- @interface YOUPAIHRSearchResultVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @property(nonatomic,strong)UITableView *tableView;
- @property (nonatomic, assign) NSInteger page;
- @end
- @implementation YOUPAIHRSearchResultVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- if (self.type ==1) {
- self.title = @"相关聊天室";
- }else{
- self.title = @"相关直播间";
- }
- [self tableView];
- @weakify(self);
- [self.tableView setRefreshHeaderWithBlock:^{
- @strongify(self);
- [self youpaifrequestRankListWithStatus:kRefreshHeader];
- }];
- [self.tableView.mj_header beginRefreshing];
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- @weakify(self);
- [self.tableView setRefreshFooter:hidden withBlock:^{
- @strongify(self);
- [self youpaifrequestRankListWithStatus:kRefreshFooter];
- }];
- }
- - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.page ++;
- }else{
- self.page = 1;
- }
- @weakify(self);
-
- NSString *typeUrl;
- if (self.type == 1) {
- typeUrl = ChatRoom_likeList;
- }else{
- typeUrl = ChatRoom_searchLive;
- }
- [LCHttpHelper requestWithURLString:typeUrl parameters:@{@"number":[NSString stringWithFormat:@"%d",15],@"page":@(self.page),@"keyword":self.keyword} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- [self.tableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [self.dataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
- NSMutableArray* modelArray = [talkDataModel mj_objectArrayWithKeyValuesArray:array];
- NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
- [self.dataSource addObjectsFromArray:tempArray];
- [self.tableView reloadData];
- NSInteger youpaiptotalPage = [data[@"guildMember"][@"total_page"] integerValue];
- [self youpaifrefreshFooterWithHidden:self.page >= youpaiptotalPage];
- if (self.dataSource.count != 0) {
- [self.tableView lz_hideEmptyView];
- }else{
- [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"没有搜到相关结果,换个词试试~"];
- }
- }
- } failure:^(NSError *error) {
- @strongify(self);
- [self.tableView endRefreshing:kRefreshAll];
- }];
- }
- #pragma mark UITableViewDelegate&UITableViewDataSource
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- talkDataModel *model = self.dataSource[indexPath.row];
- if (self.type == 1) {
- NSString *roomId = [NSString stringWithFormat:@"%@",@(model.youpaiproom_id)];
-
- if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
- [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
- return;
- }
- [self youpaifshowPasswordWindowWithRoomId:[NSString stringWithFormat:@"%ld",(long)model.youpaiproom_id] youpaipis_comein_room_hide:0];
- }
-
-
- }
- - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_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 youpaipis_comein_room_hide:youpaipis_comein_room_hide window:window];
- }];
- [self TFPresentVC:window completion:^{}];
- }else{
- [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:nil];
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- /// 加入语聊房
- /// @param pwd 密码
- /// @param roomId 房间号
- /// @param youpaipis_comein_room_hide 是否悄悄进房
- /// @param window 密码框
- - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{
- [ZCHUDHelper show];
- @weakify(self);
- [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(youpaipis_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 *youpaipchatroomModel = [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 = youpaipchatroomModel;
- [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];
- }];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- return 68;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return self.dataSource.count;
- }
- -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- NSString *CellIdentifier = @"HRSearchLiveRoomID";
- YOUPAIHRSearchLiveRoomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];;
- if (cell == nil) {
- cell = [[YOUPAIHRSearchLiveRoomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- cell.backgroundColor = LCBkgColor;
- talkDataModel *model = self.dataSource[indexPath.row];
- cell.youpaipmodel = model;
- cell.youpaiptype = self.type;
- return cell;
- }
- -(UITableView *)tableView{
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- [self.view addSubview:_tableView];
- [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(NavBarHeight);
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(-SafeHeight);
- }];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 15.0, *)) {
- _tableView.sectionHeaderTopPadding = 0;
- }
- }
-
- return _tableView;
- }
- -(NSMutableArray *)dataSource{
-
- if (_dataSource == nil) {
- _dataSource = [NSMutableArray new];
- }
- return _dataSource;
- }
- @end
|