杨锴
2024-11-07 62a24b3c7cf92919a93ee575e9460037e1a53816
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
//
//  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)
                                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 m = viewModel.dataSource.value!.list[indexPath.row]
 
        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{
                let vc = PaymentOrderVC(museItemModel: m,type: .muse)
                jq_push(vc: vc)
            }
        }
                }
}