杨锴
2024-09-12 e15c976316feef72ff9bcabce38e0a078f9505db
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
//
//  CourseMenuVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/16.
//
 
import UIKit
import JQTools
 
class CourseMenuVC: BaseVC {
 
                private var tableView:UITableView!
                private var collectionView:UICollectionView!
                private var titleItems = [TitleItem]()
                private var selectIndex:Int = 0
                private var viewModel = CourseVCOfficalViewModel()
 
    override func viewDidLoad() {
        super.viewDidLoad()
                                title = "全部课程"
                                viewModel.cateId.accept(titleItems[selectIndex].id)
                                viewModel.configure(collectionView)
                                viewModel.beginRefresh()
    }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor.white
 
                                tableView = UITableView(frame: .zero, style: .plain)
                                tableView.backgroundColor = UIColor(hexString: "#f6f6f6")
                                tableView.separatorStyle = .none
                                tableView.isScrollEnabled = false
                                tableView.register(UINib(nibName: "MenuListTCell", bundle: nil), forCellReuseIdentifier: "_MenuListTCell")
                                tableView.delegate = self
                                tableView.dataSource = self
                                view.addSubview(tableView)
                                tableView.snp.makeConstraints { make in
                                                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
                                                make.left.bottom.equalToSuperview()
                                                make.width.equalTo(JQ_ScreenW * 0.2487)
                                }
 
                                let layout = UICollectionViewFlowLayout()
                                collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.showsVerticalScrollIndicator = false
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 21, bottom: 0, right: 21)
                                view.addSubview(collectionView)
                                collectionView.snp.makeConstraints { make in
                                                make.left.equalTo(tableView.snp.right)
                                                make.right.equalToSuperview()
                                                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(18)
                                                make.bottom.equalTo(tableView)
                                }
                }
 
                func setTitleItem(_ items:[TitleItem],defaultSelectIndex:Int = 0){
                                self.selectIndex = defaultSelectIndex
                                self.titleItems = items
                }
}
 
extension CourseMenuVC:UITableViewDelegate & UITableViewDataSource{
 
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                selectIndex = indexPath.row
                                viewModel.cateId.accept(titleItems[selectIndex].id)
                                viewModel.beginRefresh()
                                tableView.reloadData()
                }
 
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_MenuListTCell", for: indexPath) as! MenuListTCell
                                cell.backgroundColor = .clear
                                cell.view_line.isHidden = indexPath.row != selectIndex
                                cell.label_title.text = titleItems[indexPath.row].title
                                cell.label_title.textColor = indexPath.row == selectIndex ? UIColor(hexString: "#8AAE65") : UIColor(hexString: "#5C5C5C")
                                return cell
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return titleItems.count
                }
 
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                return 53
                }
}
 
extension CourseMenuVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                let model = viewModel.dataSource.value!.list[indexPath.row]
                                let vc = CourseDetialVC(courseId: model.id)
                                push(vc: vc)
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let model = viewModel.dataSource.value!.list[indexPath.row]
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                cell.backgroundColor = .jq_randomColor
                                cell.setCourseModel(model)
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return viewModel.dataSource.value?.list.count ?? 0
                }
}
 
extension CourseMenuVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 10
                }
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 10
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                let w = ((JQ_ScreenW - 70) * (1 - 0.2487)) / 2
                                return CGSize(width: w, height: w * 1.313)
                }
}