From e15c976316feef72ff9bcabce38e0a078f9505db Mon Sep 17 00:00:00 2001
From: 杨锴 <841720330@qq.com>
Date: 星期四, 12 九月 2024 18:18:03 +0800
Subject: [PATCH] fix API

---
 XQMuse/Root/Course/VC/CourseMenuVC.swift |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/XQMuse/Root/Course/VC/CourseMenuVC.swift b/XQMuse/Root/Course/VC/CourseMenuVC.swift
index c3ad658..3d992ff 100644
--- a/XQMuse/Root/Course/VC/CourseMenuVC.swift
+++ b/XQMuse/Root/Course/VC/CourseMenuVC.swift
@@ -14,16 +14,14 @@
 				private var collectionView:UICollectionView!
 				private var titleItems = [TitleItem]()
 				private var selectIndex:Int = 0
+				private var viewModel = CourseVCOfficalViewModel()
 
     override func viewDidLoad() {
         super.viewDidLoad()
 								title = "全部课程"
-
-								titleItems.append(TitleItem(title: "会员专区"))
-								titleItems.append(TitleItem(title: "免费专区"))
-								titleItems.append(TitleItem(title: "付费专区"))
-								titleItems.append(TitleItem(title: "线下课程"))
-								titleItems.append(TitleItem(title: "水晶疗愈"))
+								viewModel.cateId.accept(titleItems[selectIndex].id)
+								viewModel.configure(collectionView)
+								viewModel.beginRefresh()
     }
 
 				override func setUI() {
@@ -49,14 +47,20 @@
 								collectionView.delegate = self
 								collectionView.dataSource = self
 								collectionView.showsVerticalScrollIndicator = false
-								collectionView.register(UINib(nibName: "HomeRelaxBanner_2_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_CCell")
-								collectionView.contentInset = UIEdgeInsets(top: 34, left: 21, bottom: 0, right: 21)
+								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.bottom.equalTo(tableView)
+												make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(18)
+												make.bottom.equalTo(tableView)
 								}
+				}
+
+				func setTitleItem(_ items:[TitleItem],defaultSelectIndex:Int = 0){
+								self.selectIndex = defaultSelectIndex
+								self.titleItems = items
 				}
 }
 
@@ -64,6 +68,8 @@
 
 				func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 								selectIndex = indexPath.row
+								viewModel.cateId.accept(titleItems[selectIndex].id)
+								viewModel.beginRefresh()
 								tableView.reloadData()
 				}
 
@@ -88,23 +94,21 @@
 extension CourseMenuVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
 				func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-								if indexPath.row == 0{
-												let vc = CourseDetialVC(courseSytle: .style1)
-												push(vc: vc)
-								}else{
-												let vc = CourseDetialVC(courseSytle: .style2)
-												push(vc: vc)
-								}
+								let model = viewModel.dataSource.value!.list[indexPath.row]
+								let vc = CourseDetialVC(courseId: model.id)
+								push(vc: vc)
 				}
 
 				func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-								let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell
+								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.backgroundColor = .jq_randomColor
+								cell.setCourseModel(model)
 								return cell
 				}
 
 				func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-								return 2
+								return viewModel.dataSource.value?.list.count ?? 0
 				}
 }
 

--
Gitblit v1.7.1