YOUPAIHRChatRoomWindow.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // YOUPAIHRChatRoomWindow.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/6.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomWindow.h"
  9. #import "YOUPAIHRChatRoomWindowCell.h"
  10. #import "UIScrollView+LZRefresh.h"
  11. #import "YOUPAIHRChatRoomWindowModel.h"
  12. @interface YOUPAIHRChatRoomWindow ()<UITableViewDelegate,UITableViewDataSource>
  13. @property(nonatomic,strong)UITableView *youpaiptableView;
  14. @property (nonatomic, assign) NSInteger youpaippage;
  15. @property (nonatomic, strong) NSMutableArray *youpaipdataSource;
  16. @end
  17. @implementation YOUPAIHRChatRoomWindow
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.baseView.hidden = YES;
  21. [self youpaifsetupUI];
  22. @weakify(self);
  23. [self.youpaiptableView setRefreshHeaderWithBlock:^{
  24. @strongify(self);
  25. [self youpaifrequestRankListWithStatus:kRefreshHeader];
  26. }];
  27. [self.youpaiptableView.mj_header beginRefreshing];
  28. }
  29. /// 设置加载更多
  30. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  31. @weakify(self);
  32. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  33. @strongify(self);
  34. [self youpaifrequestRankListWithStatus:kRefreshFooter];
  35. }];
  36. }
  37. - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{
  38. if (status == kRefreshFooter) {
  39. self.youpaippage ++;
  40. }else{
  41. self.youpaippage = 1;
  42. }
  43. @weakify(self);
  44. [LCHttpHelper requestWithURLString:ChatRoom_guildRoom parameters:@{@"number":[NSString stringWithFormat:@"%d",15],@"page":@(self.youpaippage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  45. @strongify(self);
  46. [self.youpaiptableView endRefreshing:kRefreshAll];
  47. NSDictionary* dict = (NSDictionary*)responseObject;
  48. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  49. if (code == 0) {//成功
  50. if (status != kRefreshFooter) {
  51. [self.youpaipdataSource removeAllObjects];
  52. }
  53. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  54. NSMutableArray* modelArray = [YOUPAIHRChatRoomWindowModel mj_objectArrayWithKeyValuesArray:array];
  55. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  56. [self.youpaipdataSource addObjectsFromArray:tempArray];
  57. [self.youpaiptableView reloadData];
  58. NSInteger youpaiptotalPage = [dict[@"total_page"] integerValue];
  59. [self youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
  60. if (self.youpaipdataSource.count != 0) {
  61. [self.youpaiptableView lz_hideEmptyView];
  62. }else{
  63. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"];
  64. }
  65. }
  66. } failure:^(NSError *error) {
  67. @strongify(self);
  68. [self.youpaiptableView endRefreshing:kRefreshAll];
  69. }];
  70. }
  71. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  72. YOUPAIHRChatRoomWindowModel *model = self.youpaipdataSource[indexPath.row];
  73. if (self.youpaipdidSelectCellUserBlock) {
  74. self.youpaipdidSelectCellUserBlock(model.youpaiproom_id);
  75. }
  76. }
  77. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  78. return 68;
  79. }
  80. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  81. return self.youpaipdataSource.count;
  82. }
  83. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  84. YOUPAIHRChatRoomWindowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRChatRoomWindowID" forIndexPath:indexPath];;
  85. if (cell == nil) {
  86. cell = [[YOUPAIHRChatRoomWindowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRChatRoomWindowID"];
  87. }
  88. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  89. cell.backgroundColor = LCBkgColor;
  90. YOUPAIHRChatRoomWindowModel *model = self.youpaipdataSource[indexPath.row];
  91. cell.youpaipmodel = model;
  92. return cell;
  93. }
  94. -(void)youpaifsetupUI{
  95. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight*0.5)];
  96. bgV.backgroundColor = LCBkgColor;
  97. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  98. [self.view addSubview:bgV];
  99. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.left.right.bottom.offset(0.0f);
  101. make.height.offset(KScreenHeight*0.5);
  102. }];
  103. //youpaipheaderView
  104. UIView *youpaipheaderView = [UIView new];
  105. [bgV addSubview:youpaipheaderView];
  106. [youpaipheaderView mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.mas_equalTo(0);
  108. make.right.mas_equalTo(0);
  109. make.top.mas_equalTo(0);
  110. make.height.mas_equalTo(49);
  111. }];
  112. //查看全部
  113. UIButton *lookAllBtn = [UIButton new];
  114. [youpaipheaderView addSubview:lookAllBtn];
  115. [lookAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.right.mas_equalTo(-44);
  117. make.centerY.mas_equalTo(0);
  118. make.size.mas_equalTo(CGSizeMake(64, 21));
  119. }];
  120. [lookAllBtn setTitle:@"重置筛选" forState:UIControlStateNormal];
  121. [lookAllBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  122. lookAllBtn.titleLabel.font = LCBoldFont(12);
  123. [lookAllBtn addTarget:self action:@selector(youpaiflookAllBtnClick) forControlEvents:UIControlEventTouchUpInside];
  124. //title
  125. UILabel *titleLabel = [UILabel new];
  126. [youpaipheaderView addSubview:titleLabel];
  127. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.center.mas_equalTo(0);
  129. }];
  130. titleLabel.text = @"房间筛选";
  131. titleLabel.textColor = HexColorFromRGB(0xffffff);
  132. titleLabel.font = LCBoldFont(15);
  133. //分割线
  134. UIView *lineView = [UIView new];
  135. [youpaipheaderView addSubview:lineView];
  136. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.bottom.mas_equalTo(0);
  138. make.left.mas_equalTo(0);
  139. make.right.mas_equalTo(0);
  140. make.height.mas_equalTo(0.5);
  141. }];
  142. lineView.backgroundColor = HexColorFromRGB(0x4F4B5B);
  143. //tableView
  144. UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  145. self.youpaiptableView = tableView;
  146. [self.view addSubview:tableView];
  147. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.top.mas_equalTo(youpaipheaderView.mas_bottom);
  149. make.left.mas_equalTo(0);
  150. make.right.mas_equalTo(0);
  151. make.bottom.mas_equalTo(-SafeHeight);
  152. }];
  153. tableView.delegate = self;
  154. tableView.dataSource = self;
  155. tableView.backgroundColor = [UIColor clearColor];
  156. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  157. tableView.showsVerticalScrollIndicator = NO;
  158. tableView.showsHorizontalScrollIndicator = NO;
  159. if (@available(iOS 15.0, *)) {
  160. tableView.sectionHeaderTopPadding = 0;
  161. }
  162. [tableView registerClass:[YOUPAIHRChatRoomWindowCell class] forCellReuseIdentifier:@"HRChatRoomWindowID"];
  163. }
  164. -(void)youpaiflookAllBtnClick{
  165. if (self.youpaipdidResetBlock) {
  166. self.youpaipdidResetBlock();
  167. }
  168. }
  169. -(NSMutableArray *)youpaipdataSource{
  170. if(_youpaipdataSource == nil){
  171. _youpaipdataSource = [NSMutableArray new];
  172. }
  173. return _youpaipdataSource;
  174. }
  175. @end