jsdw_ios/QuickLocation/Section/Schedule/ScheduleVC.swift

126 lines
3.9 KiB
Swift

//
// ScheduleVC.swift
// QuickLocation
//
// Created by on 2026/6/23.
//
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
import MJRefresh
import ObjectMapper
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()
requestFollowList()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestData()
}
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)
rootView.tableView.rx.modelSelected(ScheduleModel.self)
.subscribe(viewModel.cellAction.inputs)
.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<ViewedListSectionModel> = {
RxCollectionViewSectionedReloadDataSource<ViewedListSectionModel> { datasource, collectionView, indexPath, model in
let cell: ViewedCell = collectionView.dequeueReusableCell(for: indexPath)
cell.configure(model)
return cell
}
}()
// MARK: - UITableViewDataSource
lazy private var tableViewDataSource: RxTableViewSectionedReloadDataSource<ScheduleListSectionModel> = {
return RxTableViewSectionedReloadDataSource<ScheduleListSectionModel>(
configureCell: { (_, tableView, indexPath, model) in
let cell: ScheduleListPopCell = tableView.dequeueReusableCell(for: indexPath)
cell.configure(model)
//
cell.editBtn.rx.tap.subscribe(onNext: { _ in
AppRouter.push(Route.createSchedule, userInfo: ["scheduleJson": model.toJSON()])
}).disposed(by: cell.disposeBag)
//
cell.followBtn.rx.tap.subscribe(onNext: { _ in
}).disposed(by: cell.disposeBag)
return cell
}
)
}()
}