YOUPAIHRChatRoomContributeDetailVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // YOUPAIHRChatRoomContributeDetailVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/11/3.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomContributeDetailVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZChatRoomInviationUpSeatCell.h"
  11. #import "YOUPAILZChatRoomCurrentMemberView.h"
  12. @interface YOUPAIHRChatRoomContributeDetailVC () <UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, weak) UITableView *youpaiptableView;
  14. @property (nonatomic, assign) NSInteger youpaippage;
  15. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomMemberModel *>*youpaipdataSource;
  16. @property (nonatomic, weak) YOUPAILZChatRoomCurrentMemberView *youpaipfooterView;
  17. @end
  18. @implementation YOUPAIHRChatRoomContributeDetailVC
  19. - (void)dealloc{
  20. [[NSNotificationCenter defaultCenter] removeObserver:self];
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self youpaifinitUI];
  25. /// 关注状态改变,接收通知
  26. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  27. [self youpaifrequestRankListWithStatus:kRefreshNormal];
  28. }
  29. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  30. NSDictionary *dict = [notification userInfo];
  31. NSString *idStr = dict[@"follow_uid"];
  32. NSInteger isfollow = [dict[@"is_follow"] intValue];
  33. NSArray *arr = self.youpaipdataSource;
  34. NSMutableArray *arrM = [NSMutableArray new];
  35. if (arr.count>0) {
  36. for (int i = 0; i<arr.count; i++) {
  37. YOUPAILZChatRoomMemberModel *model = arr[i];
  38. if ([model.youpaipid isEqualToString:idStr]) {
  39. model.youpaipis_follow = isfollow;
  40. }
  41. [arrM addObject:model];
  42. }
  43. [self.youpaipdataSource removeAllObjects];
  44. self.youpaipdataSource = arrM;
  45. [self.youpaiptableView reloadData];
  46. }
  47. }
  48. - (void)youpaifinitUI{
  49. YOUPAILZChatRoomCurrentMemberView *youpaipfooterView = [[YOUPAILZChatRoomCurrentMemberView alloc] init];
  50. youpaipfooterView.backgroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth, 60.0f + SafeHeight) FromColors:@[HexColorFromRGB(0xE41E84),HexColorFromRGB(0xEE6942)] ByGradientType:GradientLeftToRight]];
  51. [self.view addSubview:youpaipfooterView];
  52. self.youpaipfooterView = youpaipfooterView;
  53. [youpaipfooterView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.bottom.right.offset(0.0f);
  55. make.height.offset(60.0f + SafeHeight);
  56. }];
  57. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  58. tableView.delegate = self;
  59. tableView.dataSource = self;
  60. tableView.rowHeight = 60.0f;
  61. tableView.estimatedRowHeight = 60.0f;
  62. tableView.estimatedSectionHeaderHeight = 0.0f;
  63. tableView.estimatedSectionFooterHeight = 0.0f;
  64. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  65. tableView.backgroundColor = [UIColor clearColor];
  66. [self.view addSubview:tableView];
  67. self.youpaiptableView = tableView;
  68. @weakify(self);
  69. [tableView setRefreshHeaderWithBlock:^{
  70. @strongify(self);
  71. [self youpaifrequestRankListWithStatus:kRefreshHeader];
  72. }];
  73. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.top.right.offset(0.0f);
  75. make.bottom.equalTo(self.youpaipfooterView.mas_top);
  76. }];
  77. }
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  79. return self.youpaipdataSource.count;
  80. }
  81. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  82. NSString *cellID = @"YOUPAILZChatRoomInviationUpSeatCell";
  83. YOUPAILZChatRoomInviationUpSeatCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  84. if (cell == nil) {
  85. cell = [[YOUPAILZChatRoomInviationUpSeatCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  86. }
  87. NSString *contributionName = @"贡献值";
  88. if (self.youpaiptype == 1) {
  89. contributionName = @"魅力值";
  90. }
  91. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] index:indexPath.row buttonType:LZChatRoomInviationUpSeatCellButtonTypeWithFollow rankType:LZChatRoomInviationUpSeatCellRankTypeWithTopThree contributionName:contributionName];
  92. return cell;
  93. }
  94. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  95. return CGFLOAT_MIN;
  96. }
  97. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  98. return CGFLOAT_MIN;
  99. }
  100. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  101. if (self.youpaiptouchUserBlock != nil) {
  102. self.youpaiptouchUserBlock(self.youpaipdataSource[indexPath.row].youpaipid);
  103. }
  104. }
  105. /// 设置加载更多
  106. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  107. @weakify(self);
  108. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  109. @strongify(self);
  110. [self youpaifrequestRankListWithStatus:kRefreshFooter];
  111. }];
  112. }
  113. - (void)youpaifrequestRankListWithStatus:(kRefreshStatus)status{
  114. if (status == kRefreshFooter) {
  115. self.youpaippage ++;
  116. }else{
  117. self.youpaippage = 1;
  118. }
  119. @weakify(self);
  120. [LCHttpHelper requestWithURLString:GetTalkUserRank parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"page":@(self.youpaippage),@"type":@(self.youpaiptype)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  121. @strongify(self);
  122. [self.youpaiptableView endRefreshing:kRefreshAll];
  123. NSDictionary* dict = (NSDictionary*)responseObject;
  124. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  125. if (code == 0) {//成功
  126. if (status != kRefreshFooter) {
  127. [self.youpaipdataSource removeAllObjects];
  128. }
  129. NSDictionary *data = [dict objectForKey:@"data"];
  130. NSArray <YOUPAILZChatRoomMemberModel *>*list = [YOUPAILZChatRoomMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  131. [self.youpaipdataSource addObjectsFromArray:list];
  132. [self.youpaiptableView reloadData];
  133. YOUPAILZChatRoomMemberModel *youpaipmemberModel = [YOUPAILZChatRoomMemberModel mj_objectWithKeyValues:[data objectForKey:@"current"]];
  134. NSString *contributionName = @"贡献值";
  135. if (self.youpaiptype == 1) {
  136. contributionName = @"魅力值";
  137. }
  138. [self.youpaipfooterView youpaifreloadWithModel:youpaipmemberModel contributionName:contributionName];
  139. NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue];
  140. [self youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
  141. }
  142. } failure:^(NSError *error) {
  143. @strongify(self);
  144. [self.youpaiptableView endRefreshing:kRefreshAll];
  145. }];
  146. }
  147. - (NSMutableArray<YOUPAILZChatRoomMemberModel *> *)youpaipdataSource{
  148. if (!_youpaipdataSource) {
  149. _youpaipdataSource = [NSMutableArray array];
  150. }
  151. return _youpaipdataSource;
  152. }
  153. #pragma mark - JXCategoryListContentViewDelegate
  154. - (UIView *)listView{
  155. return self.view;
  156. }
  157. @end