//
|
// HomeItemListVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/14.
|
//
|
|
import UIKit
|
import JQTools
|
import RxSwift
|
import RxRelay
|
|
class HomeItemViewModel:RefreshInnerModel<MeditationModel>{
|
var id = BehaviorRelay<Int>(value: 0)
|
override func api() -> (Observable<BaseResponse<BaseResponseList<MeditationModel>>>)? {
|
return Services.getMeditationPage(id.value, page: page)
|
}
|
}
|
|
|
class HomeItemListVC: BaseVC {
|
|
private var collectionView:UICollectionView!
|
private var topTitle:String!
|
private var viewModel = HomeItemViewModel()
|
private var showType: DisplayType!
|
|
init(topTitle:String,id:Int,showType: DisplayType) {
|
super.init(nibName: nil, bundle: nil)
|
self.topTitle = topTitle
|
self.showType = showType
|
self.viewModel.id.accept(id)
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = self.topTitle
|
|
viewModel.configure(collectionView)
|
viewModel.beginRefresh()
|
}
|
|
override func setUI() {
|
view.backgroundColor = UIColor(hexString: "#f6f6f6")
|
let layout = UICollectionViewFlowLayout()
|
let w = (JQ_ScreenW - 21.5 * 2 - 13.5) / 2
|
let h = w * 1.3142
|
layout.itemSize = CGSize(width: w, height: h)
|
layout.minimumLineSpacing = 13.5
|
layout.minimumInteritemSpacing = 13.5
|
layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 20)
|
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.backgroundColor = UIColor(hexString: "#f6f6f6")
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 21.5, bottom: 0, right: 21.5)
|
collectionView.register(UINib(nibName: "HomeRelaxBanner_2_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_CCell")
|
view.addSubview(collectionView)
|
collectionView.snp.makeConstraints { make in
|
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
|
make.right.bottom.left.equalToSuperview()
|
}
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
}
|
|
extension HomeItemListVC:UICollectionViewDelegate & UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell
|
let model = viewModel.dataSource.value!.list[indexPath.row]
|
cell.setMeditationModel(model,showType: showType)
|
cell.label_title.font = .systemFont(ofSize: 18, weight: .bold)
|
cell.cons_maxSubTitle.constant = 16
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return viewModel.dataSource.value?.list.count ?? 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
let item = viewModel.dataSource.value!.list[indexPath.row]
|
|
Services.getMeditationDetail(id: item.id).subscribe(onNext: {[weak self]data in
|
guard let weakSelf = self else { return }
|
if let m = data.data{
|
let isVip = m.isVip == .yes
|
if m.chargeType == .free || (isVip && m.chargeType == .vipFree) || (m.chargeType == .payment && m.isBuy == .yes){
|
let vc = HomeItemDetailVC(model: m)
|
JQ_currentViewController().jq_push(vc: vc)
|
return
|
}
|
|
if m.chargeType == .payment && m.isBuy == .no{
|
guard sceneDelegate!.checkisLoginState() else{return}
|
let vc = PaymentOrderVC(museItemModel: m,type: .muse,showType: weakSelf.showType)
|
JQ_currentViewController().jq_push(vc: vc)
|
return
|
}
|
|
if m.chargeType == .vipFree{
|
let vc = VIPCenterVC()
|
JQ_currentViewController().jq_push(vc: vc)
|
return
|
}
|
}
|
}).disposed(by: disposeBag)
|
|
|
|
|
|
// let isVip = UserViewModel.getAvatarInfo().checkVip()
|
//
|
// if m.chargeType == .free || (m.chargeType == .vipFree && isVip) || (m.chargeType == .payment && m.isBuy == .yes){
|
// let detailVC = HomeItemDetailVC(id: m.id)
|
// jq_push(vc: detailVC)
|
// }else{
|
// if m.chargeType == .vipFree{
|
// let vc = VIPCenterVC()
|
// jq_push(vc: vc)
|
// }else{
|
// guard sceneDelegate!.checkisLoginState() else{return}
|
// let vc = PaymentOrderVC(museItemModel: m,type: .muse,showType: showType)
|
// jq_push(vc: vc)
|
// }
|
// }
|
}
|
}
|