YMGuildManagementMyConnectionsViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // YMGuildManagementMyConnectionsViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/26.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMGuildManagementMyConnectionsViewController.h"
  9. #import "YMGuildManagementMyConnectionsViewModel.h"
  10. #import "GHMemberTableViewCell.h"
  11. @interface YMGuildManagementMyConnectionsViewController ()<UITableViewDataSource, UITableViewDelegate>
  12. /// 列表VM
  13. @property (nonatomic, strong) YMGuildManagementMyConnectionsViewModel *viewModel;
  14. /// 容器列表
  15. @property (nonatomic, strong) UITableView *contentTableView;
  16. @property (nonatomic, strong) UIView *topView;
  17. @property (nonatomic, strong) UILabel *topLabel;
  18. @end
  19. @implementation YMGuildManagementMyConnectionsViewController
  20. @dynamic viewModel;
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self.view addSubview:self.topView];
  24. [self.topView addSubview:self.topLabel];
  25. [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.top.equalTo(self.view).offset(kYMNavHeight);
  27. make.left.equalTo(self.view).offset(10);
  28. make.right.equalTo(self.view).offset(-10);
  29. make.height.mas_equalTo(adapt(36));
  30. }];
  31. [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.center.equalTo(self.topView);
  33. }];
  34. }
  35. - (void)ym_setupViews {
  36. [self.view addSubview:self.contentTableView];
  37. [self.view setNeedsUpdateConstraints];
  38. [self.view updateConstraintsIfNeeded];
  39. }
  40. - (void)updateViewConstraints {
  41. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.equalTo(self.topView.mas_bottom).offset(10);
  43. make.left.equalTo(self.view);
  44. make.right.equalTo(self.view);
  45. make.bottom.equalTo(self.view);
  46. }];
  47. [super updateViewConstraints];
  48. }
  49. - (void)ym_bindViewModel {
  50. [self headerRefreshing];
  51. @weakify(self)
  52. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  53. @strongify(self)
  54. [self.contentTableView reloadData];
  55. switch ([result intValue]) {
  56. case YMHeaderRefresh_HasMoreData:
  57. case YMHeaderRefresh_HasNoMoreData:
  58. {
  59. [self.contentTableView.mj_header endRefreshing];
  60. [self.contentTableView.mj_footer endRefreshing];
  61. }
  62. break;
  63. case YMFooterRefresh_HasMoreData:
  64. {
  65. [self.contentTableView.mj_header endRefreshing];
  66. [self.contentTableView.mj_footer endRefreshing];
  67. if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
  68. self.contentTableView.mj_footer = self.loadMoreFooter;
  69. }
  70. }
  71. break;
  72. case YMFooterRefresh_HasNoMoreData:
  73. {
  74. [self.contentTableView.mj_header endRefreshing];
  75. [self.contentTableView.mj_footer endRefreshing];
  76. if (self.contentTableView.mj_footer == self.loadMoreFooter) {
  77. self.contentTableView.mj_footer = self.noLoadMoreFooter;
  78. }
  79. }
  80. break;
  81. case YMRefreshError: {
  82. [self.contentTableView.mj_header endRefreshing];
  83. [self.contentTableView.mj_footer endRefreshing];
  84. }
  85. break;
  86. default:
  87. break;
  88. }
  89. [self.contentTableView ym_endLoading];
  90. }];
  91. [[[[RACObserve(self.viewModel, memberNumber) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * memberNumber) {
  92. @strongify(self)
  93. //self.topLabel.text = [NSString stringWithFormat:@"公会人数%@人",memberNumber];
  94. NSString *str = [NSString stringWithFormat:@"公会人数%@人",memberNumber];
  95. NSString *numStr = [NSString stringWithFormat:@"%@",memberNumber];
  96. NSRange range = [str rangeOfString:numStr];
  97. NSMutableAttributedString *attrStrm = [[NSMutableAttributedString alloc] initWithString:str];
  98. [attrStrm addAttributes:@{NSForegroundColorAttributeName: HexColorFromRGBA(0xFF4A92, 1)} range:range];
  99. self.topLabel.attributedText = attrStrm;
  100. }];
  101. }
  102. #pragma mark - UITableViewDataSource
  103. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  104. return 1;
  105. }
  106. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  107. return self.viewModel.listDataArray.count;
  108. }
  109. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  110. GHMemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GHMemberTableViewCell"];
  111. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  112. [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
  113. return cell;
  114. }
  115. #pragma mark - UITableViewDelegate
  116. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  117. return nil;
  118. }
  119. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  120. return CGFLOAT_MIN;
  121. }
  122. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  123. return nil;
  124. }
  125. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  126. return CGFLOAT_MIN;
  127. }
  128. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  129. [self.viewModel.gotoPersonalPageSubject sendNext:self.viewModel.listDataArray[indexPath.item].Id];
  130. }
  131. - (void)headerRefreshing{
  132. [self.contentTableView ym_startLoading];
  133. self.viewModel.currentPage = 1;
  134. [self.viewModel getMyConnectionsListData];
  135. }
  136. - (void)footerRefreshing{
  137. [self.contentTableView ym_startLoading];
  138. self.viewModel.currentPage++;
  139. [self.viewModel getMyConnectionsListData];
  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.rowHeight = UITableViewAutomaticDimension;
  147. _contentTableView.estimatedRowHeight = adapt(44);
  148. _contentTableView.showsVerticalScrollIndicator = NO;
  149. _contentTableView.showsHorizontalScrollIndicator = NO;
  150. _contentTableView.separatorColor = UIColor.clearColor;
  151. _contentTableView.rowHeight = 95;
  152. [_contentTableView registerNib:[UINib nibWithNibName:@"GHMemberTableViewCell" bundle:[NSBundle bundleForClass:[GHMemberTableViewCell class]]] forCellReuseIdentifier:@"GHMemberTableViewCell"];
  153. _contentTableView.mj_header = self.refreshHeader;
  154. _contentTableView.mj_footer = self.noLoadMoreFooter;
  155. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
  156. empty.imageSize = kEmptyViewSize;
  157. _contentTableView.ym_emptyView = empty;
  158. _contentTableView.ym_emptyView.autoShowEmptyView = NO;
  159. }
  160. return _contentTableView;
  161. }
  162. - (UIView*)topView{
  163. if(!_topView){
  164. _topView = [[UIView alloc] init];
  165. _topView.backgroundColor = HexColorFromRGBA(0xFF76C0, 0.2);
  166. _topView.layer.cornerRadius = 12;
  167. _topView.layer.masksToBounds = YES;
  168. }
  169. return _topView;
  170. }
  171. - (UILabel*)topLabel{
  172. if(!_topLabel){
  173. _topLabel = [[UILabel alloc] init];
  174. _topLabel.text = @"";
  175. _topLabel.font = LCFont(16);
  176. _topLabel.textAlignment = NSTextAlignmentCenter;
  177. _topLabel.textColor = UIColor.blackColor;
  178. }
  179. return _topLabel;
  180. }
  181. @end