// // YOUPAIHRChatRoomWindow.m // VQU // // Created by xiaohaoran on 2021/11/6. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRChatRoomWindow.h" #import "YOUPAIHRChatRoomWindowCell.h" #import "UIScrollView+LZRefresh.h" #import "YOUPAIHRChatRoomWindowModel.h" @interface YOUPAIHRChatRoomWindow () @property(nonatomic,strong)UITableView *youpaiptableView; @property (nonatomic, assign) NSInteger youpaippage; @property (nonatomic, strong) NSMutableArray *youpaipdataSource; @end @implementation YOUPAIHRChatRoomWindow - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [self youpaifsetupUI]; @weakify(self); [self.youpaiptableView setRefreshHeaderWithBlock:^{ @strongify(self); [self youpaifrequestRankListWithStatus:kRefreshHeader]; }]; [self.youpaiptableView.mj_header beginRefreshing]; } /// 设置加载更多 - (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_guildRoom parameters:@{@"number":[NSString stringWithFormat:@"%d",15],@"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]; } NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAIHRChatRoomWindowModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; [self.youpaipdataSource addObjectsFromArray:tempArray]; [self.youpaiptableView reloadData]; NSInteger youpaiptotalPage = [dict[@"total_page"] integerValue]; [self youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage]; 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]; }]; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRChatRoomWindowModel *model = self.youpaipdataSource[indexPath.row]; if (self.youpaipdidSelectCellUserBlock) { self.youpaipdidSelectCellUserBlock(model.youpaiproom_id); } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 68; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRChatRoomWindowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRChatRoomWindowID" forIndexPath:indexPath];; if (cell == nil) { cell = [[YOUPAIHRChatRoomWindowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRChatRoomWindowID"]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.backgroundColor = LCBkgColor; YOUPAIHRChatRoomWindowModel *model = self.youpaipdataSource[indexPath.row]; cell.youpaipmodel = model; return cell; } -(void)youpaifsetupUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight*0.5)]; bgV.backgroundColor = LCBkgColor; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(KScreenHeight*0.5); }]; //youpaipheaderView UIView *youpaipheaderView = [UIView new]; [bgV addSubview:youpaipheaderView]; [youpaipheaderView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(49); }]; //查看全部 UIButton *lookAllBtn = [UIButton new]; [youpaipheaderView addSubview:lookAllBtn]; [lookAllBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-44); make.centerY.mas_equalTo(0); make.size.mas_equalTo(CGSizeMake(64, 21)); }]; [lookAllBtn setTitle:@"重置筛选" forState:UIControlStateNormal]; [lookAllBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; lookAllBtn.titleLabel.font = LCBoldFont(12); [lookAllBtn addTarget:self action:@selector(youpaiflookAllBtnClick) forControlEvents:UIControlEventTouchUpInside]; //title UILabel *titleLabel = [UILabel new]; [youpaipheaderView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(0); }]; titleLabel.text = @"房间筛选"; titleLabel.textColor = HexColorFromRGB(0xffffff); titleLabel.font = LCBoldFont(15); //分割线 UIView *lineView = [UIView new]; [youpaipheaderView addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(0.5); }]; lineView.backgroundColor = HexColorFromRGB(0x4F4B5B); //tableView UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; self.youpaiptableView = tableView; [self.view addSubview:tableView]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(youpaipheaderView.mas_bottom); 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; } [tableView registerClass:[YOUPAIHRChatRoomWindowCell class] forCellReuseIdentifier:@"HRChatRoomWindowID"]; } -(void)youpaiflookAllBtnClick{ if (self.youpaipdidResetBlock) { self.youpaipdidResetBlock(); } } -(NSMutableArray *)youpaipdataSource{ if(_youpaipdataSource == nil){ _youpaipdataSource = [NSMutableArray new]; } return _youpaipdataSource; } @end