MOInviteTableView.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // MOInviteTableView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/8.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOInviteTableView.h"
  10. #import "MOInviteTableViewCell.h"
  11. @interface MOInviteTableView ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *dataArr;
  14. /** 没有更多的数据视图 */
  15. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  16. @property (nonatomic, copy) NSString *next;
  17. @property (nonatomic, strong) NSMutableArray *inviteArr;
  18. @end
  19. @implementation MOInviteTableView
  20. - (instancetype)init{
  21. self = [super init];
  22. if (self)
  23. {
  24. [self setupUI];
  25. }
  26. return self;
  27. }
  28. - (void)setupUI{
  29. [self addSubview:self.tableView];
  30. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.left.right.bottom.equalTo(self);
  32. }];
  33. self.next = @"";
  34. }
  35. #pragma mark - JXCategoryListContentViewDelegate
  36. - (void)listWillAppear{
  37. if(self.dataArr.count == 0){
  38. [self getFirstHttpData];
  39. }
  40. }
  41. - (void)getFirstHttpData{
  42. self.next = @"";
  43. NSString *roomId = self.roomId;
  44. if(roomId.length == 0){
  45. return;
  46. }
  47. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  48. NSDictionary *baseDict = @{@"page":basePage,
  49. @"relation":@(self.relation),
  50. @"roomId":roomId};
  51. [self toGetLinkMicListDataWith:baseDict];
  52. }
  53. - (void)toGetLinkMicListDataWith:(NSDictionary *)dict{
  54. WEAKSELF
  55. [kHttpManager toGetTheLinkMicInviteListDataWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  56. __strong typeof(weakSelf) self = weakSelf;
  57. [self.tableView.mj_header endRefreshing];
  58. [self.tableView.mj_footer endRefreshing];
  59. if(kCode_Success){
  60. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  61. MOPkInviteData *personModel = [MOPkInviteData modelObjectWithDictionary:data[@"data"]];
  62. if(personModel.next == nil || personModel.next.length == 0){
  63. if(self.next == nil || self.next.length == 0){
  64. //第一页
  65. self.dataArr = [personModel.pkUserList mutableCopy];
  66. }
  67. else{
  68. //最后一页
  69. [self.dataArr addObjectsFromArray:personModel.pkUserList];
  70. }
  71. self.next = @"";
  72. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  73. }
  74. else{
  75. self.next = personModel.next;
  76. [self.dataArr addObjectsFromArray:personModel.pkUserList];
  77. }
  78. [self.tableView reloadData];
  79. self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  80. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  81. }
  82. else{
  83. kShowNetError(data)
  84. }
  85. }];
  86. }
  87. - (UIView *)listView{
  88. return self;
  89. }
  90. #pragma mark - UITableViewDelegate,UITableViewDataSource
  91. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  92. return 1;
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  95. return self.dataArr.count;
  96. }
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  98. WEAKSELF
  99. MOPkUserList *model = self.dataArr[indexPath.row];
  100. MOInviteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MOInviteTableViewCell_ID];
  101. cell.roomId = self.roomId;
  102. cell.camera = self.camera;
  103. cell.cellModel = model;
  104. cell.inviteActionBlock = ^(MOPkUserList * _Nonnull cellModel) {
  105. for (MOPkUserList *object in weakSelf.dataArr) {
  106. if([object.userProfile.id isEqualToString:cellModel.userProfile.id]){
  107. object.isSelect = !object.isSelect;
  108. break;
  109. }
  110. }
  111. [weakSelf.tableView reloadData];
  112. };
  113. return cell;
  114. }
  115. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  116. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  117. }
  118. #pragma mark - Lazy
  119. - (UITableView *)tableView{
  120. if (!_tableView)
  121. {
  122. _tableView= [[UITableView alloc] init];
  123. if (@available(iOS 11.0, *))
  124. {
  125. _tableView.estimatedRowHeight = 0;
  126. _tableView.estimatedSectionFooterHeight = 0;
  127. _tableView.estimatedSectionHeaderHeight = 0;
  128. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  129. }
  130. //iOS15适配
  131. if (@available(iOS 15.0, *))
  132. {
  133. self.tableView.sectionHeaderTopPadding = 0;
  134. }
  135. _tableView.backgroundColor = [UIColor whiteColor];
  136. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  137. _tableView.dataSource = self;
  138. _tableView.delegate = self;
  139. _tableView.showsVerticalScrollIndicator = NO;
  140. _tableView.showsHorizontalScrollIndicator = NO;
  141. _tableView.rowHeight = 50.0;
  142. [_tableView registerNib:[UINib nibWithNibName:@"MOInviteTableViewCell" bundle:nil] forCellReuseIdentifier:MOInviteTableViewCell_ID];
  143. _tableView.backgroundView = self.noMoreDataView;
  144. WEAKSELF
  145. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  146. [weakSelf getFirstHttpData];
  147. }];
  148. header.lastUpdatedTimeLabel.hidden = YES;
  149. header.stateLabel.hidden = YES;
  150. _tableView.mj_header = header;
  151. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  152. NSString *roomId = weakSelf.roomId;
  153. if(roomId.length == 0){
  154. return;
  155. }
  156. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  157. NSDictionary *baseDict = @{@"page":basePage,
  158. @"relation":@(weakSelf.relation),
  159. @"roomId":roomId};
  160. [weakSelf toGetLinkMicListDataWith:baseDict];
  161. }];
  162. _tableView.mj_footer.hidden = YES;
  163. }
  164. return _tableView;
  165. }
  166. - (NSMutableArray *)dataArr{
  167. if(!_dataArr){
  168. _dataArr = [NSMutableArray array];
  169. }
  170. return _dataArr;
  171. }
  172. - (MONoMoreDataView *)noMoreDataView{
  173. if(!_noMoreDataView){
  174. _noMoreDataView = [MONoMoreDataView new];
  175. }
  176. return _noMoreDataView;
  177. }
  178. - (NSMutableArray *)inviteArr{
  179. if(!_inviteArr){
  180. _inviteArr = [NSMutableArray array];
  181. }
  182. return _inviteArr;
  183. }
  184. @end