//
|
// 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{
|
|
}
|