MOContributionListView.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // MOContributionListView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/26.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOContributionListView.h"
  10. #import "MOVoiceContriCell.h"
  11. @interface MOContributionListView ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (weak, nonatomic) IBOutlet UIView *bgView;
  13. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  14. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  15. /** 展示数据 */
  16. @property (nonatomic, strong) NSMutableArray *dataArr;
  17. /** 没有更多的数据视图 */
  18. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  19. @property (nonatomic, copy) NSString *next;
  20. @end
  21. @implementation MOContributionListView
  22. + (instancetype)moContributionListView{
  23. return [[[NSBundle mainBundle] loadNibNamed:@"MOContributionListView" owner:self options:nil] firstObject];
  24. }
  25. - (void)awakeFromNib{
  26. [super awakeFromNib];
  27. self.next = @"";
  28. //上方 两个圆角
  29. self.bgView.layer.cornerRadius = 16.0;
  30. self.bgView.layer.masksToBounds = YES;
  31. self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  32. self.tableView.delegate = self;
  33. self.tableView.dataSource = self;
  34. self.tableView.rowHeight = 62.0;
  35. self.tableView.estimatedRowHeight = 0;
  36. self.tableView.estimatedSectionHeaderHeight = 0;
  37. self.tableView.estimatedSectionFooterHeight = 0;
  38. //iOS15适配
  39. if (@available(iOS 15.0, *))
  40. {
  41. self.tableView.sectionHeaderTopPadding = 0;
  42. }
  43. [self.tableView registerNib:[UINib nibWithNibName:@"MOVoiceContriCell" bundle:nil] forCellReuseIdentifier:MOVoiceContriCell_ID];
  44. WEAKSELF
  45. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  46. NSString *roomId = weakSelf.roomId;
  47. if(roomId.length == 0){
  48. return;
  49. }
  50. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  51. NSDictionary *baseDict = @{@"page":basePage,
  52. @"roomId":roomId,
  53. @"userId":weakSelf.userId};
  54. [weakSelf getTheVoiceOutcomeRankDataWith:baseDict];
  55. }];
  56. self.tableView.mj_footer.hidden = YES;
  57. self.tableView.backgroundView = self.noMoreDataView;
  58. self.titleLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalTitleFontStr];
  59. }
  60. - (IBAction)closeBtnClick:(id)sender {
  61. [self dismissContributionListView];
  62. }
  63. - (void)getFirstHttpData{
  64. self.next = @"";
  65. NSString *roomId = self.roomId;
  66. if(roomId.length == 0 || self.userId.length == 0){
  67. return;
  68. }
  69. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  70. NSDictionary *baseDict = @{@"page":basePage,
  71. @"roomId":roomId,
  72. @"userId":self.userId};
  73. [self getTheVoiceOutcomeRankDataWith:baseDict];
  74. }
  75. - (void)getTheVoiceOutcomeRankDataWith:(NSDictionary *)dict{
  76. WEAKSELF
  77. [kHttpManager toGetTheOutcomeAboutGuestWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  78. if(kCode_Success){
  79. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  80. MORankBasedata *personModel = [MORankBasedata modelObjectWithDictionary:data[@"data"]];
  81. if(personModel.next == nil || personModel.next.length == 0){
  82. if(self.next == nil || self.next.length == 0){
  83. //第一页
  84. self.dataArr = [personModel.ranklist mutableCopy];
  85. }
  86. else{
  87. //最后一页
  88. [self.dataArr addObjectsFromArray:personModel.ranklist];
  89. }
  90. self.next = @"";
  91. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  92. }
  93. else{
  94. self.next = personModel.next;
  95. [self.dataArr addObjectsFromArray:personModel.ranklist];
  96. }
  97. [self.tableView reloadData];
  98. self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  99. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  100. }
  101. else{
  102. MOLogV(@"toGetTheOutcomeAboutGuestWithParams 接口报错了");
  103. kShowNetError(data)
  104. }
  105. }];
  106. }
  107. #pragma mark - UITableViewDelegate,UITableViewDataSource
  108. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  109. return 1;
  110. }
  111. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  112. return self.dataArr.count;
  113. }
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  115. MORanklist *model = self.dataArr[indexPath.row];
  116. MOVoiceContriCell *cell = [tableView dequeueReusableCellWithIdentifier:MOVoiceContriCell_ID];
  117. cell.cellIndexPath = indexPath;
  118. cell.cellModel = model;
  119. return cell;
  120. }
  121. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  122. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  123. }
  124. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  125. UIView *view = [[UIView alloc] init];
  126. view.backgroundColor = [UIColor clearColor];
  127. return view;
  128. }
  129. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  130. return 0.01;
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  133. return 0.01;
  134. }
  135. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  136. UIView *view = [[UIView alloc] init];
  137. view.backgroundColor = [UIColor clearColor];
  138. return view;
  139. }
  140. - (void)showContributionListView{
  141. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  142. CGRect actionViewRect = self.bgView.frame;
  143. actionViewRect.origin.y = SCREENHEIGHT;
  144. self.bgView.frame = actionViewRect;
  145. WEAKSELF
  146. [UIView animateWithDuration:0.3 animations:^{
  147. CGRect actionViewRect = weakSelf.bgView.frame;
  148. actionViewRect.origin.y = SCREENHEIGHT - 480.0;
  149. weakSelf.bgView.frame = actionViewRect;
  150. }];
  151. //不能滑动
  152. SendNotification(@"MOShowLivePagesVCCannotScroll")
  153. }
  154. - (void)dismissContributionListView{
  155. //完成下移动画
  156. WEAKSELF
  157. [UIView animateWithDuration:0.3 animations:^
  158. {
  159. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  160. actionSheetViewRect.origin.y = SCREENHEIGHT;
  161. weakSelf.bgView.frame = actionSheetViewRect;
  162. } completion:^(BOOL finished)
  163. {
  164. [self removeFromSuperview];
  165. }];
  166. //可以滑动
  167. SendNotification(@"MOShowLivePagesVCCanScroll")
  168. }
  169. - (NSMutableArray *)dataArr{
  170. if(!_dataArr){
  171. _dataArr = [NSMutableArray array];
  172. }
  173. return _dataArr;
  174. }
  175. - (MONoMoreDataView *)noMoreDataView{
  176. if(!_noMoreDataView){
  177. _noMoreDataView = [MONoMoreDataView new];
  178. }
  179. return _noMoreDataView;
  180. }
  181. @end