YOUPAIHRChatRoomCurrentAudienceVC.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // YOUPAIHRChatRoomCurrentAudienceVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/3.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomCurrentAudienceVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZChatRoomInviationUpSeatCell.h"
  11. @interface YOUPAIHRChatRoomCurrentAudienceVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, weak) UITableView *youpaiptableView;
  13. @property (nonatomic, strong) NSString *youpaipendTime;
  14. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomMemberModel *>*youpaipdataSource;
  15. @end
  16. @implementation YOUPAIHRChatRoomCurrentAudienceVC
  17. - (void)dealloc{
  18. [[NSNotificationCenter defaultCenter] removeObserver:self];
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self youpaifinitUI];
  23. /// 关注状态改变,接收通知
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  25. [self youpaifrequestOnlineListWithStatus:kRefreshNormal];
  26. }
  27. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  28. NSDictionary *dict = [notification userInfo];
  29. NSString *idStr = dict[@"follow_uid"];
  30. NSInteger isfollow = [dict[@"is_follow"] intValue];
  31. NSArray *arr = self.youpaipdataSource;
  32. NSMutableArray *arrM = [NSMutableArray new];
  33. if (arr.count>0) {
  34. for (int i = 0; i<arr.count; i++) {
  35. YOUPAILZChatRoomMemberModel *model = arr[i];
  36. if ([model.youpaipid isEqualToString:idStr]) {
  37. model.youpaipis_follow = isfollow;
  38. }
  39. [arrM addObject:model];
  40. }
  41. [self.youpaipdataSource removeAllObjects];
  42. self.youpaipdataSource = arrM;
  43. [self.youpaiptableView reloadData];
  44. }
  45. }
  46. - (void)youpaifinitUI{
  47. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  48. tableView.delegate = self;
  49. tableView.dataSource = self;
  50. tableView.rowHeight = 60.0f;
  51. tableView.estimatedRowHeight = 60.0f;
  52. tableView.estimatedSectionHeaderHeight = 0.0f;
  53. tableView.estimatedSectionFooterHeight = 0.0f;
  54. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  55. tableView.backgroundColor = [UIColor clearColor];
  56. tableView.showsVerticalScrollIndicator = NO;
  57. [self.view addSubview:tableView];
  58. self.youpaiptableView = tableView;
  59. @weakify(self);
  60. [tableView setRefreshHeaderWithBlock:^{
  61. @strongify(self);
  62. [self youpaifrequestOnlineListWithStatus:kRefreshHeader];
  63. }];
  64. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.right.top.offset(0.0f);
  66. make.bottom.offset(-SafeHeight);
  67. }];
  68. }
  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 = @"YOUPAILZChatRoomInviationUpSeatCell";
  74. YOUPAILZChatRoomInviationUpSeatCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  75. if (cell == nil) {
  76. cell = [[YOUPAILZChatRoomInviationUpSeatCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  77. }
  78. LZChatRoomInviationUpSeatCellButtonType buttonType = LZChatRoomInviationUpSeatCellButtonTypeWithInviation;
  79. if (self.youpaipchatroomModel.youpaipuserInfo.youpaifroleType == LZUserRoleTypeWithNormal) {
  80. buttonType = LZChatRoomInviationUpSeatCellButtonTypeWithFollow;
  81. }
  82. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] index:indexPath.row buttonType:buttonType rankType:LZChatRoomInviationUpSeatCellRankTypeWithDefault contributionName:@"贡献值"];
  83. @weakify(self);
  84. [cell setYoupaipinviationBtnClickBlock:^(YOUPAILZChatRoomMemberModel * _Nonnull model) {
  85. @strongify(self);
  86. [self youpaifinviationUpSeatWithModel:model];
  87. }];
  88. return cell;
  89. }
  90. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  91. return CGFLOAT_MIN;
  92. }
  93. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  94. return CGFLOAT_MIN;
  95. }
  96. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  97. if (self.youpaiptouchUserBlock != nil) {
  98. self.youpaiptouchUserBlock(self.youpaipdataSource[indexPath.row].youpaipid);
  99. }
  100. }
  101. /// 邀请上麦
  102. - (void)youpaifinviationUpSeatWithModel:(YOUPAILZChatRoomMemberModel *)model{
  103. if (self.youpaipupseatBlock != nil) {
  104. self.youpaipupseatBlock(model);
  105. }
  106. }
  107. /// 设置加载更多
  108. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  109. @weakify(self);
  110. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  111. @strongify(self);
  112. [self youpaifrequestOnlineListWithStatus:kRefreshFooter];
  113. }];
  114. }
  115. - (void)youpaifrequestOnlineListWithStatus:(kRefreshStatus)status{
  116. if (status == kRefreshFooter) {
  117. }else{
  118. self.youpaipendTime = @"0";
  119. }
  120. @weakify(self);
  121. [LCHttpHelper requestWithURLString:GetTalkOnlineUser parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"endtime":self.youpaipendTime} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  122. @strongify(self);
  123. [self.youpaiptableView endRefreshing:kRefreshAll];
  124. NSDictionary* dict = (NSDictionary*)responseObject;
  125. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  126. if (code == 0) {//成功
  127. if (status != kRefreshFooter) {
  128. [self.youpaipdataSource removeAllObjects];
  129. }
  130. NSDictionary *data = [dict objectForKey:@"data"];
  131. NSArray <YOUPAILZChatRoomMemberModel *>*list = [YOUPAILZChatRoomMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  132. [self.youpaipdataSource addObjectsFromArray:list];
  133. [self.youpaiptableView reloadData];
  134. self.youpaipendTime = [data objectForKey:@"end_time"];
  135. [self youpaifrefreshFooterWithHidden:NO];
  136. }
  137. } failure:^(NSError *error) {
  138. @strongify(self);
  139. [self.youpaiptableView endRefreshing:kRefreshAll];
  140. }];
  141. }
  142. - (NSMutableArray<YOUPAILZChatRoomMemberModel *> *)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