From a2589f9891509d85a873192d56e785885513e780 Mon Sep 17 00:00:00 2001 From: younger_times <841720330@qq.com> Date: 星期二, 18 七月 2023 15:54:32 +0800 Subject: [PATCH] 新增 --- WanPai/Root/Course/VC/CourseOnlineListVC.swift | 79 +++++++++++++++++++++++++++++++++++---- 1 files changed, 71 insertions(+), 8 deletions(-) diff --git a/WanPai/Root/Course/VC/CourseOnlineListVC.swift b/WanPai/Root/Course/VC/CourseOnlineListVC.swift index d023611..711ab7c 100644 --- a/WanPai/Root/Course/VC/CourseOnlineListVC.swift +++ b/WanPai/Root/Course/VC/CourseOnlineListVC.swift @@ -8,8 +8,24 @@ import UIKit import JQTools import MJRefresh +import RxCocoa +import RxSwift +import QMUIKit + + +class VideoViewModel:RefreshModel<VideosModel>{ + let position = BehaviorRelay<Int>(value: 1) + let search = BehaviorRelay<String>(value: "") + + override func api() -> (Observable<BaseResponse<[VideosModel]>>)? { + return Services.benefitsVideoList(position: position.value, search: search.value) + } +} + class CourseOnlineListVC: BaseVC { + + private var viewModel = VideoViewModel() lazy var searchView:CourseOnlineSearchView = { let searchV = CourseOnlineSearchView.jq_loadNibView() @@ -18,10 +34,31 @@ return searchV }() - var collectionView:UICollectionView! + var collectionView:BaseCollectionView! + required init(position:Int){ + super.init(nibName: nil, bundle: nil) + self.viewModel.position.accept(position) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func viewDidLoad() { super.viewDidLoad() + + Services.bannerList(position: 3).subscribe(onNext: {[weak self] data in + if let models = data.data{ + self?.searchView.bannerView.setImages(images: models.map({$0.img}),type: .URL, imageClickBlock: { index in + + }) + } + }).disposed(by: disposeBag) + + viewModel.configure(collectionView,needMore: false) + viewModel.beginRefresh() + collectionView.jq_setEmptyView() } override func setUI() { @@ -32,7 +69,7 @@ flowlayout.minimumLineSpacing = 22 // flowlayout.sectionHeadersPinToVisibleBounds = true flowlayout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 52) - collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowlayout) + collectionView = BaseCollectionView(frame: .zero, collectionViewLayout: flowlayout) collectionView.register(UINib(nibName: "CourseOnlineCCell", bundle: nil), forCellWithReuseIdentifier: "_CourseOnlineCCell") collectionView.register(UINib(nibName: "CourseOnlineHeadView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "_CourseOnlineHeadView") collectionView.delegate = self @@ -48,6 +85,17 @@ } view.addSubview(searchView) + searchView.btn_search.addTarget(self, action: #selector(beginSearch), for: .touchUpInside) + searchView.tf_search.delegate = self + } + + override func setRx() { + searchView.tf_search.rx.text.orEmpty.bind(to: viewModel.search).disposed(by: disposeBag) + } + + @objc func beginSearch(){ + searchView.tf_search.resignFirstResponder() + viewModel.beginRefresh() } @@ -58,41 +106,56 @@ } extension CourseOnlineListVC:UICollectionViewDelegate{ - + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let model = viewModel.dataSource.value[indexPath.section].list[indexPath.row] + let vc = CourseVideoDetailVC(id: model.id) + vc.title = title ?? "" + push(vc: vc) + } } extension CourseOnlineListVC:UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { - if kind == UICollectionView.elementKindSectionHeader{ let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "_CourseOnlineHeadView", for: indexPath) as! CourseOnlineHeadView headerView.indexPath = indexPath headerView.moreClouse = { [weak self] index in - let vc = CourseOnlineSubListVC() + let id = self?.viewModel.dataSource.value[index.section].id + let vc = CourseOnlineSubListVC(classificationId: id!) vc.title = self?.title ?? "" self?.push(vc: vc) } + headerView.label_name.text = viewModel.dataSource.value[indexPath.section].name return headerView } - return UICollectionReusableView() } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let model = viewModel.dataSource.value[indexPath.section].list[indexPath.row] let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CourseOnlineCCell", for: indexPath) as! CourseOnlineCCell + cell.videoDetailModel = model return cell } func numberOfSections(in collectionView: UICollectionView) -> Int { - return 3 + return viewModel.dataSource.value.count } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 4 + return viewModel.dataSource.value[section].list.count } } class OnlineLayout:UICollectionViewFlowLayout{ } + +extension CourseOnlineListVC:QMUITextFieldDelegate{ + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + viewModel.beginRefresh() + return true + } +} -- Gitblit v1.7.1