MOApplicationTableView.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // MOApplicationTableView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/9.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOApplicationTableView.h"
  10. #import "MOApplicationTableViewCell.h"
  11. @interface MOApplicationTableView ()<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. @end
  18. @implementation MOApplicationTableView
  19. - (instancetype)init{
  20. self = [super init];
  21. if (self)
  22. {
  23. [self setupUI];
  24. }
  25. return self;
  26. }
  27. - (void)setupUI{
  28. [self addSubview:self.tableView];
  29. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.top.left.right.bottom.equalTo(self);
  31. }];
  32. self.next = @"";
  33. }
  34. #pragma mark - JXCategoryListContentViewDelegate
  35. - (void)listWillAppear{
  36. if(self.dataArr.count == 0 && !self.isManage){
  37. [self getFirstHttpData];
  38. }
  39. }
  40. - (void)getFirstHttpData{
  41. NSString *roomId = self.roomId;
  42. if(roomId.length == 0){
  43. return;
  44. }
  45. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  46. NSDictionary *baseDict = @{@"page":basePage,
  47. @"roomId":roomId};
  48. [self getAllLinkMicApplyListDataWith:baseDict];
  49. }
  50. - (void)getAllLinkMicApplyListDataWith:(NSDictionary *)dict{
  51. WEAKSELF
  52. [kHttpManager toGetApplyListAboutLinkMicWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  53. __strong typeof(weakSelf) self = weakSelf;
  54. [self.tableView.mj_header endRefreshing];
  55. [self.tableView.mj_footer endRefreshing];
  56. if(kCode_Success){
  57. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  58. MOPersonData *personModel = [MOPersonData modelObjectWithDictionary:data[@"data"]];
  59. if(personModel.next == nil || personModel.next.length == 0){
  60. if(self.next == nil || self.next.length == 0){
  61. //第一页
  62. self.dataArr = [personModel.personList mutableCopy];
  63. }
  64. else{
  65. //最后一页
  66. [self.dataArr addObjectsFromArray:personModel.personList];
  67. }
  68. self.next = @"";
  69. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  70. }
  71. else{
  72. self.next = personModel.next;
  73. [self.dataArr addObjectsFromArray:personModel.personList];
  74. }
  75. [self.tableView reloadData];
  76. self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  77. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  78. }
  79. else{
  80. kShowNetError(data)
  81. }
  82. }];
  83. }
  84. - (UIView *)listView{
  85. return self;
  86. }
  87. - (void)setLinkMics:(NSArray *)linkMics{
  88. _linkMics = linkMics;
  89. [self.dataArr removeAllObjects];
  90. NSInteger seatNum = 1;
  91. for (MOLinkMic *linkObject in linkMics) {
  92. if(linkObject.profile.id.length > 0){
  93. linkObject.seatNum = seatNum;
  94. [self.dataArr addObject:linkObject];
  95. }
  96. seatNum ++;
  97. }
  98. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  99. [self.tableView reloadData];
  100. }
  101. #pragma mark - UITableViewDelegate,UITableViewDataSource
  102. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  103. return 1;
  104. }
  105. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  106. return self.dataArr.count;
  107. }
  108. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  109. WEAKSELF
  110. if(self.isManage){
  111. //管理Cell
  112. MOLinkMic *model = self.dataArr[indexPath.row];
  113. MOApplicationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MOApplicationTableViewCell_ID];
  114. cell.isManage = self.isManage;
  115. cell.roomId = self.roomId;
  116. cell.linkCellModel = model;
  117. __weak __typeof__(cell) weakCell = cell;
  118. cell.roomStatusChangeBlock = ^(MORoomStatus * _Nonnull roomStatus) {
  119. weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatus) : nil;
  120. };
  121. cell.hangUpBlock = ^(MOLinkMic * _Nonnull linkCellModel) {
  122. NSIndexPath *newIndexPath = [weakSelf.tableView indexPathForCell:weakCell];
  123. if (newIndexPath && newIndexPath.row < weakSelf.dataArr.count) {
  124. [weakSelf.dataArr removeObjectAtIndex:newIndexPath.row];
  125. [weakSelf.tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  126. }
  127. weakSelf.hangUpBlock ? weakSelf.hangUpBlock(linkCellModel) : nil;
  128. };
  129. cell.addRTMTipBlock = ^(NSString * _Nonnull rtmTipStr) {
  130. weakSelf.addRTMTipBlock ? weakSelf.addRTMTipBlock(rtmTipStr) : nil;
  131. };
  132. return cell;
  133. }
  134. else{
  135. MOPersonList *moel = self.dataArr[indexPath.row];
  136. MOApplicationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MOApplicationTableViewCell_ID];
  137. cell.isManage = self.isManage;
  138. cell.roomId = self.roomId;
  139. cell.cellModel = moel;
  140. __weak __typeof__(cell) weakCell = cell;
  141. cell.roomStatusChangeBlock = ^(MORoomStatus * _Nonnull roomStatus) {
  142. NSIndexPath *newIndexPath = [weakSelf.tableView indexPathForCell:weakCell];
  143. [weakSelf.dataArr removeObjectAtIndex:newIndexPath.row];
  144. [weakSelf.tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  145. if(roomStatus){
  146. weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatus) : nil;
  147. }
  148. };
  149. cell.addRTMTipBlock = ^(NSString * _Nonnull rtmTipStr) {
  150. weakSelf.addRTMTipBlock ? weakSelf.addRTMTipBlock(rtmTipStr) : nil;
  151. };
  152. return cell;
  153. }
  154. }
  155. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  156. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  157. }
  158. #pragma mark - Lazy
  159. - (UITableView *)tableView{
  160. if (!_tableView)
  161. {
  162. _tableView= [[UITableView alloc] init];
  163. if (@available(iOS 11.0, *))
  164. {
  165. _tableView.estimatedRowHeight = 0;
  166. _tableView.estimatedSectionFooterHeight = 0;
  167. _tableView.estimatedSectionHeaderHeight = 0;
  168. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  169. }
  170. //iOS15适配
  171. if (@available(iOS 15.0, *))
  172. {
  173. self.tableView.sectionHeaderTopPadding = 0;
  174. }
  175. _tableView.backgroundColor = [UIColor whiteColor];
  176. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  177. _tableView.dataSource = self;
  178. _tableView.delegate = self;
  179. _tableView.showsVerticalScrollIndicator = NO;
  180. _tableView.showsHorizontalScrollIndicator = NO;
  181. _tableView.rowHeight = 50.0;
  182. [_tableView registerNib:[UINib nibWithNibName:@"MOApplicationTableViewCell" bundle:nil] forCellReuseIdentifier:MOApplicationTableViewCell_ID];
  183. _tableView.backgroundView = self.noMoreDataView;
  184. WEAKSELF
  185. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  186. if(!weakSelf.isManage){
  187. [weakSelf getFirstHttpData];
  188. }
  189. else{
  190. [weakSelf.tableView.mj_header endRefreshing];
  191. }
  192. }];
  193. header.lastUpdatedTimeLabel.hidden = YES;
  194. header.stateLabel.hidden = YES;
  195. _tableView.mj_header = header;
  196. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  197. NSString *roomId = weakSelf.roomId;
  198. if(roomId.length == 0){
  199. return;
  200. }
  201. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  202. NSDictionary *baseDict = @{@"page":basePage,
  203. @"roomId":roomId};
  204. [weakSelf getAllLinkMicApplyListDataWith:baseDict];
  205. }];
  206. _tableView.mj_footer.hidden = YES;
  207. }
  208. return _tableView;
  209. }
  210. - (NSMutableArray *)dataArr{
  211. if(!_dataArr){
  212. _dataArr = [NSMutableArray array];
  213. }
  214. return _dataArr;
  215. }
  216. - (MONoMoreDataView *)noMoreDataView{
  217. if(!_noMoreDataView){
  218. _noMoreDataView = [MONoMoreDataView new];
  219. }
  220. return _noMoreDataView;
  221. }
  222. @end