// // ScheduleVC.swift // QuickLocation // // Created by 八条 on 2026/6/23. // import UIKit import RxSwift import RxCocoa import RxDataSources import MJRefresh class ScheduleVC: BaseViewController { fileprivate var rootView: ScheduleView! override func loadView() { rootView = ScheduleView(frame: UIScreen.main.bounds) view = rootView } private var viewModel = ScheduleViewModel() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. setupTableViewHeaderFooter() bindViewModel() reactiveAction() requestData() requestFollowList() } private func bindViewModel() { viewModel.output.sectionedItems .bind(to: rootView.collectionView.rx.items(dataSource: dataSource)) .disposed(by: disposeBag) viewModel.output.scheduleSectionedItems .bind(to: rootView.tableView.rx.items(dataSource: tableViewDataSource)) .disposed(by: disposeBag) viewModel.output.refreshResult.subscribe(onNext: { [weak self] (status, isEmpty) in guard let self = self else { return } self.dl.dismiss() self.rootView.tableView.refresh(status: status, isEmpty: isEmpty) }).disposed(by: disposeBag) } private func reactiveAction() { } private func setupTableViewHeaderFooter() { // 设置刷新header/footer let header = MJRefreshNormalHeader(refreshingBlock: { [weak self] in self?.viewModel.refresh() }) header.addFeedbackGenerator() header.stateLabel?.isHidden = true rootView.tableView.mj_header = header let footer = MJRefreshAutoNormalFooter(refreshingBlock: viewModel.loadMore) footer.isHidden = true rootView.tableView.mj_footer = footer } // MARK: - API private func requestFollowList() { dl.showLoading() UserService.followList().subscribe(onNext: { response in self.dl.dismiss() self.viewModel.loadViewedData(response.list) }, onError: { _ in }).disposed(by: disposeBag) } // MARK: - API 行程列表 private func requestData() { dl.showLoading() viewModel.refresh() } // MARK: - dataSource private lazy var dataSource: RxCollectionViewSectionedReloadDataSource = { RxCollectionViewSectionedReloadDataSource { datasource, collectionView, indexPath, model in let cell: ViewedCell = collectionView.dequeueReusableCell(for: indexPath) cell.configure(model) return cell } }() // MARK: - UITableViewDataSource lazy private var tableViewDataSource: RxTableViewSectionedReloadDataSource = { return RxTableViewSectionedReloadDataSource( configureCell: { (_, tableView, indexPath, model) in let cell: ScheduleListPopCell = tableView.dequeueReusableCell(for: indexPath) cell.configure(model) return cell } ) }() }