杨锴
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
//
//  CourseVCOfficalCommentVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/15.
//
 
import UIKit
import JQTools
import RxRelay
import RxSwift
 
class CourseVCOfficalViewModel:RefreshInnerModel<CourseModel>{
                var cateId = BehaviorRelay<Int?>(value: nil)
    var search = BehaviorRelay<String?>(value: nil)
                override func api() -> (Observable<BaseResponse<BaseResponseList<CourseModel>>>)? {
        return Services.getCoursePageList(page: page,cateId: cateId.value, courseTitle: search.value)
                }
}
 
let CourseOfficalComment_Noti = Notification.Name.init("CourseOfficalComment_Noti")
 
class CourseVCOfficalCommentVC: BaseVC {
 
                private var collectionView:UICollectionView!
                private var titleItems = [TitleItem]()
                private var subTitleItems = [TitleItem]()
                private var bannerModels = [CommonBannerModel]()
                private var viewModel = CourseVCOfficalViewModel()
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        Services.getCourseBannerList().subscribe(onNext: {data in
            for (index,v) in (data.data ?? []).enumerated(){
                self.bannerModels.append(CommonBannerModel(index: index, id: v.id, name: v.name, resource:v.imageUrl.jq_urlEncoded(), mediaType: .imageUrl,courseId: v.courseId))
            }
            self.collectionView.reloadData()
        }).disposed(by: disposeBag)
    }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                                titleItems.append(TitleItem(title: "新手冥想指南", subTitle: "Meditation guide"))
                                titleItems.append(TitleItem(title: "推荐课程", subTitle: "与内心的宁静与喜悦入睡"))
 
                                Services.getCourseCategory().subscribe(onNext: {data in
                                                for v in data.data ?? []{
                                                                self.subTitleItems.append(TitleItem(id:v.id,title: v.name,coverImage: v.imageUrl.jq_urlEncoded()))
                                                }
                                                self.collectionView.reloadData()
                                }).disposed(by: disposeBag)
 
 
 
                                viewModel.configure(collectionView)
                                viewModel.beginRefresh()
 
                }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor(hexString: "#F0F0F0")
                                let layout = UICollectionViewFlowLayout()
                                collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 19, bottom: 0, right: 19)
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_CCell")
                                collectionView.register(UINib(nibName: "CourseOfficalCommendTopCCell", bundle: nil), forCellWithReuseIdentifier: "_CourseOfficalCommendTopCCell")
 
                                collectionView.register(HomeHeaderView_1.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
                                view.addSubview(collectionView)
                                collectionView.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
                }
 
    override func setRx() {
        NotificationCenter.default.rx.notification(CourseOfficalComment_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] _ in
            self?.viewModel.beginRefresh()
        }).disposed(by: disposeBag)
    }
 
                override var shouldAutorotate: Bool{
                                return  false
                }
}
 
extension CourseVCOfficalCommentVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                let model = viewModel.dataSource.value!.list[indexPath.row]
 
        if model.courseType == .online{
            if model.chargeType == .vipFree || model.chargeType == .payment{
                guard sceneDelegate!.checkisLoginState() else{return}
            }
 
 
            Services.getCourseDetail(courseId: model.id).subscribe(onNext: {data in
                if let m = data.data{
                    if m.isVip == .no && m.chargeType == .vipFree{
                        let vc = VIPCenterVC()
                        JQ_currentViewController().jq_push(vc: vc)
                    }else if m.courseType == .online{
                        let vc = CourseDetialVC(courseModel: m)
                        JQ_currentViewController().jq_push(vc: vc)
                    }else{
                        let vc = CourseDetialOfflineVC(courseId: m.id)
                        JQ_currentViewController().jq_push(vc: vc)
                    }
                }
            }).disposed(by: disposeBag)
        }else{
            let vc = CourseDetialOfflineVC(courseId: model.id)
            JQ_currentViewController().jq_push(vc: vc)
        }
                }
 
 
                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! HomeHeaderView_1
                                                let m = titleItems[indexPath.section]
                                                headerView.setTitle(m.title, subTitle: m.subTitle)
                                                headerView.btn_more.isHidden = true
                                                return headerView
                                }
                                return UICollectionReusableView()
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
 
                                if indexPath.section == 0{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CourseOfficalCommendTopCCell", for: indexPath) as! CourseOfficalCommendTopCCell
                                                cell.setTitles(subTitleItems)
                                                cell.setBanners(bannerModels)
                                                cell.clickAtClouse { index in
                                                                let vc = CourseMenuVC()
                                                                vc.setTitleItem(self.subTitleItems,defaultSelectIndex: index)
                                                                vc.hidesBottomBarWhenPushed = true
                                                                JQ_currentNavigationController().pushViewController(vc, animated: true)
                                                }
                                                return cell
                                }
                                let model = viewModel.dataSource.value!.list[indexPath.row]
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell
                                cell.setCourseModel(model)
        cell.label_title.font = UIFont.systemFont(ofSize: 19, weight: .bold)
        cell.cons_title_top.constant = 14
        cell.cons_title_left.constant = 16.5
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                if section == 0{
                                                return 1
                                }
                                return viewModel.dataSource.value?.list.count ?? 0
                }
 
                func numberOfSections(in collectionView: UICollectionView) -> Int {
                                return titleItems.count
                }
}
 
extension CourseVCOfficalCommentVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                if indexPath.section == 0{
 
                                                let h = ceil(subTitleItems.count.double / 4.0) * 103.75 + floor(subTitleItems.count.double / 4.0) * 5 + 208.5
                                                return CGSize(width: JQ_ScreenW, height: h)
                                }
 
                                let w = (JQ_ScreenW - 19 * 2 - 14) / 2
 
                                return CGSize(width: w, height: w * 1.314)
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 14
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 14
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        if section == 0{
            return .zero
        }
                                return CGSize(width: JQ_ScreenW, height: 80.5)
                }
}