杨锴
2024-09-19 642175113bf6f2c90894e689dacda50278cad570
XQMuse/Root/Me/VC/StudyListVC.swift
@@ -12,14 +12,29 @@
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")
@@ -37,25 +52,52 @@
extension StudyListVC:UICollectionViewDelegate & UICollectionViewDataSource{
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                        var modelId:Int?
                        if indexPath.section == 0{
                                    modelId = datas?.courseList[indexPath.row].id
                        }
                        if indexPath.section == 0{
                                    modelId = datas?.freeCourseList[indexPath.row].id
                        }
                        if let id = modelId{
                                    let vc = CourseDetialVC(courseId: id)
                                    push(vc: vc)
                        }
            }
            func numberOfSections(in collectionView: UICollectionView) -> Int {
                        return 2
            }
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                        if indexPath.section == 0{
                                 let cell   = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
                                    let count = datas?.courseList.count ?? 0
                                    if count == 0{
                                                let cell   = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
                                                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])
                                                return cell
                                    }
                        }else{
                                    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                    cell.setCourseModel(datas!.freeCourseList[indexPath.row])
                                    return cell
                        }
                        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                        cell.backgroundColor = .jq_randomColor
                        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 {
                                    return 5
                                    return datas?.freeCourseList.count ?? 0
                        }
            }
}
@@ -88,7 +130,10 @@
            }
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                        if indexPath.section == 0{
                        let count = datas?.courseList.count ?? 0
                        if indexPath.section == 0 && count == 0{
                                    return CGSize(width: JQ_ScreenW, height: 279)
                        }