// // YMSpoorViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/17. // Copyright © 2024 MS. All rights reserved. // #import "YMSpoorViewController.h" #import "YMSpoorViewModel.h" #import "YMSpoorCell.h" @interface YMSpoorViewController() /// 粉丝VM @property (nonatomic, strong) YMSpoorViewModel *viewModel; /// 内容列表 @property (nonatomic, strong) UITableView *contentTableView; @end @implementation YMSpoorViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; } - (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.view).offset(kYMNavHeight); 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]; }]; } - (void)headerRefreshing{ [self.contentTableView ym_startLoading]; self.viewModel.currentPage = 1; [self.viewModel getSpoorListData]; } - (void)footerRefreshing{ [self.contentTableView ym_startLoading]; self.viewModel.currentPage++; [self.viewModel getSpoorListData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.viewModel.listDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YMSpoorCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMSpoorCell class])]; if (!cell) { cell = [[YMSpoorCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMSpoorCell class])]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; YMSpoorCellViewModel *cellVM = self.viewModel.listDataArray[indexPath.item]; @weakify(self) cellVM.changeAccostStatusBlock = ^{ @strongify(self) [UIView performWithoutAnimation:^{ [self.contentTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; }; [cell ym_bindViewModel:cellVM]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return adapt(70); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.viewModel.listDataArray[indexPath.item].userId != 0) { [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)]; } } - (UITableView *)contentTableView{ if (!_contentTableView) { _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _contentTableView.delegate = self; _contentTableView.dataSource = self; _contentTableView.estimatedRowHeight = 0; _contentTableView.estimatedSectionHeaderHeight = 0; _contentTableView.estimatedSectionFooterHeight = 0; _contentTableView.showsVerticalScrollIndicator = NO; _contentTableView.showsHorizontalScrollIndicator = NO; _contentTableView.separatorColor = UIColor.clearColor; _contentTableView.backgroundColor = UIColor.whiteColor; [_contentTableView registerClass:[YMSpoorCell class] forCellReuseIdentifier:NSStringFromClass([YMSpoorCell class])]; _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; } @end