杨锴
2024-11-15 745e4fc64ca2912c011d925f12e638ed6d81b367
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
//
//  Home_Style_4_TCell.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/13.
//
 
import UIKit
import JQTools
import RxSwift
 
enum Home_Style_4_Style{
                case style1
                case style2
}
 
class Home_Style_4_TCell: UITableViewCell {
 
                var style:Home_Style_4_Style!
    private var showType: DisplayType!
                var meditationModels = [MeditationModel]()
    private let disposeBag = DisposeBag()
 
                @IBOutlet weak var collectionView: UICollectionView!
 
                override func awakeFromNib() {
        super.awakeFromNib()
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.isPagingEnabled = true
                                collectionView.register(UINib(nibName: "Home_Style_4_Inner_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_Home_Style_4_Inner_1_CCell")
                                collectionView.register(UINib(nibName: "Home_Style_4_Inner_CCell", bundle: nil), forCellWithReuseIdentifier: "_Home_Style_4_Inner_CCell")
                                collectionView.showsHorizontalScrollIndicator = false
    }
 
                func setModels(_ items:[MeditationModel],showType: DisplayType){
        self.showType = showType
                                self.meditationModels = items
                                collectionView.reloadData()
                }
}
 
extension Home_Style_4_TCell:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
        let item = meditationModels[indexPath.row]
        if (item.chargeType == .payment || item.chargeType == .vipFree || item.id == 0) && (UserViewModel.getLoginInfo()?.token.isEmpty ?? true){
            sceneDelegate?.checkisLoginState()
            return
        }
 
        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)
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return meditationModels.count
                }
                
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                if style == .style1{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Home_Style_4_Inner_1_CCell", for: indexPath) as! Home_Style_4_Inner_1_CCell
            cell.setMeditationModel(meditationModels[indexPath.row],showType: showType)
                                                return cell
                                }
 
                                if style == .style2{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Home_Style_4_Inner_CCell", for: indexPath) as! Home_Style_4_Inner_CCell
            cell.setMeditationModel(meditationModels[indexPath.row],showType: showType)
                                                return cell
                                }
 
                                return UICollectionViewCell()
                }
}
 
extension Home_Style_4_TCell:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 0
                }
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 0
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                if style == .style2{
                                                return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.734)
                                }
 
                                if style == .style1{
                                                return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.551)
                                }
 
                                return .zero
                }
}