杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
//  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)
//            }
//        }
                }
}