YOUPAILZChatRoomUpSeatApplyWindow.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // YOUPAILZChatRoomUpSeatApplyWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/11/6.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomUpSeatApplyWindow.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZChatRoomUpSeatApplyCell.h"
  11. @interface YOUPAILZChatRoomUpSeatApplyWindow ()<UITableViewDataSource,UITableViewDelegate>
  12. @property (nonatomic, weak)UITableView *youpaiptableView;
  13. @property (nonatomic, assign) NSInteger youpaippage;
  14. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomMemberModel *>*youpaipdataSource;
  15. @end
  16. @implementation YOUPAILZChatRoomUpSeatApplyWindow
  17. - (void)dealloc{
  18. [[NSNotificationCenter defaultCenter] removeObserver:self];
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.baseView.hidden = YES;
  23. [self youpaifinitUI];
  24. [self youpaifrequestUpSeatApplyListWithStatus:kRefreshNormal];
  25. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchatRoomConfirmSuccess:) name:@"ChatRoomConfirmSuccess" object:nil];
  26. }
  27. -(void)youpaifchatRoomConfirmSuccess:(NSNotification *)notify{
  28. NSString *userId = notify.userInfo[@"userId"];
  29. for (YOUPAILZChatRoomMemberModel *memberModel in self.youpaipdataSource) {
  30. if ([memberModel.youpaipid isEqual:userId]) {
  31. [self.youpaipdataSource removeObject:memberModel];
  32. [self.youpaiptableView reloadData];
  33. break;
  34. }
  35. }
  36. [self.youpaiptableView lz_hideEmptyView];
  37. if (self.youpaipdataSource.count == 0) {
  38. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"当前还没有人申请呢~"];
  39. }
  40. }
  41. - (void)youpaifinitUI{
  42. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 400.0f + SafeHeight)];
  43. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  44. [self.view addSubview:bgV];
  45. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.right.bottom.offset(0.0f);
  47. make.height.offset(400.0f + SafeHeight);
  48. }];
  49. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  50. UIView *navV = [[UIView alloc] init];
  51. [bgV addSubview:navV];
  52. [navV mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.right.top.offset(0.0f);
  54. make.height.offset(43.0f);
  55. }];
  56. [navV addLineWithColor:[[UIColor whiteColor] colorWithAlphaComponent:0.07f] lineRect:CGRectMake(0, 42.5f, KScreenWidth, 0.5f)];
  57. UILabel *titleL = [[UILabel alloc] init];
  58. titleL.text = @"上麦申请";
  59. titleL.textColor = [UIColor whiteColor];
  60. titleL.font = LCBoldFont(16.0f);
  61. [navV addSubview:titleL];
  62. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.center.equalTo(navV);
  64. }];
  65. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  66. tableView.delegate = self;
  67. tableView.dataSource = self;
  68. tableView.rowHeight = 60.0f;
  69. tableView.estimatedRowHeight = 60.0f;
  70. tableView.estimatedSectionHeaderHeight = 0.0f;
  71. tableView.estimatedSectionFooterHeight = 0.0f;
  72. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  73. tableView.backgroundColor = [UIColor clearColor];
  74. tableView.showsVerticalScrollIndicator = NO;
  75. [self.view addSubview:tableView];
  76. self.youpaiptableView = tableView;
  77. @weakify(self);
  78. [tableView setRefreshHeaderWithBlock:^{
  79. @strongify(self);
  80. [self youpaifrequestUpSeatApplyListWithStatus:kRefreshHeader];
  81. }];
  82. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.right.offset(0.0f);
  84. make.bottom.offset(-SafeHeight);
  85. make.top.equalTo(navV.mas_bottom).offset(0.0f);
  86. }];
  87. }
  88. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  89. return self.youpaipdataSource.count;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  92. NSString *cellID = @"YOUPAILZChatRoomUpSeatApplyCell";
  93. YOUPAILZChatRoomUpSeatApplyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  94. if (cell == nil) {
  95. cell = [[YOUPAILZChatRoomUpSeatApplyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  96. }
  97. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] index:indexPath.row playType:self.youpaipplayType];
  98. @weakify(self);
  99. [cell setYoupaipignoreBtnClickBlock:^(YOUPAILZChatRoomMemberModel * _Nonnull model, NSInteger index) {
  100. @strongify(self);
  101. [self youpaifignoreWithModel:model index:index];
  102. }];
  103. [cell setYoupaipupseatBtnClickBlock:^(YOUPAILZChatRoomMemberModel * _Nonnull model, NSInteger index) {
  104. @strongify(self);
  105. if (self.youpaipupseatBlock != nil) {
  106. self.youpaipupseatBlock(model);
  107. }
  108. }];
  109. return cell;
  110. }
  111. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  112. return CGFLOAT_MIN;
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  115. return CGFLOAT_MIN;
  116. }
  117. /// 忽略
  118. - (void)youpaifignoreWithModel:(YOUPAILZChatRoomMemberModel *)model index:(NSInteger)index{
  119. [self.youpaipdataSource removeObject:model];
  120. [self.youpaiptableView reloadData];
  121. [self.youpaiptableView lz_hideEmptyView];
  122. if (self.youpaipdataSource.count == 0) {
  123. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"当前还没有人申请呢~"];
  124. }
  125. [LCHttpHelper requestWithURLString:RejectApply parameters:@{@"room_id":self.youpaiproomId,@"op_uid":model.youpaipid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  126. } failure:^(NSError *error) {
  127. }];
  128. }
  129. /// 设置加载更多
  130. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  131. @weakify(self);
  132. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  133. @strongify(self);
  134. [self youpaifrequestUpSeatApplyListWithStatus:kRefreshFooter];
  135. }];
  136. }
  137. - (void)youpaifrequestUpSeatApplyListWithStatus:(kRefreshStatus)status{
  138. if (status == kRefreshFooter) {
  139. self.youpaippage ++;
  140. }else{
  141. self.youpaippage = 1;
  142. }
  143. @weakify(self);
  144. [LCHttpHelper requestWithURLString:ApplyList parameters:@{@"page":@(self.youpaippage),@"room_id":self.youpaiproomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  145. @strongify(self);
  146. [self.youpaiptableView endRefreshing:kRefreshAll];
  147. NSDictionary* dict = (NSDictionary*)responseObject;
  148. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  149. if (code == 0) {//成功
  150. if (status != kRefreshFooter) {
  151. [self.youpaipdataSource removeAllObjects];
  152. }
  153. NSDictionary *data = [dict objectForKey:@"data"];
  154. NSArray <YOUPAILZChatRoomMemberModel *>*list = [YOUPAILZChatRoomMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  155. [self.youpaipdataSource addObjectsFromArray:list];
  156. [self.youpaiptableView reloadData];
  157. [self.youpaiptableView lz_hideEmptyView];
  158. if (self.youpaipdataSource.count == 0) {
  159. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"当前还没有人申请呢~"];
  160. }
  161. NSInteger totalPage = [[data objectForKey:@"total_page"] integerValue];
  162. [self youpaifrefreshFooterWithHidden:self.youpaippage >= totalPage];
  163. }
  164. } failure:^(NSError *error) {
  165. @strongify(self);
  166. [self.youpaiptableView endRefreshing:kRefreshAll];
  167. }];
  168. }
  169. - (NSMutableArray<YOUPAILZChatRoomMemberModel *> *)youpaipdataSource{
  170. if (!_youpaipdataSource) {
  171. _youpaipdataSource = [NSMutableArray array];
  172. }
  173. return _youpaipdataSource;
  174. }
  175. @end