杨锴
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
//
//  CourseOfficalCommendTopCCell.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/15.
//
 
import UIKit
import JQTools
import RxSwift
 
class CourseOfficalCommendTopCCell: UICollectionViewCell {
 
                @IBOutlet weak var view_bannerContentView: CommonBannerView!
                @IBOutlet weak var collectionView: UICollectionView!
                @IBOutlet weak var cons_hei: NSLayoutConstraint!
                private var titleItems = [TitleItem]()
                private var bannerModels = [CommonBannerModel]()
                private var clouse:((Int)->Void)?
 
    private var disposeBag = DisposeBag()
 
                override func awakeFromNib() {
        super.awakeFromNib()
 
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.isScrollEnabled = false
                                collectionView.register(UINib(nibName: "CourseOfficialItemCCell", bundle: nil), forCellWithReuseIdentifier: "_CourseOfficialItemCCell")
    }
 
                func setTitles(_ items:[TitleItem]){
                                titleItems = items
        cons_hei.constant = ceil(Double(items.count) / 4) * 93.75
                                collectionView.reloadData()
                }
 
                func setBanners(_ items:[CommonBannerModel]){
                                bannerModels = items
        view_bannerContentView.setItems(items: items) {[weak self] m in
            guard let weakSelf = self else { return }
            if let id = m.courseId?.int{
                Services.getCourseDetail(courseId: id).subscribe(onNext: {data in
                    if let m = data.data{
                        if m.isVip == .no && m.chargeType == .vipFree{
                            let vc = VIPCenterVC()
                            vc.hidesBottomBarWhenPushed = true
                            JQ_currentNavigationController().pushViewController(vc)
                        }else if m.courseType == .online{
                            let courseDetialVC = CourseDetialVC(courseModel: m)
                            courseDetialVC.hidesBottomBarWhenPushed = true
                            JQ_currentNavigationController().pushViewController(courseDetialVC)
                        }else{
                            let vc = CourseDetialOfflineVC(courseId: m.id)
                            vc.hidesBottomBarWhenPushed = true
                            JQ_currentNavigationController().pushViewController(vc)
                        }
                    }
                }).disposed(by: weakSelf.disposeBag)
            }
        }
                }
 
                func clickAtClouse(_ clouse:@escaping (Int)->Void){
                                self.clouse = clouse
                }
}
 
extension CourseOfficalCommendTopCCell:UICollectionViewDelegate & UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return titleItems.count
                }
                
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CourseOfficialItemCCell", for: indexPath) as! CourseOfficialItemCCell
                                cell.setItem(titleItems[indexPath.row])
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                clouse?(indexPath.row)
                }
}
 
extension CourseOfficalCommendTopCCell:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                let w = JQ_ScreenW / 4
                                return CGSize(width: w, height: 101.25)
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 5
                }
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 0
                }
}