// // YMGuildManagementMyConnectionsViewController.m // MSYOUPAI // // Created by YoMi on 2024/3/26. // Copyright © 2024 MS. All rights reserved. // #import "YMGuildManagementMyConnectionsViewController.h" #import "YMGuildManagementMyConnectionsViewModel.h" #import "GHMemberTableViewCell.h" @interface YMGuildManagementMyConnectionsViewController () /// 列表VM @property (nonatomic, strong) YMGuildManagementMyConnectionsViewModel *viewModel; /// 容器列表 @property (nonatomic, strong) UITableView *contentTableView; @property (nonatomic, strong) UIView *topView; @property (nonatomic, strong) UILabel *topLabel; @end @implementation YMGuildManagementMyConnectionsViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.topView]; [self.topView addSubview:self.topLabel]; [self.topView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(kYMNavHeight); make.left.equalTo(self.view).offset(10); make.right.equalTo(self.view).offset(-10); make.height.mas_equalTo(adapt(36)); }]; [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.topView); }]; } - (void)ym_setupViews { [self.view addSubview:self.contentTableView]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints { [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.topView.mas_bottom).offset(10); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel { [self headerRefreshing]; @weakify(self) [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) { @strongify(self) [self.contentTableView reloadData]; switch ([result intValue]) { case YMHeaderRefresh_HasMoreData: case YMHeaderRefresh_HasNoMoreData: { [self.contentTableView.mj_header endRefreshing]; [self.contentTableView.mj_footer endRefreshing]; } break; case YMFooterRefresh_HasMoreData: { [self.contentTableView.mj_header endRefreshing]; [self.contentTableView.mj_footer endRefreshing]; if (self.contentTableView.mj_footer == self.noLoadMoreFooter) { self.contentTableView.mj_footer = self.loadMoreFooter; } } break; case YMFooterRefresh_HasNoMoreData: { [self.contentTableView.mj_header endRefreshing]; [self.contentTableView.mj_footer endRefreshing]; if (self.contentTableView.mj_footer == self.loadMoreFooter) { self.contentTableView.mj_footer = self.noLoadMoreFooter; } } break; case YMRefreshError: { [self.contentTableView.mj_header endRefreshing]; [self.contentTableView.mj_footer endRefreshing]; } break; default: break; } [self.contentTableView ym_endLoading]; }]; [[[[RACObserve(self.viewModel, memberNumber) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * memberNumber) { @strongify(self) //self.topLabel.text = [NSString stringWithFormat:@"公会人数%@人",memberNumber]; NSString *str = [NSString stringWithFormat:@"公会人数%@人",memberNumber]; NSString *numStr = [NSString stringWithFormat:@"%@",memberNumber]; NSRange range = [str rangeOfString:numStr]; NSMutableAttributedString *attrStrm = [[NSMutableAttributedString alloc] initWithString:str]; [attrStrm addAttributes:@{NSForegroundColorAttributeName: HexColorFromRGBA(0xFF4A92, 1)} range:range]; self.topLabel.attributedText = attrStrm; }]; } #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.viewModel.listDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ GHMemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GHMemberTableViewCell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]]; return cell; } #pragma mark - UITableViewDelegate - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return CGFLOAT_MIN; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.viewModel.gotoPersonalPageSubject sendNext:self.viewModel.listDataArray[indexPath.item].Id]; } - (void)headerRefreshing{ [self.contentTableView ym_startLoading]; self.viewModel.currentPage = 1; [self.viewModel getMyConnectionsListData]; } - (void)footerRefreshing{ [self.contentTableView ym_startLoading]; self.viewModel.currentPage++; [self.viewModel getMyConnectionsListData]; } - (UITableView *)contentTableView{ if (!_contentTableView) { _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _contentTableView.delegate = self; _contentTableView.dataSource = self; _contentTableView.rowHeight = UITableViewAutomaticDimension; _contentTableView.estimatedRowHeight = adapt(44); _contentTableView.showsVerticalScrollIndicator = NO; _contentTableView.showsHorizontalScrollIndicator = NO; _contentTableView.separatorColor = UIColor.clearColor; _contentTableView.rowHeight = 95; [_contentTableView registerNib:[UINib nibWithNibName:@"GHMemberTableViewCell" bundle:[NSBundle bundleForClass:[GHMemberTableViewCell class]]] forCellReuseIdentifier:@"GHMemberTableViewCell"]; _contentTableView.mj_header = self.refreshHeader; _contentTableView.mj_footer = self.noLoadMoreFooter; YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""]; empty.imageSize = kEmptyViewSize; _contentTableView.ym_emptyView = empty; _contentTableView.ym_emptyView.autoShowEmptyView = NO; } return _contentTableView; } - (UIView*)topView{ if(!_topView){ _topView = [[UIView alloc] init]; _topView.backgroundColor = HexColorFromRGBA(0xFF76C0, 0.2); _topView.layer.cornerRadius = 12; _topView.layer.masksToBounds = YES; } return _topView; } - (UILabel*)topLabel{ if(!_topLabel){ _topLabel = [[UILabel alloc] init]; _topLabel.text = @""; _topLabel.font = LCFont(16); _topLabel.textAlignment = NSTextAlignmentCenter; _topLabel.textColor = UIColor.blackColor; } return _topLabel; } @end