| | |
| | | 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() { |
| | |
| | | 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 |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| | | selectIndex = indexPath.row |
| | | viewModel.cateId.accept(titleItems[selectIndex].id) |
| | | viewModel.beginRefresh() |
| | | tableView.reloadData() |
| | | } |
| | | |
| | |
| | | extension CourseMenuVC:UICollectionViewDelegate & UICollectionViewDataSource{ |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | if indexPath.row == 0{ |
| | | let vc = CourseDetialVC(courseSytle: .style1) |
| | | let model = viewModel.dataSource.value!.list[indexPath.row] |
| | | let vc = CourseDetialVC(courseId: model.id) |
| | | push(vc: vc) |
| | | }else{ |
| | | let vc = CourseDetialVC(courseSytle: .style2) |
| | | 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 |
| | | } |
| | | } |
| | | |