//
|
// 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
|
// let v = UIView()
|
// v.backgroundColor = .red
|
//
|
// return
|
// }
|
}
|
|
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{
|
let vc = CourseDetialVC(courseId: model.id)
|
push(vc: vc)
|
}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{
|
func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
|
return UIImage(named: "icon_empty")
|
}
|
|
func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
|
return AttributedStringbuilder.build().add(string: "暂无数据", withFont: .systemFont(ofSize: 12, weight: .medium), withColor: .gray).mutableAttributedString
|
}
|
|
func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat {
|
return 300
|
}
|
|
func spaceHeight(forEmptyDataSet scrollView: UIScrollView) -> CGFloat {
|
return 200
|
}
|
}
|
|
extension CourseMenuVC:EmptyDataSetDelegate{
|
|
}
|