杨锴
2024-09-19 642175113bf6f2c90894e689dacda50278cad570
XQMuse/Root/Me/VC/WatchHistoryDetailVC.swift
@@ -7,53 +7,89 @@
import UIKit
import JQTools
import RxRelay
import RxSwift
class WatchHistoryViewModel:RefreshInnerModel<CourseModel>{
            let state = BehaviorRelay<Int>(value: 1)
            var type = BehaviorRelay<WatchType>(value: .collect)
            override func api() -> (Observable<BaseResponse<BaseResponseList<CourseModel>>>)? {
                        switch type.value {
                                    case .history:Services.lookHistory(page: page, pageSize: 20, state: state.value)
                                    case .collect:Services.myCollect(page: page, pageSize: 20, state: state.value)
                                    case .payment:Services.myOrderCourse(page: page, pageSize: 20, state: state.value)
                        }
            }
}
class WatchHistoryDetailVC: BaseVC {
            private var page:Int!
            private var viewModel = WatchHistoryViewModel()
            private var collectionView:UICollectionView!
            init(page:Int) {
            init(state:Int,type:WatchType) {
                        super.init(nibName: nil, bundle: nil)
                        self.page = page
                        self.viewModel.type.accept(type)
                        self.viewModel.state.accept(state)
            }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
    override func viewDidLoad() {
        super.viewDidLoad()
            override func viewDidLoad() {
                        super.viewDidLoad()
                        let layout = UICollectionViewFlowLayout()
                        collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
                        collectionView.delegate = self
                        collectionView.dataSource = self
                        collectionView.showsVerticalScrollIndicator = false
                        collectionView.backgroundColor = .clear
                        collectionView.register(UINib(nibName: "HomeRelaxBannerCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBannerCCell")
                        collectionView.contentInset = UIEdgeInsets(top: 29, left: 29.5 , bottom: 0, right: 29.5)
                        collectionView.contentInset = UIEdgeInsets(top: 0, left: 29.5 , bottom: 0, right: 29.5)
                        view.addSubview(collectionView)
                        collectionView.snp.makeConstraints { make in
                                    make.edges.equalToSuperview()
                                    make.top.equalTo(0)
                                    make.left.right.bottom.equalToSuperview()
                        }
    }
                        viewModel.configure(collectionView)
                        viewModel.beginRefresh()
            }
}
extension WatchHistoryDetailVC:UICollectionViewDelegate & UICollectionViewDataSource{
            func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                        return 5
                        return viewModel.dataSource.value?.list.count ?? 0
            }
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBannerCCell", for: indexPath) as! HomeRelaxBannerCCell
                        cell.contentView.backgroundColor = .jq_randomColor
                        let m = viewModel.dataSource.value!.list[indexPath.row]
                        cell.setCourseModel(m)
                        return cell
            }
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
                        return CGSizeMake(JQ_ScreenW, 29)
            }
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                    let vc = HomeItemDetailVC(id: 0)
                        let m = viewModel.dataSource.value!.list[indexPath.row]
                        if viewModel.state.value == 1{
                                    let vc = HomeItemDetailVC(id: m.id)
                                    JQ_currentViewController().jq_push(vc: vc)
                        }else{
                                    let vc = CourseDetialVC(courseId: m.id)
                                    JQ_currentViewController().jq_push(vc: vc)
                        }
            }
}