杨锴
2024-11-14 1cc03dff6006c235686f87fe0f80af2fde97abf4
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
//
//  CourseMenuVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/16.
//
 
import UIKit
import JQTools
import EmptyDataSet_Swift
 
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)
                                }
 
        collectionView.emptyDataSetSource = self
        collectionView.emptyDataSetDelegate = self
        collectionView.emptyDataSetView { v in
 
            if let sub = v.viewWithTag(10010){
 
 
            }else{
                let v1 = UIView()
                v1.tag = 10010
                v1.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
                v1.center = CGPoint(x: v.center.x - 20, y: v.center.y - 150)
                v.addSubview(v1)
 
                let image = UIImageView(image: UIImage(named: "bg_empty"))
                image.contentMode = .scaleAspectFill
                v1.addSubview(image)
                image.snp.makeConstraints { make in
                    make.top.left.right.equalToSuperview()
                }
 
                let label = UILabel(text: "暂未找到相关内容哦~")
                label.font = .systemFont(ofSize: 14, weight: .medium)
                label.textColor = .gray
                v1.addSubview(label)
                label.snp.makeConstraints { make in
                    make.centerX.equalTo(image)
                    make.top.equalTo(image.snp.bottom).offset(8)
                }
            }
        }
                }
 
                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]
 
        if model.courseType == .online{
 
            if model.chargeType == .payment || model.chargeType == .vipFree{
                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()
                        self.push(vc: vc)
                    }else if m.courseType == .online{
                        let vc = CourseDetialVC(courseModel: m)
                        self.push(vc: vc)
                    }else{
                        let vc = CourseDetialOfflineVC(courseId: m.id)
                        self.push(vc: vc)
                    }
                }
            }).disposed(by: disposeBag)
        }else{
            let vc = CourseDetialOfflineVC(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.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)
                }
}
 
extension CourseMenuVC:EmptyDataSetSource{
 
}
 
extension CourseMenuVC:EmptyDataSetDelegate{
 
}