杨锴
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
//
//  CourseDetail_3_TCell.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/19.
//
 
import UIKit
import JQTools
import RxSwift
 
class CourseDetail_3_TCell: UITableViewCell {
                @IBOutlet weak var collectionView: UICollectionView!
                @IBOutlet weak var cons_hei: NSLayoutConstraint!
                private let CellW  = (JQ_ScreenW - 21.5 * 2 - 13.5) / 2
                private let CellH = ((JQ_ScreenW - 21.5 * 2 - 13.5) / 2) * 1.313
 
                var items = [CourseModel]()
    private var disposeBag = DisposeBag()
 
                override func awakeFromNib() {
                                super.awakeFromNib()
                                backgroundColor = .clear
                                selectionStyle = .none
                                collectionView.backgroundColor = .clear
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.isScrollEnabled = false
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 21.5, bottom: 0, right: 21.5)
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_CCell")
 
                                cons_hei.constant = 0
                }
 
                func setItems(_ items:[CourseModel]){
                                self.items = items
                                cons_hei.constant = ceil(Double(items.count) / 2.0) * CellH + floor(Double(items.count) / 2.0) * 13.5
                                collectionView.reloadData()
                }
}
 
extension CourseDetail_3_TCell:UICollectionViewDelegate & UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return items.count
                }
                
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell
                                cell.setCourseModel(items[indexPath.row])
        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, didSelectItemAt indexPath: IndexPath) {
                                let model = items[indexPath.row]
        if model.courseType == .online{
            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_currentNavigationController().pushViewController(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)
        }
                }
}
 
extension CourseDetail_3_TCell: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 13.5
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                return CGSize(width: CellW, height: CellH)
                }
}