//
|
// StudyListVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/20.
|
//
|
|
import UIKit
|
import QMUIKit
|
import JQTools
|
|
class StudyListVC: BaseVC {
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
private var datas:MyStudyModel?
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "学习"
|
|
Services.studyPage().subscribe(onNext: {data in
|
self.datas = data.data
|
self.collectionView.reloadData()
|
}).disposed(by: disposeBag)
|
}
|
|
override func setUI() {
|
super.setUI()
|
view.backgroundColor = UIColor(hexString: "#F6F6F6")
|
|
|
let layout = HoverHeaderFlowLayout()
|
layout.naviHeight = 0
|
let w = (JQ_ScreenW - 18 * 3) / 2
|
layout.itemSize = CGSize(width: w, height: w * 1.319)
|
layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 59)
|
collectionView.collectionViewLayout = layout
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.backgroundColor = UIColor(hexString: "#F6F6F6")
|
collectionView.register(UINib(nibName: "EmptyCCell", bundle: nil), forCellWithReuseIdentifier: "_EmptyCCell")
|
collectionView.register(UINib(nibName: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 18, bottom: 20, right: 18)
|
collectionView.register(StudyListHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
|
}
|
|
@IBAction func questionAction(_ sender: QMUIButton) {
|
let vc = HelpCenterVC()
|
push(vc: vc)
|
}
|
}
|
|
extension StudyListVC:UICollectionViewDelegate & UICollectionViewDataSource{
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
var modelId:Int?
|
if indexPath.section == 0{
|
guard datas?.courseList.count != 0 else{return}
|
modelId = datas?.courseList[indexPath.row].id
|
}
|
|
if indexPath.section == 1{
|
guard datas?.freeCourseList.count != 0 else{return}
|
modelId = datas?.freeCourseList[indexPath.row].id
|
}
|
|
if let id = modelId{
|
Services.getCourseDetail(courseId: id).subscribe(onNext: {[weak self]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)
|
}
|
}
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
return 2
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
if indexPath.section == 0{
|
let count = datas?.courseList.count ?? 0
|
if count == 0{
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
|
cell.btn_call.isHidden = false
|
cell.label_hint.text = "你还没有购买课程"
|
return cell
|
}else{
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
|
cell.setCourseModel(datas!.courseList[indexPath.row])
|
cell.view_price.isHidden = true
|
cell.view_waitPay.isHidden = true
|
cell.image_free.isHidden = true
|
cell.img_vip.isHidden = true
|
return cell
|
}
|
}else{
|
let count = datas?.freeCourseList.count ?? 0
|
if count == 0{
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
|
cell.btn_call.isHidden = true
|
cell.label_hint.text = "暂无推荐"
|
return cell
|
}
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
|
cell.setCourseModel(datas!.freeCourseList[indexPath.row])
|
cell.view_price.isHidden = true
|
cell.view_waitPay.isHidden = true
|
cell.image_free.isHidden = true
|
cell.img_vip.isHidden = true
|
return cell
|
}
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
if section == 0{
|
let count = datas?.courseList.count ?? 0
|
if count > 0{return count}
|
return 1
|
}else {
|
let count = datas?.freeCourseList.count ?? 0
|
if count > 0{return count}
|
return 1
|
}
|
}
|
}
|
|
extension StudyListVC: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 0
|
}
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
return CGSize(width: JQ_ScreenW, height: 59)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
if kind == UICollectionView.elementKindSectionHeader{
|
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! StudyListHeaderView
|
|
if indexPath.section == 0{
|
headerView.setTitle(text: "已购课程")
|
}else if indexPath.section == 1{
|
headerView.setTitle(text: "免费课程")
|
}
|
return headerView
|
}
|
|
return UICollectionReusableView()
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
var count = 0
|
if indexPath.section == 0{
|
count = datas?.courseList.count ?? 0
|
}else{
|
count = datas?.freeCourseList.count ?? 0
|
}
|
|
|
if count == 0{
|
return CGSize(width: JQ_ScreenW, height: 279)
|
}else{
|
let w = (JQ_ScreenW - 18 * 3) / 2
|
return CGSize(width: w, height: w * 1.319)
|
}
|
}
|
}
|
|
class StudyListHeaderView:UICollectionReusableView{
|
|
let lineLabel = UILabel()
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
setUI()
|
}
|
|
|
func setTitle(text:String){
|
lineLabel.text = text
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
private func setUI(){
|
backgroundColor = UIColor(hexString: "#F6F6F6")
|
lineLabel.font = .systemFont(ofSize: 15, weight: .bold)
|
lineLabel.textColor = UIColor(hexString: "#282828")
|
addSubview(lineLabel)
|
lineLabel.snp.makeConstraints { make in
|
make.left.equalTo(5)
|
make.centerY.equalToSuperview()
|
make.width.equalTo(71)
|
make.height.equalTo(20)
|
}
|
}
|
}
|