YMGuestViewController.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // YMGuestViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMGuestViewController.h"
  9. #import "YMGuestViewModel.h"
  10. #import "YMGuestCell.h"
  11. #import "YMGuestUnlockPopupView.h"
  12. @interface YMGuestViewController()<UITableViewDataSource, UITableViewDelegate>
  13. /// 粉丝VM
  14. @property (nonatomic, strong) YMGuestViewModel *viewModel;
  15. /// 内容列表
  16. @property (nonatomic, strong) UITableView *contentTableView;
  17. /// 遮罩基础视图
  18. @property (nonatomic, strong) UIView *maskView;
  19. /// 模糊遮罩视图
  20. @property (nonatomic, strong) YMCustomEffectView *blurMaskView;
  21. /// 解锁全部访客按钮
  22. @property (nonatomic, strong) UIButton *unlockGuestBtn;
  23. @end
  24. @implementation YMGuestViewController
  25. @dynamic viewModel;
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated{
  30. [super viewWillAppear:animated];
  31. self.maskView.hidden = [self.viewModel isHideMaskView];
  32. }
  33. - (void)ym_setupViews{
  34. [self.view addSubview:self.contentTableView];
  35. [self.view addSubview:self.maskView];
  36. [self.maskView addSubview:self.blurMaskView];
  37. [self.maskView addSubview:self.unlockGuestBtn];
  38. [self.view setNeedsUpdateConstraints];
  39. [self.view updateConstraintsIfNeeded];
  40. }
  41. - (void)updateViewConstraints{
  42. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.equalTo(self.view).offset(kYMNavHeight);
  44. make.left.equalTo(self.view);
  45. make.right.equalTo(self.view);
  46. make.bottom.equalTo(self.view);
  47. }];
  48. [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.view).offset(kYMNavHeight);
  50. make.left.equalTo(self.view);
  51. make.right.equalTo(self.view);
  52. make.bottom.equalTo(self.view);
  53. }];
  54. [self.blurMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(self.maskView);
  56. make.left.equalTo(self.maskView);
  57. make.right.equalTo(self.maskView);
  58. make.bottom.equalTo(self.maskView);
  59. }];
  60. [self.unlockGuestBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.equalTo(self.maskView).offset(adapt(24));
  62. make.right.equalTo(self.maskView).offset(adapt(-24));
  63. make.bottom.equalTo(self.maskView).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  64. make.height.mas_equalTo(adapt(45));
  65. }];
  66. [super updateViewConstraints];
  67. }
  68. - (void)ym_bindViewModel{
  69. [self headerRefreshing];
  70. @weakify(self)
  71. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  72. @strongify(self)
  73. [self.contentTableView reloadData];
  74. switch ([result intValue]) {
  75. case YMHeaderRefresh_HasMoreData:
  76. case YMHeaderRefresh_HasNoMoreData:
  77. {
  78. [self.contentTableView.mj_header endRefreshing];
  79. [self.contentTableView.mj_footer endRefreshing];
  80. }
  81. break;
  82. case YMFooterRefresh_HasMoreData:
  83. {
  84. [self.contentTableView.mj_header endRefreshing];
  85. [self.contentTableView.mj_footer endRefreshing];
  86. if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
  87. self.contentTableView.mj_footer = self.loadMoreFooter;
  88. }
  89. }
  90. break;
  91. case YMFooterRefresh_HasNoMoreData:
  92. {
  93. [self.contentTableView.mj_header endRefreshing];
  94. [self.contentTableView.mj_footer endRefreshing];
  95. if (self.contentTableView.mj_footer == self.loadMoreFooter) {
  96. self.contentTableView.mj_footer = self.noLoadMoreFooter;
  97. }
  98. }
  99. break;
  100. case YMRefreshError: {
  101. [self.contentTableView.mj_header endRefreshing];
  102. [self.contentTableView.mj_footer endRefreshing];
  103. }
  104. break;
  105. default:
  106. break;
  107. }
  108. [self.contentTableView ym_endLoading];
  109. }];
  110. }
  111. - (void)headerRefreshing{
  112. [self.contentTableView ym_startLoading];
  113. self.viewModel.currentPage = 1;
  114. [self.viewModel getGuestListData];
  115. }
  116. - (void)footerRefreshing{
  117. [self.contentTableView ym_startLoading];
  118. self.viewModel.currentPage++;
  119. [self.viewModel getGuestListData];
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  122. return self.viewModel.listDataArray.count;
  123. }
  124. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  125. YMGuestCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMGuestCell class])];
  126. if (!cell) {
  127. cell = [[YMGuestCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMGuestCell class])];
  128. }
  129. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  130. [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
  131. return cell;
  132. }
  133. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. return adapt(85);
  135. }
  136. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  137. if (self.viewModel.listDataArray[indexPath.item].userId != 0) {
  138. [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)];
  139. }
  140. }
  141. - (UITableView *)contentTableView{
  142. if (!_contentTableView) {
  143. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  144. _contentTableView.delegate = self;
  145. _contentTableView.dataSource = self;
  146. _contentTableView.estimatedRowHeight = 0;
  147. _contentTableView.estimatedSectionHeaderHeight = 0;
  148. _contentTableView.estimatedSectionFooterHeight = 0;
  149. _contentTableView.showsVerticalScrollIndicator = NO;
  150. _contentTableView.showsHorizontalScrollIndicator = NO;
  151. _contentTableView.separatorColor = UIColor.clearColor;
  152. _contentTableView.backgroundColor = UIColor.whiteColor;
  153. [_contentTableView registerClass:[YMGuestCell class] forCellReuseIdentifier:NSStringFromClass([YMGuestCell class])];
  154. _contentTableView.mj_header = self.refreshHeader;
  155. _contentTableView.mj_footer = self.noLoadMoreFooter;
  156. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
  157. empty.imageSize = kEmptyViewSize;
  158. _contentTableView.ym_emptyView = empty;
  159. _contentTableView.ym_emptyView.autoShowEmptyView = NO;
  160. }
  161. return _contentTableView;
  162. }
  163. - (UIView *)maskView{
  164. if (!_maskView) {
  165. _maskView = [[UIView alloc]init];
  166. _maskView.hidden = YES;
  167. }
  168. return _maskView;
  169. }
  170. - (YMCustomEffectView *)blurMaskView{
  171. if (!_blurMaskView) {
  172. UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight];
  173. _blurMaskView = [[YMCustomEffectView alloc]initWithEffect:blurEffect intensity:0.15];
  174. _blurMaskView.userInteractionEnabled = YES;
  175. WS(weakSelf)
  176. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  177. [_blurMaskView addGestureRecognizer:tap];
  178. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  179. weakSelf.unlockGuestBtn.hidden = YES;
  180. YMGuestUnlockPopupView *customView = [[YMGuestUnlockPopupView alloc]init];
  181. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:weakSelf.maskView popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  182. popupView.priority = 999;
  183. popupView.cornerRadius = adapt(10);
  184. popupView.rectCorners = UIRectCornerAllCorners;
  185. popupView.positionStyle = YMPositionStyleCenter;
  186. popupView.isHideBg = NO;
  187. popupView.bgAlpha = 0.5;
  188. @weakify(popupView)
  189. customView.buttonBlock = ^(BOOL isConfirm) {
  190. @strongify(popupView)
  191. if (isConfirm) {
  192. if ([weakSelf.viewModel isNeedPurchaseMember]) {
  193. return;
  194. }
  195. }
  196. weakSelf.unlockGuestBtn.hidden = NO;
  197. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  198. };
  199. [popupView pop];
  200. }];
  201. }
  202. return _blurMaskView;
  203. }
  204. - (UIButton *)unlockGuestBtn{
  205. if (!_unlockGuestBtn) {
  206. _unlockGuestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  207. _unlockGuestBtn.titleLabel.font = LCFont(15);
  208. [_unlockGuestBtn setTitle:@"解锁全部访客" forState:UIControlStateNormal];
  209. [_unlockGuestBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
  210. _unlockGuestBtn.layer.cornerRadius = adapt(10);
  211. [_unlockGuestBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  212. WS(weakSelf)
  213. [[[_unlockGuestBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  214. if ([weakSelf.viewModel isNeedPurchaseMember]) {
  215. return;
  216. }
  217. }];
  218. }
  219. return _unlockGuestBtn;
  220. }
  221. @end