YOUPAIHRLiveRankDetailVC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // YOUPAIHRAccompanyRankDetailVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/10/19.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRLiveRankDetailVC.h"
  9. #import "YOUPAIHRsendRankModel.h"
  10. #import "YOUPAIHRLiveRankDetailCell.h"
  11. #import "YOUPAILZUserShowVC.h"
  12. @interface YOUPAIHRLiveRankDetailVC ()<UITableViewDelegate,UITableViewDataSource>{
  13. int ispage;
  14. int nextpage;
  15. }
  16. @property(nonatomic,strong)UITableView *youpaiptableView;
  17. @property(nonatomic,strong)NSMutableArray *youpaipdataArr;//数据源
  18. @end
  19. @implementation YOUPAIHRLiveRankDetailVC
  20. - (void)dealloc{
  21. [[NSNotificationCenter defaultCenter] removeObserver:self];
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // self.view.backgroundColor = LCBkgColor;
  26. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  27. [self youpaiptableView];
  28. [self youpaifRefreshUI];
  29. }
  30. -(void)youpaifRefreshUI{
  31. nextpage = 1;
  32. self.view.tag = 1;
  33. @weakify(self);
  34. self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  35. @strongify(self);
  36. self->nextpage = 1;
  37. [self youpaifgift_rankData];
  38. }];
  39. // 上拉刷新
  40. self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  41. @strongify(self);
  42. if (self->nextpage< self->ispage) {
  43. self.view.tag = 2;
  44. self->nextpage = self->nextpage+1;
  45. [self youpaifgift_rankData];
  46. }else
  47. {
  48. [self.youpaiptableView.mj_footer endRefreshing];
  49. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  50. }
  51. }];
  52. [self.youpaiptableView.mj_header beginRefreshing];
  53. }
  54. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  55. NSDictionary *dict = [notification userInfo];
  56. NSString *idStr = dict[@"follow_uid"];
  57. NSInteger isfollow = [dict[@"is_follow"] intValue];
  58. NSArray *arr = self.youpaipdataArr;
  59. if (arr.count>0) {
  60. NSIndexPath *index;
  61. NSMutableArray *arrM = [NSMutableArray new];
  62. for (int i = 0; i<arr.count; i++) {
  63. YOUPAIHRsendRankModel *model = arr[i];
  64. if ([model.youpaipid isEqualToString:idStr]) {
  65. model.youpaipis_follow = isfollow;
  66. index = [NSIndexPath indexPathForRow:i inSection:0];
  67. [arrM addObject:index];
  68. }
  69. }
  70. [UIView performWithoutAnimation:^{
  71. [self.youpaiptableView reloadRowsAtIndexPaths:arrM withRowAnimation:UITableViewRowAnimationFade];
  72. }];
  73. }
  74. }
  75. #pragma mark UITableViewDelegate&UITableViewDataSource
  76. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  77. YOUPAIHRsendRankModel *model = self.youpaipdataArr[indexPath.row];
  78. YOUPAILZUserShowVC *showVC = [[YOUPAILZUserShowVC alloc]init];
  79. showVC.youpaipuserId = model.youpaipid;
  80. [self.navigationController pushViewController:showVC animated:YES];
  81. }
  82. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  83. return 75;
  84. }
  85. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  86. return self.youpaipdataArr.count;
  87. }
  88. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  89. YOUPAIHRLiveRankDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRLiveRankDetailID"];
  90. if (cell == nil) {
  91. cell = [[YOUPAIHRLiveRankDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRLiveRankDetailID"];
  92. }
  93. YOUPAIHRsendRankModel *model = self.youpaipdataArr[indexPath.row];
  94. cell.youpaipuserModel = model;
  95. // cell.backgroundColor = LCBkgColor;
  96. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  97. return cell;
  98. }
  99. -(UITableView *)youpaiptableView{
  100. if (!_youpaiptableView) {
  101. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  102. [self.view addSubview:_youpaiptableView];
  103. [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.mas_equalTo(0);
  105. make.top.mas_equalTo(0);
  106. make.bottom.mas_equalTo(0);
  107. make.right.mas_equalTo(0);
  108. }];
  109. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  110. _youpaiptableView.showsVerticalScrollIndicator = NO;
  111. _youpaiptableView.showsHorizontalScrollIndicator = NO;
  112. _youpaiptableView.delegate = self;
  113. _youpaiptableView.dataSource = self;
  114. _youpaiptableView.backgroundColor = UIColor.clearColor;
  115. [_youpaiptableView registerClass:[YOUPAIHRLiveRankDetailCell class] forCellReuseIdentifier:@"HRLiveRankDetailID"];
  116. _youpaiptableView.tableFooterView = [UIView new];
  117. if (@available(iOS 15.0, *)) {
  118. _youpaiptableView.sectionHeaderTopPadding = 0;
  119. }
  120. }
  121. return _youpaiptableView;
  122. }
  123. #pragma 获取数据
  124. -(void)youpaifgift_rankData{
  125. NSMutableDictionary *mutDict = [NSMutableDictionary new];
  126. [mutDict setObject:[NSString stringWithFormat:@"%d",nextpage] forKey:@"page"];
  127. [mutDict setObject:@"2" forKey:@"type"];
  128. [mutDict setObject:self.youpaiptype forKey:@"status"];
  129. [LCHttpHelper requestWithURLString:Gift_rank parameters:mutDict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  130. NSDictionary* dict = (NSDictionary*)responseObject;
  131. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  132. if (code==0) {//成功
  133. [self.youpaiptableView.mj_header endRefreshing];
  134. NSDictionary *dic = dict[@"data"];
  135. NSMutableArray *arrM = [NSMutableArray new];
  136. if (self.view.tag == 1) {
  137. NSArray *arr = dic[@"list"];
  138. [self.youpaiptableView lz_hideEmptyView];
  139. if (arr.count == 0) {
  140. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无记录"];
  141. }
  142. if (arr.count<=0) {
  143. [self.youpaipdataArr removeAllObjects];
  144. [self.youpaiptableView reloadData];
  145. return ;
  146. }
  147. [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  148. YOUPAIHRsendRankModel *noticModel = [YOUPAIHRsendRankModel mj_objectWithKeyValues:obj];
  149. [self.youpaipdataArr addObject:noticModel];
  150. [arrM addObject:noticModel];
  151. }];
  152. if (self->nextpage == 1) {
  153. self.youpaipdataArr = arrM;
  154. self->nextpage = [dict[@"data"][@"page"] intValue];
  155. self->ispage = [dict[@"data"][@"total_page"] intValue];
  156. [self.youpaiptableView reloadData];
  157. }
  158. }else{
  159. NSArray *arr = dic[@"list"];
  160. if (arr.count<=0) {
  161. return ;
  162. }
  163. [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  164. YOUPAIHRsendRankModel *noticModel = [YOUPAIHRsendRankModel mj_objectWithKeyValues:obj];
  165. [self.youpaipdataArr addObject:noticModel];
  166. }];
  167. self->nextpage = [dict[@"data"][@"page"] intValue];
  168. self->ispage = [dict[@"data"][@"total_page"] intValue];
  169. [self.youpaiptableView reloadData];
  170. [self.youpaiptableView.mj_header endRefreshing];
  171. [self.youpaiptableView.mj_footer endRefreshing];
  172. }
  173. }
  174. } failure:^(NSError *error) {
  175. [self.youpaiptableView.mj_header endRefreshing];
  176. [self.youpaiptableView.mj_footer endRefreshing];
  177. }];
  178. }
  179. -(NSMutableArray *)youpaipdataArr{
  180. if (_youpaipdataArr == nil) {
  181. _youpaipdataArr = [NSMutableArray new];
  182. }
  183. return _youpaipdataArr;
  184. }
  185. #pragma mark - JXCategoryListContainerView
  186. - (UIView *)listView{
  187. return self.view;
  188. }
  189. @end