//
|
// WatchHistoryDetailVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/22.
|
//
|
|
import UIKit
|
import JQTools
|
import RxRelay
|
import RxSwift
|
|
let WatchHistory_Noti = Notification.Name.init("WatchHistory_Noti")
|
|
class WatchHistoryViewModel:RefreshModel<CourseModel>{
|
|
let state = BehaviorRelay<Int>(value: 1)
|
var type = BehaviorRelay<WatchType>(value: .collect)
|
|
override func api() -> (Observable<BaseResponse<[CourseModel]>>)? {
|
switch type.value {
|
case .history:return Services.lookHistory(page: page, pageSize: 20, state: state.value)
|
case .collect:return Services.myCollect(page: page, pageSize: 20, state: state.value)
|
case .payment:return Services.myOrderCourse(page: page, pageSize: 20, state: state.value)
|
}
|
}
|
}
|
|
|
class WatchHistoryDetailVC: BaseVC {
|
|
private var viewModel = WatchHistoryViewModel()
|
private var collectionView:UICollectionView!
|
|
init(state:Int,type:WatchType) {
|
super.init(nibName: nil, bundle: nil)
|
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()
|
|
|
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: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 29.5 , bottom: 0, right: 29.5)
|
|
view.addSubview(collectionView)
|
collectionView.snp.makeConstraints { make in
|
make.top.equalTo(0)
|
make.left.right.bottom.equalToSuperview()
|
}
|
|
viewModel.configure(collectionView)
|
viewModel.beginRefresh()
|
}
|
|
override func setRx() {
|
NotificationCenter.default.rx.notification(WatchHistory_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] _ in
|
self?.viewModel.beginRefresh()
|
}).disposed(by: disposeBag)
|
}
|
}
|
|
extension WatchHistoryDetailVC:UICollectionViewDelegate & UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
|
let m = viewModel.dataSource.value[indexPath.row]
|
cell.setCourseModel(m)
|
|
if viewModel.type.value == .payment{
|
cell.image_free.isHidden = true
|
cell.img_vip.isHidden = true
|
cell.view_price.isHidden = true
|
}
|
|
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 item = viewModel.dataSource.value[indexPath.row]
|
if item.paymentStatus == .no{
|
//音频
|
if viewModel.state.value == 1{
|
Services.getMeditationDetail(id: item.businessId).subscribe(onNext: {data in
|
if let m = data.data{
|
let vc = HomeItemDetailVC(model: m)
|
JQ_currentViewController().jq_push(vc: vc)
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
//课程
|
if viewModel.state.value == 2{
|
Services.getCourseDetail(courseId: item.businessId).subscribe(onNext: {data in
|
if let m = data.data{
|
if m.isVip == .no && m.chargeType == .vipFree{
|
let vc = VIPCenterVC()
|
JQ_currentNavigationController().pushViewController(vc)
|
}else if m.courseType == .online{
|
let vc = CourseDetialVC(courseModel: m)
|
JQ_currentViewController().jq_push(vc: vc)
|
}else{
|
let vc = CourseDetialOfflineVC(courseId: m.id)
|
JQ_currentViewController().jq_push(vc: vc)
|
}
|
}
|
}).disposed(by: disposeBag)
|
}
|
}else{
|
Services.gvieCourseAgain(id: item.id).subscribe(onNext: {[weak self]data in
|
guard let weakSelf = self else { return }
|
if let m = data.data{
|
let vc = PaymentOrderVC(pendingModel: m, type: weakSelf.viewModel.state.value == 1 ? .muse:.course)
|
JQ_currentViewController().jq_push(vc: vc)
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
|
|
// if viewModel.state.value == 1{
|
// //待支付
|
// if item.paymentStatus == .yes{
|
// Services.getMeditationDetail(id: item.businessId).subscribe(onNext: {data in
|
// if let m = data.data{
|
// let vc = PaymentOrderVC(museItemModel: m, type: .muse, giftToOther: false, showType: .horizontal,businessId: item.id)
|
// JQ_currentViewController().jq_push(vc: vc)
|
// }
|
// }).disposed(by: disposeBag)
|
// return
|
// }
|
//
|
//
|
// Services.getMeditationDetail(id: item.businessId).subscribe(onNext: {data in
|
// if let m = data.data{
|
// let vc = HomeItemDetailVC(model: m)
|
// JQ_currentViewController().jq_push(vc: vc)
|
// }
|
// }).disposed(by: disposeBag)
|
// }else{
|
// if item.courseType == .online{
|
//
|
// //待支付
|
// if item.paymentStatus == .yes{
|
// Services.getCourseDetail(courseId: item.businessId).subscribe(onNext: { data in
|
// if let m = data.data{
|
// let vc = PaymentOrderVC(courseItemModel: m, type: .course, giftToOther: false, showType: .horizontal,businessId: item.id)
|
// JQ_currentViewController().jq_push(vc: vc)
|
// }
|
// }).disposed(by: disposeBag)
|
// return
|
// }
|
//
|
//
|
// Services.getCourseDetail(courseId: item.businessId).subscribe(onNext: {data in
|
// if let m = data.data{
|
// if m.isVip == .no && m.chargeType == .vipFree{
|
// let vc = VIPCenterVC()
|
// JQ_currentNavigationController().pushViewController(vc)
|
// }else if m.courseType == .online{
|
// let vc = CourseDetialVC(courseModel: m)
|
// JQ_currentViewController().jq_push(vc: vc)
|
// }else{
|
// let vc = CourseDetialOfflineVC(courseId: m.id)
|
// JQ_currentViewController().jq_push(vc: vc)
|
// }
|
// }
|
// }).disposed(by: disposeBag)
|
// }else{
|
// let vc = CourseDetialOfflineVC(courseId: item.businessId)
|
// push(vc: vc)
|
// }
|
// }
|
}
|
}
|
|
extension WatchHistoryDetailVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
let w = (JQ_ScreenW - (29.5 * 2) - 18.5) / 2
|
return CGSize(width: w, height: w * 1.3124)
|
}
|
}
|