YOUPAILZLiveOnlineMemberListVC.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // YOUPAILZLiveOnlineMemberListVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/7/22.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveOnlineMemberListVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZLiveOnlineMemberCell.h"
  11. #import "YOUPAILZLiveMemberModel.h"
  12. @interface YOUPAILZLiveOnlineMemberListVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, weak) UITableView *youpaiptableView;
  14. @property (nonatomic, strong) NSString *youpaipendtime;
  15. @property (nonatomic, strong) NSMutableArray<YOUPAILZLiveMemberModel *> *youpaipdataSource;
  16. @end
  17. @implementation YOUPAILZLiveOnlineMemberListVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self youpaifinitUI];
  21. /// 关注状态改变,接收通知
  22. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  23. [self youpaifrequestMemberListWithStatus:kRefreshNormal];
  24. }
  25. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  26. NSDictionary *dict = [notification userInfo];
  27. NSString *idStr = dict[@"follow_uid"];
  28. NSInteger isfollow = [dict[@"is_follow"] intValue];
  29. NSArray *arr = self.youpaipdataSource;
  30. NSMutableArray *arrM = [NSMutableArray new];
  31. if (arr.count>0) {
  32. for (int i = 0; i<arr.count; i++) {
  33. YOUPAILZLiveMemberModel *model = arr[i];
  34. if ([model.youpaipid isEqualToString:idStr]) {
  35. model.youpaipis_follow = isfollow;
  36. }
  37. [arrM addObject:model];
  38. }
  39. [self.youpaipdataSource removeAllObjects];
  40. self.youpaipdataSource = arrM;
  41. [self.youpaiptableView reloadData];
  42. }
  43. }
  44. -(void)dealloc{
  45. [[NSNotificationCenter defaultCenter]removeObserver:self];
  46. }
  47. - (void)youpaifinitUI{
  48. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  49. tableView.delegate = self;
  50. tableView.dataSource = self;
  51. tableView.rowHeight = 60.0f;
  52. tableView.estimatedRowHeight = 60.0f;
  53. tableView.estimatedSectionHeaderHeight = 0.0f;
  54. tableView.estimatedSectionFooterHeight = 0.0f;
  55. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  56. tableView.backgroundColor = [UIColor clearColor];
  57. [self.view addSubview:tableView];
  58. self.youpaiptableView = tableView;
  59. __weak typeof(self) weakSelf = self;
  60. [tableView setRefreshHeaderWithBlock:^{
  61. [weakSelf youpaifrequestMemberListWithStatus:kRefreshHeader];
  62. }];
  63. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.top.right.offset(0.0f);
  65. make.bottom.offset(-SafeHeight);
  66. }];
  67. }
  68. #pragma mark - UITableViewDataSource
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  70. return self.youpaipdataSource.count;
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  73. NSString *cellID = @"YOUPAILZLiveOnlineMemberCell";
  74. YOUPAILZLiveOnlineMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  75. if (!cell) {
  76. cell = [[YOUPAILZLiveOnlineMemberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  77. }
  78. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] indexPath:indexPath type:self.youpaiptype youpaipthemeColor:HexColorFromRGB(0xFFDD8D)];
  79. return cell;
  80. }
  81. #pragma mark - UITableViewDelegate
  82. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  83. [self dismissViewControllerAnimated:YES completion:^{
  84. if (self.youpaipisAnchor == YES) {
  85. if (self.selectedMemberBlock != nil) {
  86. self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
  87. }
  88. }else{
  89. if (self.selectedMemberBlock != nil) {
  90. self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
  91. }
  92. }
  93. }];
  94. }
  95. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  96. return CGFLOAT_MIN;
  97. }
  98. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  99. return CGFLOAT_MIN;
  100. }
  101. /// 设置加载更多
  102. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  103. __weak typeof(self) weakSelf = self;
  104. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  105. [weakSelf youpaifrequestMemberListWithStatus:kRefreshFooter];
  106. }];
  107. }
  108. /// 获取预约列表数据
  109. - (void)youpaifrequestMemberListWithStatus:(kRefreshStatus)status{
  110. if (status != kRefreshFooter) {
  111. self.youpaipendtime = @"0";
  112. }
  113. WeakSelf;
  114. [LCHttpHelper requestWithURLString:GetLiveOnlineUsers parameters:@{@"endtime":self.youpaipendtime,@"live_id":self.youpaiplive_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  115. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  116. NSDictionary* dict = (NSDictionary*)responseObject;
  117. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  118. if (code == 0) {//成功
  119. if (status != kRefreshFooter) {
  120. [weakSelf.youpaipdataSource removeAllObjects];
  121. }
  122. NSDictionary *data = [dict objectForKey:@"data"];
  123. NSString *endTime = [NSString stringWithFormat:@"%@",[data objectForKey:@"end_time"]];
  124. NSArray <YOUPAILZLiveMemberModel *>*list = [YOUPAILZLiveMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  125. [weakSelf.youpaipdataSource addObjectsFromArray:list];
  126. [weakSelf.youpaiptableView reloadData];
  127. [weakSelf.youpaiptableView lz_hideEmptyView];
  128. if (weakSelf.youpaipdataSource.count == 0) {
  129. [weakSelf.youpaiptableView lz_showEmptyViewWithImage:nil content:@"当前还没有观众呢~"];
  130. }
  131. if ([weakSelf.youpaipendtime isEqual:endTime]) {
  132. [weakSelf youpaifrefreshFooterWithHidden:YES];
  133. }else{
  134. weakSelf.youpaipendtime = endTime;
  135. [weakSelf youpaifrefreshFooterWithHidden:NO];
  136. }
  137. }
  138. } failure:^(NSError *error) {
  139. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  140. }];
  141. }
  142. - (NSMutableArray<YOUPAILZLiveMemberModel *> *)youpaipdataSource{
  143. if (!_youpaipdataSource) {
  144. _youpaipdataSource = [NSMutableArray array];
  145. }
  146. return _youpaipdataSource;
  147. }
  148. #pragma mark - JXCategoryListContentViewDelegate
  149. - (UIView *)listView{
  150. return self.view;
  151. }
  152. @end