100 lines
3.5 KiB
Swift
100 lines
3.5 KiB
Swift
//
|
|
// ScheduleDetailVC.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/25.
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxDataSources
|
|
import ObjectMapper
|
|
|
|
class ScheduleDetailVC: BaseViewController {
|
|
|
|
fileprivate var rootView: ScheduleDetailView!
|
|
|
|
override func loadView() {
|
|
rootView = ScheduleDetailView(frame: UIScreen.main.bounds)
|
|
view = rootView
|
|
}
|
|
|
|
private var viewModel: ScheduleDetailViewModel
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
setupData()
|
|
bindViewModel()
|
|
requestFollowList()
|
|
|
|
viewModel.loadPointData()
|
|
}
|
|
|
|
private func bindViewModel() {
|
|
viewModel.output.sectionedItems
|
|
.bind(to: rootView.collectionView.rx.items(dataSource: dataSource))
|
|
.disposed(by: disposeBag)
|
|
|
|
viewModel.output.pointSectionedItems
|
|
.bind(to: rootView.tableView.rx.items(dataSource: tableViewDataSource))
|
|
.disposed(by: disposeBag)
|
|
}
|
|
|
|
private func setupData() {
|
|
guard let model = viewModel.scheduModel else { return }
|
|
rootView.dateLab.text = rootView.dateLab.getDateInterval2String(date: "\(model.timestamp / 1000)", dateFormat: "yyyy年MM月dd日")
|
|
rootView.creatorIcon.image = model.userIcon
|
|
}
|
|
|
|
// MARK: - API
|
|
private func requestFollowList() {
|
|
dl.showLoading()
|
|
UserService.followList().subscribe(onNext: { response in
|
|
self.dl.dismiss()
|
|
self.viewModel.loadViewedData(response.list)
|
|
self.rootView.noDataLab.isHidden = response.list.count > 0
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}()
|
|
|
|
lazy private var tableViewDataSource: RxTableViewSectionedReloadDataSource<SchedulePointDetailSectionModel> = {
|
|
return RxTableViewSectionedReloadDataSource<SchedulePointDetailSectionModel>(
|
|
configureCell: { (dataSource, tableView, indexPath, item) in
|
|
switch item {
|
|
case let .point(model):
|
|
let cell: SchedulePointDetailCell = tableView.dequeueReusableCell(for: indexPath)
|
|
cell.configure(model: model, index: indexPath.section, total: dataSource.sectionModels.count)
|
|
return cell
|
|
case let .event(model):
|
|
let cell: SchedulePointEventCell = tableView.dequeueReusableCell(for: indexPath)
|
|
cell.configure(model: model, index: indexPath.section, total: dataSource.sectionModels.count)
|
|
return cell
|
|
}
|
|
}
|
|
)
|
|
}()
|
|
|
|
// MARK: - Init
|
|
init(routeId: String, scheduleJson: [String: Any]) {
|
|
self.viewModel = ScheduleDetailViewModel(routeId: routeId,
|
|
model: scheduleJson.isEmpty ? nil : ScheduleModel.init(JSON: scheduleJson))
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|