| | |
| | | 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() |
| | |
| | | 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() { |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | 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() |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | } |