jsdw_ios/QuickLocation/Section/Schedule/ScheduleViewModel.swift

91 lines
2.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ScheduleViewModel.swift
// QuickLocation
//
// Created by on 2026/6/23.
//
import RxSwift
import RxCocoa
import RxDataSources
import MJRefresh
import ObjectMapper
typealias ViewedListSectionModel = SectionModel<String, ViewedModel>
typealias ScheduleListSectionModel = AnimatableSectionModel<String, ScheduleModel>
class ScheduleViewModel: ViewModelType {
struct Input {}
struct Output {
var sectionedItems: Observable<[ViewedListSectionModel]>
var scheduleSectionedItems: Observable<[ScheduleListSectionModel]>
var refreshResult: Observable<RefreshResult>
var pagination: Observable<PaginationModel?>
var error: Observable<Error>
}
let input: Input
let output: Output
private var listService: ListService<ScheduleListResponse>
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<ViewedModel, Void> = { this in
return Action { model in
AppRouter.push(Route.scheduleViewed)
return .empty()
}
}(self)
lazy var cellAction: Action<ScheduleModel, Void> = { 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
)
}
}