杨锴
2024-09-19 642175113bf6f2c90894e689dacda50278cad570
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
//
//  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: 0, 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{
                                                modelId = datas?.courseList[indexPath.row].id
                                }
 
                                if indexPath.section == 0{
                                                modelId = datas?.freeCourseList[indexPath.row].id
                                }
 
                                if let id = modelId{
                                                let vc = CourseDetialVC(courseId: id)
                                                push(vc: vc)
                                }
                }
 
                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
                                                                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])
                                                                return cell
                                                }
                                }else{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                                cell.setCourseModel(datas!.freeCourseList[indexPath.row])
                                                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 {
                                                return datas?.freeCourseList.count ?? 0
                                }
                }
}
 
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 {
 
                                let count = datas?.courseList.count ?? 0
 
                                if indexPath.section == 0 && count == 0{
                                                return CGSize(width: JQ_ScreenW, height: 279)
                                }
 
                                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: .medium)
                                lineLabel.textColor = UIColor(hexString: "#282828")
                                addSubview(lineLabel)
                                lineLabel.snp.makeConstraints { make in
                                                make.left.equalTo(0)
                                                make.centerY.equalToSuperview()
                                                make.width.equalTo(71)
                                                make.height.equalTo(20)
                                }
                }
}