YOUPAILZLiveAnchorHotListVC.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // YOUPAILZLiveConsumeMemberListVC.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/13.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveAnchorHotListVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZLiveAnchorHotCell.h"
  11. #import "YOUPAILZLiveMemberModel.h"
  12. #import "YOUPAILZLiveAnchorHotMemberView.h"
  13. #import "YOUPAILZLiveCurrent_anchorModel.h"
  14. @interface YOUPAILZLiveAnchorHotListVC () <UITableViewDelegate,UITableViewDataSource>
  15. @property (nonatomic, weak) UITableView *youpaiptableView;
  16. @property (nonatomic, assign) NSInteger youpaippage;
  17. @property (nonatomic, strong) NSMutableArray<YOUPAILZLiveMemberModel *> *youpaipdataSource;
  18. @property (nonatomic, weak) YOUPAILZLiveAnchorHotMemberView *youpaipfooterView;
  19. @end
  20. @implementation YOUPAILZLiveAnchorHotListVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self youpaifinitUI];
  24. /// 关注状态改变,接收通知
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  26. [self youpaifrequestMemberListWithStatus:kRefreshNormal];
  27. }
  28. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  29. NSDictionary *dict = [notification userInfo];
  30. NSString *idStr = dict[@"follow_uid"];
  31. NSInteger isfollow = [dict[@"is_follow"] intValue];
  32. NSArray *arr = self.youpaipdataSource;
  33. NSMutableArray *arrM = [NSMutableArray new];
  34. if (arr.count>0) {
  35. for (int i = 0; i<arr.count; i++) {
  36. YOUPAILZLiveMemberModel *model = arr[i];
  37. if ([model.youpaipid isEqualToString:idStr]) {
  38. model.youpaipis_follow = isfollow;
  39. }
  40. [arrM addObject:model];
  41. }
  42. [self.youpaipdataSource removeAllObjects];
  43. self.youpaipdataSource = arrM;
  44. [self.youpaiptableView reloadData];
  45. }
  46. }
  47. -(void)dealloc{
  48. [[NSNotificationCenter defaultCenter]removeObserver:self];
  49. }
  50. - (void)youpaifinitUI{
  51. YOUPAILZLiveAnchorHotMemberView *youpaipfooterView = [[YOUPAILZLiveAnchorHotMemberView alloc] init];
  52. youpaipfooterView.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 3.0f, 60.0f + SafeHeight) FromColors:@[HexColorFromRGB(0xF775BD),HexColorFromRGB(0xF43333)] ByGradientType:GradientTopToBottom]];
  53. [self.view addSubview:youpaipfooterView];
  54. self.youpaipfooterView = youpaipfooterView;
  55. [youpaipfooterView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.bottom.right.offset(0.0f);
  57. make.height.offset(60.0f + SafeHeight);
  58. }];
  59. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  60. tableView.delegate = self;
  61. tableView.dataSource = self;
  62. tableView.rowHeight = 60.0f;
  63. tableView.estimatedRowHeight = 60.0f;
  64. tableView.estimatedSectionHeaderHeight = 0.0f;
  65. tableView.estimatedSectionFooterHeight = 0.0f;
  66. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  67. tableView.backgroundColor = [UIColor clearColor];
  68. [self.view addSubview:tableView];
  69. self.youpaiptableView = tableView;
  70. __weak typeof(self) weakSelf = self;
  71. [tableView setRefreshHeaderWithBlock:^{
  72. [weakSelf youpaifrequestMemberListWithStatus:kRefreshHeader];
  73. }];
  74. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.top.right.offset(0.0f);
  76. make.bottom.equalTo(youpaipfooterView.mas_top);
  77. }];
  78. }
  79. #pragma mark - UITableViewDataSource
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  81. return self.youpaipdataSource.count;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  84. NSString *cellID = @"YOUPAILZLiveAnchorHotCell";
  85. YOUPAILZLiveAnchorHotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  86. if (!cell) {
  87. cell = [[YOUPAILZLiveAnchorHotCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  88. }
  89. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] indexPath:indexPath type:self.youpaiptype youpaipthemeColor:HexColorFromRGB(0xFF9494)];
  90. return cell;
  91. }
  92. #pragma mark - UITableViewDelegate
  93. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  94. [self dismissViewControllerAnimated:YES completion:^{
  95. if (self.youpaipisAnchor == YES) {
  96. if (self.selectedMemberBlock != nil) {
  97. self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
  98. }
  99. }else{
  100. if (self.selectedMemberBlock != nil) {
  101. self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
  102. }
  103. }
  104. }];
  105. }
  106. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  107. return CGFLOAT_MIN;
  108. }
  109. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  110. return CGFLOAT_MIN;
  111. }
  112. /// 设置加载更多
  113. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  114. __weak typeof(self) weakSelf = self;
  115. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  116. [weakSelf youpaifrequestMemberListWithStatus:kRefreshFooter];
  117. }];
  118. }
  119. /// 获取预约列表数据
  120. - (void)youpaifrequestMemberListWithStatus:(kRefreshStatus)status{
  121. if (status == kRefreshFooter) {
  122. self.youpaippage ++;
  123. }else{
  124. self.youpaippage = 1;
  125. }
  126. int youpaiptypeint;
  127. // 1=周 2=月 4=日
  128. if (self.youpaiptype == LZLiveAnchorHotListType_day) {
  129. youpaiptypeint = 4;
  130. }else if (self.youpaiptype == LZLiveAnchorHotListType_week){
  131. youpaiptypeint = 1;
  132. }else{
  133. youpaiptypeint = 2;
  134. }
  135. NSMutableDictionary *dict = [NSMutableDictionary new];
  136. [dict setObject:@(self.youpaippage) forKey:@"page"];
  137. [dict setObject:self.youpaiplive_id forKey:@"live_id"];
  138. [dict setObject:@(youpaiptypeint) forKey:@"type"];
  139. WeakSelf;
  140. [LCHttpHelper requestWithURLString:GetLiveRankList parameters:dict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  141. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  142. NSDictionary* dict = (NSDictionary*)responseObject;
  143. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  144. if (code == 0) {//成功
  145. if (status != kRefreshFooter) {
  146. [weakSelf.youpaipdataSource removeAllObjects];
  147. }
  148. NSDictionary *data = [dict objectForKey:@"data"];
  149. NSArray <YOUPAILZLiveMemberModel *>*list = [YOUPAILZLiveMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  150. [weakSelf.youpaipdataSource addObjectsFromArray:list];
  151. [weakSelf.youpaiptableView reloadData];
  152. YOUPAILZLiveCurrent_anchorModel *youpaipmemberModel = [YOUPAILZLiveCurrent_anchorModel mj_objectWithKeyValues:[data objectForKey:@"current_anchor"]];
  153. [weakSelf.youpaipfooterView youpaifreloadWithModel:youpaipmemberModel];
  154. weakSelf.youpaipfooterView.youpaiprankL.textColor = [UIColor whiteColor];
  155. weakSelf.youpaipfooterView.youpaipnicknameL.textColor = [UIColor whiteColor];
  156. // NSMutableAttributedString *attrStr = weakSelf.youpaipfooterView.youpaipcontributionL.attributedText.mutableCopy;
  157. // [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x75170A) range:NSMakeRange(0, weakSelf.youpaipfooterView.youpaipcontributionL.attributedText.string.length)];
  158. // weakSelf.youpaipfooterView.youpaipcontributionL.attributedText = attrStr.copy;
  159. weakSelf.youpaipfooterView.youpaiplastDifferenceL.textColor = [UIColor whiteColor];
  160. [weakSelf.youpaiptableView lz_hideEmptyView];
  161. if (weakSelf.youpaipdataSource.count == 0) {
  162. [weakSelf.youpaiptableView lz_showEmptyViewWithImage:nil content:@"暂未有女神上榜哦~"];
  163. }
  164. NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue];
  165. [weakSelf youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
  166. }
  167. } failure:^(NSError *error) {
  168. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  169. }];
  170. }
  171. - (NSMutableArray<YOUPAILZLiveMemberModel *> *)youpaipdataSource{
  172. if (!_youpaipdataSource) {
  173. _youpaipdataSource = [NSMutableArray array];
  174. }
  175. return _youpaipdataSource;
  176. }
  177. #pragma mark - JXCategoryListContentViewDelegate
  178. - (UIView *)listView{
  179. return self.view;
  180. }
  181. @end