杨锴
2024-11-06 63f7ed967433acee3ae8764c7a077e15c29c41f2
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
//
//  Home_Style_4_TCell.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/13.
//
 
import UIKit
import JQTools
 
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]()
 
                @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 m = meditationModels[indexPath.row]
        guard m.id != 0 else{
            alert(msg: "平台暂未设置私人定制");return
        }
 
        let isVip = UserViewModel.getAvatarInfo().isVip
 
        if m.chargeType == .free || (m.chargeType == .vipFree && isVip == .yes) || (m.chargeType == .payment && m.isBuy == .yes){
            let detailVC = HomeItemDetailVC(id: meditationModels[indexPath.row].id)
            JQ_currentViewController().jq_push(vc: detailVC)
        }else{
            if m.chargeType == .vipFree{
                let vc = VIPCenterVC()
                JQ_currentViewController().jq_push(vc: vc)
            }else{
                let vc = PaymentOrderVC(museItemModel: m,type: .muse)
                JQ_currentViewController().jq_push(vc:vc)
            }
        }
                }
 
                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
                }
}