杨锴
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//
//  StudyListVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/20.
//
 
import UIKit
import QMUIKit
import JQTools
 
class StudyListVC: BaseVC {
 
                @IBOutlet weak var collectionView: UICollectionView!
 
                private var datas:MyStudyModel?
                override func viewDidLoad() {
        super.viewDidLoad()
                                title = "学习"
 
                                Services.studyPage().subscribe(onNext: {data in
                                                self.datas = data.data
                                                self.collectionView.reloadData()
                                }).disposed(by: disposeBag)
    }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor(hexString: "#F6F6F6")
 
 
                                let layout = HoverHeaderFlowLayout()
                                layout.naviHeight = 0
                                let w = (JQ_ScreenW - 18 * 3) / 2
                                layout.itemSize = CGSize(width: w, height: w * 1.319)
                                layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 59)
                                collectionView.collectionViewLayout = layout
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.backgroundColor = UIColor(hexString: "#F6F6F6")
                                collectionView.register(UINib(nibName: "EmptyCCell", bundle: nil), forCellWithReuseIdentifier: "_EmptyCCell")
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 18, bottom: 20, right: 18)
                                collectionView.register(StudyListHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
                }
 
                @IBAction func questionAction(_ sender: QMUIButton) {
                                let vc = HelpCenterVC()
                                push(vc: vc)
                }
}
 
extension StudyListVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
                                var modelId:Int?
                                if indexPath.section == 0{
            guard datas?.courseList.count != 0 else{return}
                                                modelId = datas?.courseList[indexPath.row].id
                                }
 
                                if indexPath.section == 1{
            guard datas?.freeCourseList.count != 0 else{return}
                                                modelId = datas?.freeCourseList[indexPath.row].id
                                }
 
                                if let id = modelId{
            Services.getCourseDetail(courseId: id).subscribe(onNext: {[weak self]data in
                if let m = data.data{
                    if m.isVip == .no && m.chargeType == .vipFree{
                        let vc = VIPCenterVC()
                        self?.push(vc: vc)
                    }else if m.courseType == .online{
                        let vc = CourseDetialVC(courseModel: m)
                        self?.push(vc: vc)
                    }else{
                        let vc = CourseDetialOfflineVC(courseId: m.id)
                        self?.push(vc: vc)
                    }
                }
            }).disposed(by: disposeBag)
                                }
                }
 
                func numberOfSections(in collectionView: UICollectionView) -> Int {
                                return 2
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                if indexPath.section == 0{
                                                let count = datas?.courseList.count ?? 0
                                                if count == 0{
                                                                let cell    = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
                cell.btn_call.isHidden = false
                cell.label_hint.text = "你还没有购买课程"
                                                                return cell
                                                }else{
                                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                                                cell.setCourseModel(datas!.courseList[indexPath.row])
                cell.view_price.isHidden = true
                cell.view_waitPay.isHidden = true
                cell.image_free.isHidden = true
                cell.img_vip.isHidden = true
                                                                return cell
                                                }
                                }else{
             let count = datas?.freeCourseList.count ?? 0
            if count == 0{
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
                cell.btn_call.isHidden = true
                cell.label_hint.text = "暂无推荐"
                return cell
            }
 
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                                cell.setCourseModel(datas!.freeCourseList[indexPath.row])
            cell.view_price.isHidden = true
            cell.view_waitPay.isHidden = true
            cell.image_free.isHidden = true
            cell.img_vip.isHidden = true
                                                return cell
                                }
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
 
                                if section == 0{
                                                let count = datas?.courseList.count ?? 0
                                                if count > 0{return count}
                                                return 1
                                }else {
            let count = datas?.freeCourseList.count ?? 0
            if count > 0{return count}
                                                return 1
                                }
                }
}
 
extension StudyListVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 13.5
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 0
                }
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
                                return CGSize(width: JQ_ScreenW, height: 59)
                }
 
                func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
                                if kind == UICollectionView.elementKindSectionHeader{
                                                let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! StudyListHeaderView
 
                                                if indexPath.section == 0{
                                                                headerView.setTitle(text: "已购课程")
                                                }else if indexPath.section == 1{
                                                                headerView.setTitle(text: "免费课程")
                                                }
                                                return headerView
                                }
 
                                return UICollectionReusableView()
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
 
 
        var count = 0
        if indexPath.section == 0{
            count = datas?.courseList.count ?? 0
        }else{
            count = datas?.freeCourseList.count ?? 0
        }
 
 
        if count == 0{
            return CGSize(width: JQ_ScreenW, height: 279)
        }else{
            let w = (JQ_ScreenW - 18 * 3) / 2
            return CGSize(width: w, height: w * 1.319)
        }
                }
}
 
class StudyListHeaderView:UICollectionReusableView{
 
                let lineLabel = UILabel()
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
                                setUI()
                }
 
 
                func setTitle(text:String){
                                lineLabel.text = text
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                private func setUI(){
                                backgroundColor = UIColor(hexString: "#F6F6F6")
        lineLabel.font = .systemFont(ofSize: 15, weight: .bold)
                                lineLabel.textColor = UIColor(hexString: "#282828")
                                addSubview(lineLabel)
                                lineLabel.snp.makeConstraints { make in
                                                make.left.equalTo(5)
                                                make.centerY.equalToSuperview()
                                                make.width.equalTo(71)
                                                make.height.equalTo(20)
                                }
                }
}