| | |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import RxRelay |
| | | import RxSwift |
| | | |
| | | class CourseVCOfficalViewModel:RefreshInnerModel<CourseModel>{ |
| | | var cateId = BehaviorRelay<Int?>(value: nil) |
| | | var search = BehaviorRelay<String?>(value: nil) |
| | | override func api() -> (Observable<BaseResponse<BaseResponseList<CourseModel>>>)? { |
| | | return Services.getCoursePageList(page: page,cateId: cateId.value, courseTitle: search.value) |
| | | } |
| | | } |
| | | |
| | | let CourseOfficalComment_Noti = Notification.Name.init("CourseOfficalComment_Noti") |
| | | |
| | | class CourseVCOfficalCommentVC: BaseVC { |
| | | |
| | | private var collectionView:UICollectionView! |
| | | private var titleItems = [TitleItem]() |
| | | private var subTitleItems = [TitleItem]() |
| | | private var bannerModels = [CommonBannerModel]() |
| | | private var viewModel = CourseVCOfficalViewModel() |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | Services.getCourseBannerList().subscribe(onNext: {data in |
| | | for (index,v) in (data.data ?? []).enumerated(){ |
| | | self.bannerModels.append(CommonBannerModel(index: index, id: v.id, name: v.name, resource:v.imageUrl.jq_urlEncoded(), mediaType: .imageUrl,courseId: v.courseId)) |
| | | } |
| | | self.collectionView.reloadData() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | |
| | | titleItems.append(TitleItem(title: "新手冥想指南", subTitle: "Meditation guide")) |
| | | titleItems.append(TitleItem(title: "推荐课程", subTitle: "与内心的宁静与喜悦入睡")) |
| | | |
| | | subTitleItems.append(TitleItem(title: "会员专区",coverImage: "course_1")) |
| | | subTitleItems.append(TitleItem(title: "免费专区",coverImage: "course_2")) |
| | | subTitleItems.append(TitleItem(title: "付费专区",coverImage: "course_3")) |
| | | subTitleItems.append(TitleItem(title: "线下课程",coverImage: "course_4")) |
| | | subTitleItems.append(TitleItem(title: "疗愈",coverImage: "course_5")) |
| | | subTitleItems.append(TitleItem(title: "关系",coverImage: "course_6")) |
| | | subTitleItems.append(TitleItem(title: "财富",coverImage: "course_7")) |
| | | subTitleItems.append(TitleItem(title: "分类",coverImage: "course_8")) |
| | | Services.getCourseCategory().subscribe(onNext: {data in |
| | | for v in data.data ?? []{ |
| | | self.subTitleItems.append(TitleItem(id:v.id,title: v.name,coverImage: v.imageUrl.jq_urlEncoded())) |
| | | } |
| | | self.collectionView.reloadData() |
| | | }).disposed(by: disposeBag) |
| | | |
| | | |
| | | |
| | | viewModel.configure(collectionView) |
| | | viewModel.beginRefresh() |
| | | |
| | | } |
| | | |
| | |
| | | make.edges.equalToSuperview() |
| | | } |
| | | } |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(CourseOfficalComment_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] _ in |
| | | self?.viewModel.beginRefresh() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override var shouldAutorotate: Bool{ |
| | | return false |
| | | } |
| | | } |
| | | |
| | | extension CourseVCOfficalCommentVC:UICollectionViewDelegate & UICollectionViewDataSource{ |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let vc = CourseDetialVC(courseSytle: .style1) |
| | | JQ_currentViewController().jq_push(vc: vc) |
| | | let model = viewModel.dataSource.value!.list[indexPath.row] |
| | | |
| | | if model.courseType == .online{ |
| | | if model.chargeType == .vipFree || model.chargeType == .payment{ |
| | | guard sceneDelegate!.checkisLoginState() else{return} |
| | | } |
| | | |
| | | |
| | | Services.getCourseDetail(courseId: model.id).subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | if m.isVip == .no && m.chargeType == .vipFree{ |
| | | let vc = VIPCenterVC() |
| | | JQ_currentViewController().jq_push(vc: vc) |
| | | }else if m.courseType == .online{ |
| | | let vc = CourseDetialVC(courseModel: m) |
| | | JQ_currentViewController().jq_push(vc: vc) |
| | | }else{ |
| | | let vc = CourseDetialOfflineVC(courseId: m.id) |
| | | JQ_currentViewController().jq_push(vc: vc) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | }else{ |
| | | let vc = CourseDetialOfflineVC(courseId: model.id) |
| | | JQ_currentViewController().jq_push(vc: vc) |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! HomeHeaderView_1 |
| | | let m = titleItems[indexPath.section] |
| | | headerView.setTitle(m.title, subTitle: m.subTitle) |
| | | headerView.btn_more.isHidden = true |
| | | return headerView |
| | | } |
| | | return UICollectionReusableView() |
| | |
| | | if indexPath.section == 0{ |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CourseOfficalCommendTopCCell", for: indexPath) as! CourseOfficalCommendTopCCell |
| | | cell.setTitles(subTitleItems) |
| | | cell.setBanners(bannerModels) |
| | | cell.clickAtClouse { index in |
| | | let vc = CourseMenuVC() |
| | | vc.setTitleItem(self.subTitleItems,defaultSelectIndex: index) |
| | | vc.hidesBottomBarWhenPushed = true |
| | | JQ_currentNavigationController().pushViewController(vc, animated: true) |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | let model = viewModel.dataSource.value!.list[indexPath.row] |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell |
| | | cell.backgroundColor = .jq_randomColor |
| | | cell.setCourseModel(model) |
| | | cell.label_title.font = UIFont.systemFont(ofSize: 19, weight: .bold) |
| | | cell.cons_title_top.constant = 14 |
| | | cell.cons_title_left.constant = 16.5 |
| | | return cell |
| | | } |
| | | |
| | |
| | | if section == 0{ |
| | | return 1 |
| | | } |
| | | return 20 |
| | | return viewModel.dataSource.value?.list.count ?? 0 |
| | | } |
| | | |
| | | func numberOfSections(in collectionView: UICollectionView) -> Int { |
| | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |
| | | if indexPath.section == 0{ |
| | | |
| | | let h = ceil(subTitleItems.count.double / 4.0) * 101.25 + floor(subTitleItems.count.double / 4.0) * 5 + 208.5 |
| | | let h = ceil(subTitleItems.count.double / 4.0) * 103.75 + floor(subTitleItems.count.double / 4.0) * 5 + 208.5 |
| | | return CGSize(width: JQ_ScreenW, height: h) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { |
| | | if section == 0{ |
| | | return .zero |
| | | } |
| | | return CGSize(width: JQ_ScreenW, height: 80.5) |
| | | } |
| | | } |