// // ScheduleViewModel.swift // QuickLocation // // Created by 八条 on 2026/6/23. // import RxSwift import RxCocoa import RxDataSources import MJRefresh import ObjectMapper typealias ViewedListSectionModel = SectionModel typealias ScheduleListSectionModel = AnimatableSectionModel class ScheduleViewModel: ViewModelType { struct Input {} struct Output { var sectionedItems: Observable<[ViewedListSectionModel]> var scheduleSectionedItems: Observable<[ScheduleListSectionModel]> var refreshResult: Observable var pagination: Observable var error: Observable } let input: Input let output: Output private var listService: ListService private let sectionedItems = PublishSubject<[ViewedListSectionModel]>() private let scheduleSectionedItems = PublishSubject<[ScheduleListSectionModel]>() var refresh: MJRefreshComponentAction { return { self.listService.request.onNext(.refresh) } } var loadMore: MJRefreshComponentAction { return { self.listService.request.onNext(.more) } } func loadViewedData(_ list: [ViewedModel]) { sectionedItems.onNext(list.mapSection()) } lazy var viewedCellAction: Action = { this in return Action { model in AppRouter.push(Route.scheduleViewed) return .empty() } }(self) lazy var cellAction: Action = { this in return Action { model in AppRouter.push(Route.scheduleDetail, userInfo: ["scheduleJson": model.toJSON()]) return .empty() } }(self) /// 切换条件 /// - Parameters: /// - follow: 只查看关注的行程 /// - own: 只查看自己创建的行程 /// - history: true查看历史行程,默认查看今天之后的行程 /// - group_key: 过滤圈子查询 func changeCondition(follow: Bool, own: Bool) { listService.targetTransform = { page in ItineraryAPI.query(follow: follow, own: own, history: false, group_key: "", page: page).multiTarget } } // MARK: - init init() { listService = ItineraryService.query() input = Input() output = Output( sectionedItems: sectionedItems.asObservable(), scheduleSectionedItems: listService.animatableSectionedItems, refreshResult: listService.refreshResult, pagination: listService.pagination, error: listService.error ) } }