| | |
| | | // |
| | | // HomeVC.swift |
| | | // WanPai |
| | | // |
| | | // Created by 杨锴 on 2023/6/8. |
| | | // |
| | | // |
| | | // HomeVC.swift |
| | | // WanPai |
| | | // |
| | | // Created by 杨锴 on 2023/6/8. |
| | | // |
| | | |
| | | import UIKit |
| | | import JQTools |
| | |
| | | let UpdateCurrentStore_Noti = Notification.Name.init("UpdateCurrentStore_Noti") |
| | | |
| | | class HomeVC: BaseVC{ |
| | | @IBOutlet weak var collectionView: BaseCollectionView! |
| | | @IBOutlet weak var label_vipInfo: UILabel! |
| | | @IBOutlet weak var view_banner: CommonBannerView! |
| | | @IBOutlet weak var btn_localTap: TapBtn! |
| | | private var layout:FlowLayout! |
| | | @IBOutlet weak var label_store: UILabel! |
| | | private var items = Array<Any>() |
| | | private var storeModel:HomeStoreModel? |
| | | private var storeId:Int? |
| | | private var currentLocal:CLLocation? |
| | | @IBOutlet weak var collectionView: BaseCollectionView! |
| | | @IBOutlet weak var label_vipInfo: UILabel! |
| | | @IBOutlet weak var view_banner: CommonBannerView! |
| | | @IBOutlet weak var btn_localTap: TapBtn! |
| | | private var layout:FlowLayout! |
| | | @IBOutlet weak var label_store: UILabel! |
| | | private var items = Array<Any>() |
| | | private var storeModel:HomeStoreModel? |
| | | private var storeId:Int? |
| | | private var currentLocal:CLLocation? |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | if let nav = navigationController as? BaseNav{ |
| | | nav.navigationController(nav, willShow: self, animated: true) |
| | | } |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | startLocation() |
| | | Services.bannerList(position: .homeTop).subscribe(onNext: {[weak self] data in |
| | | if let models = data.data{ |
| | | var bannerResources = [CommonBannerModel]() |
| | | for (i,item) in models.enumerated() { |
| | | bannerResources.append(CommonBannerModel(index:i,resource:item.img,mediaType:.imageUrl)) |
| | | } |
| | | self?.view_banner.setItems(items: bannerResources,selectClouse: { m in |
| | | jumpPage(model: models[m.index].model, page: models[m.index].page, type: models[m.index].type, id: models[m.index].turnId) |
| | | }) |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | |
| | | } |
| | | |
| | | override func setUI() { |
| | | view.backgroundColor = UIColor(hexStr: "EEF0F3") |
| | | |
| | | layout = FlowLayout() |
| | | layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34) |
| | | collectionView.collectionViewLayout = layout |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.backgroundColor = .white |
| | | collectionView.register(UINib(nibName: "HomeCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeCCell") |
| | | // collectionView.jq_setEmptyView("无数据", image: UIImage(named: "icon_LOGO")?.jq_imageWithTintColor(color: .gray), foregroundColor: .gray, clouse: nil) |
| | | } |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(ChooseHomeStore_Noti).take(until: self.rx.deallocated).subscribe(onNext: { [weak self] noti in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.chooseStoresAction(weakSelf.btn_localTap) |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | private func getStoreInfo(){ |
| | | Services.homeInfo().subscribe(onNext: {[weak self] data in |
| | | if let m = data.data{ |
| | | self?.storeModel = m |
| | | var text = "欢迎来到 快乐运动俱乐部" |
| | | if m.storeId != 0{ |
| | | self?.label_store.text = m.name.isEmpty ? "门店获取失败":m.name |
| | | self?.storeModel = m |
| | | self?.storeId = m.storeId |
| | | if m.isVip == 0{text.append("\n加入我们 成为会员")} |
| | | self?.label_vipInfo.text = text |
| | | UserDefaults.standard.set(m.toJSONString(), forKey: "CurrentStore") |
| | | UserDefaults.standard.synchronize() |
| | | self?.getStoreItemList() |
| | | } |
| | | } |
| | | }) { [weak self] error in |
| | | self?.label_store.text = "门店获取失败" |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | private func getStoreItemList(){ |
| | | |
| | | items.removeAll() |
| | | |
| | | Services.homeStoreConfig(storeId: storeId!).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | self?.items.append(contentsOf: (data.data ?? []).filter({$0.isOpen == 1})) |
| | | Services.homeStoreConfig2(storeId: weakSelf.storeId!).subscribe(onNext: {[weak self] data in |
| | | self?.items.append(contentsOf: (data.data ?? [])) |
| | | self?.downloadImgs() |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | //图片下载 |
| | | private func downloadImgs(){ |
| | | let group = DispatchGroup() |
| | | let queue = DispatchQueue(label: "imgRadio") |
| | | let w = (view.frame.width - 78.0) / 2.0 |
| | | for item in items{ |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | queue.async(group: group){ () in |
| | | group.enter() |
| | | guard SDImageCache.shared.diskImageDataExists(withKey: m.backgroundImage) else { |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | } completed: { image, data, error, status in |
| | | if let img = image{ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | }else{ |
| | | m.cellHeight = w / (m.type.defaultImg.size.width / m.type.defaultImg.size.height) |
| | | } |
| | | group.leave() |
| | | } |
| | | return |
| | | } |
| | | if let data = SDImageCache.shared.diskCache.data(forKey: m.backgroundImage),let img = UIImage(data: data){ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | group.leave() |
| | | } |
| | | } |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | queue.async(group: group){() in |
| | | group.enter() |
| | | guard SDImageCache.shared.diskImageDataExists(withKey: m.backgroundImage) else { |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | } completed: { image, data, error, status in |
| | | if let img = image{ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | } |
| | | group.leave() |
| | | } |
| | | return |
| | | } |
| | | |
| | | if let data = SDImageCache.shared.diskCache.data(forKey: m.backgroundImage),let img = UIImage(data: data){ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | group.leave() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | group.notify(queue: .main) { |
| | | self.items = self.items.sorted { v1, v2 in |
| | | |
| | | var sort1 = 0 |
| | | var sort2 = 0 |
| | | |
| | | if let m = v1 as? HomeStoreTopBannerModel{ |
| | | sort1 = m.sort |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | if let nav = navigationController as? BaseNav{ |
| | | nav.navigationController(nav, willShow: self, animated: true) |
| | | } |
| | | } |
| | | |
| | | if let m = v1 as? HomeStoreConfigModel{ |
| | | sort1 = m.sort |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | startLocation() |
| | | Services.bannerList(position: .homeTop).subscribe(onNext: {[weak self] data in |
| | | if let models = data.data{ |
| | | var bannerResources = [CommonBannerModel]() |
| | | for (i,item) in models.enumerated() { |
| | | bannerResources.append(CommonBannerModel(index:i,resource:item.img,mediaType:.imageUrl)) |
| | | } |
| | | self?.view_banner.setItems(items: bannerResources,selectClouse: { m in |
| | | jumpPage(model: models[m.index].model, page: models[m.index].page, type: models[m.index].type, id: models[m.index].turnId) |
| | | }) |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | if let m = v2 as? HomeStoreTopBannerModel{ |
| | | sort2 = m.sort |
| | | override func setUI() { |
| | | view.backgroundColor = UIColor(hexStr: "EEF0F3",darkStr: nil) |
| | | |
| | | layout = FlowLayout() |
| | | layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34) |
| | | collectionView.collectionViewLayout = layout |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.backgroundColor = .white |
| | | collectionView.register(UINib(nibName: "HomeCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeCCell") |
| | | // collectionView.jq_setEmptyView("无数据", image: UIImage(named: "icon_LOGO")?.jq_imageWithTintColor(color: .gray), foregroundColor: .gray, clouse: nil) |
| | | } |
| | | |
| | | if let m = v2 as? HomeStoreConfigModel{ |
| | | sort2 = m.sort |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(ChooseHomeStore_Noti).take(until: self.rx.deallocated).subscribe(onNext: { [weak self] noti in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.chooseStoresAction(weakSelf.btn_localTap) |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | return sort1 < sort2 |
| | | } |
| | | |
| | | let v = self.items.compactMap { any in |
| | | if let m = any as? HomeStoreTopBannerModel{ |
| | | return "\(m.sort)" |
| | | private func getStoreInfo(){ |
| | | Services.homeInfo().subscribe(onNext: {[weak self] data in |
| | | if let m = data.data{ |
| | | self?.storeModel = m |
| | | var text = "欢迎来到 快乐运动俱乐部" |
| | | if m.storeId != 0{ |
| | | self?.label_store.text = m.name.isEmpty ? "门店获取失败":m.name |
| | | self?.storeModel = m |
| | | self?.storeId = m.storeId |
| | | if m.isVip == 0{text.append("\n加入我们 成为会员")} |
| | | self?.label_vipInfo.text = text |
| | | UserDefaults.standard.set(m.toJSONString(), forKey: "CurrentStore") |
| | | UserDefaults.standard.synchronize() |
| | | self?.getStoreItemList() |
| | | } |
| | | } |
| | | }) { [weak self] error in |
| | | self?.label_store.text = "门店获取失败" |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | if let m = any as? HomeStoreConfigModel{ |
| | | return "\(m.sort)" |
| | | |
| | | private func getStoreItemList(){ |
| | | |
| | | items.removeAll() |
| | | |
| | | Services.homeStoreConfig(storeId: storeId!).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | self?.items.append(contentsOf: (data.data ?? []).filter({$0.isOpen == 1})) |
| | | Services.homeStoreConfig2(storeId: weakSelf.storeId!).subscribe(onNext: {[weak self] data in |
| | | self?.items.append(contentsOf: (data.data ?? [])) |
| | | self?.downloadImgs() |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | return "" |
| | | } |
| | | |
| | | self.layout.collectionView?.reloadData() |
| | | self.collectionView.reloadData() |
| | | } |
| | | } |
| | | //图片下载 |
| | | private func downloadImgs(){ |
| | | let group = DispatchGroup() |
| | | let queue = DispatchQueue(label: "imgRadio") |
| | | let w = (view.frame.width - 78.0) / 2.0 |
| | | for item in items{ |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | queue.async(group: group){ () in |
| | | group.enter() |
| | | guard SDImageCache.shared.diskImageDataExists(withKey: m.backgroundImage) else { |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | } completed: { image, data, error, status in |
| | | if let img = image{ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | }else{ |
| | | m.cellHeight = w / (m.type.defaultImg.size.width / m.type.defaultImg.size.height) |
| | | } |
| | | group.leave() |
| | | } |
| | | return |
| | | } |
| | | if let data = SDImageCache.shared.diskCache.data(forKey: m.backgroundImage),let img = UIImage(data: data){ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | group.leave() |
| | | } |
| | | } |
| | | } |
| | | |
| | | private func startLocation(){ |
| | | locationTool.startLocation { [weak self] local in |
| | | guard self!.currentLocal != nil else { |
| | | self!.currentLocal = local |
| | | self!.getStoreInfo() |
| | | locationTool.stopLocation() |
| | | return |
| | | } |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | queue.async(group: group){() in |
| | | group.enter() |
| | | guard SDImageCache.shared.diskImageDataExists(withKey: m.backgroundImage) else { |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | } completed: { image, data, error, status in |
| | | if let img = image{ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | } |
| | | group.leave() |
| | | } |
| | | return |
| | | } |
| | | |
| | | } errorClouse: { [weak self] error in |
| | | alertError(msg: "定位获取失败") |
| | | self?.label_store.text = "定位获取失败" |
| | | } |
| | | } |
| | | if let data = SDImageCache.shared.diskCache.data(forKey: m.backgroundImage),let img = UIImage(data: data){ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | group.leave() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @IBAction func scanAction(_ sender: UIButton) { |
| | | let codeVC = CommonScanQRCodeVC {[weak self] text, status in |
| | | if status{ |
| | | if let model = QRCodeModel.deserialize(from: text){ |
| | | if model.scan_type == .games{ |
| | | let gamesListVC = GamesListVC(model: model) |
| | | self?.push(vc: gamesListVC) |
| | | }else if model.scan_type == .yard{ |
| | | let vc = YardDetailVC(id: model.id!) |
| | | self?.push(vc: vc) |
| | | }else if model.scan_type == .course{ |
| | | let vc = CourseDetailVC(id: model.id!) |
| | | self?.push(vc: vc) |
| | | } |
| | | }else{ |
| | | alertError(msg: "识别失败") |
| | | group.notify(queue: .main) { |
| | | self.items = self.items.sorted { v1, v2 in |
| | | |
| | | var sort1 = 0 |
| | | var sort2 = 0 |
| | | |
| | | if let m = v1 as? HomeStoreTopBannerModel{ |
| | | sort1 = m.sort |
| | | } |
| | | |
| | | if let m = v1 as? HomeStoreConfigModel{ |
| | | sort1 = m.sort |
| | | } |
| | | |
| | | if let m = v2 as? HomeStoreTopBannerModel{ |
| | | sort2 = m.sort |
| | | } |
| | | |
| | | if let m = v2 as? HomeStoreConfigModel{ |
| | | sort2 = m.sort |
| | | } |
| | | return sort1 < sort2 |
| | | } |
| | | |
| | | let v = self.items.compactMap { any in |
| | | if let m = any as? HomeStoreTopBannerModel{ |
| | | return "\(m.sort)" |
| | | } |
| | | if let m = any as? HomeStoreConfigModel{ |
| | | return "\(m.sort)" |
| | | } |
| | | return "" |
| | | } |
| | | |
| | | self.layout.collectionView?.reloadData() |
| | | self.collectionView.reloadData() |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | push(vc: codeVC) |
| | | } |
| | | |
| | | private func startLocation(){ |
| | | locationTool.startLocation { [weak self] local in |
| | | guard self!.currentLocal != nil else { |
| | | self!.currentLocal = local |
| | | self!.getStoreInfo() |
| | | locationTool.stopLocation() |
| | | return |
| | | } |
| | | |
| | | @IBAction func joinMemberAction(_ sender: UIButton) { |
| | | let joinMemberVC = JoinMemberIntroduceVC() |
| | | push(vc: joinMemberVC) |
| | | } |
| | | |
| | | |
| | | @IBAction func chooseStoresAction(_ sender: TapBtn) { |
| | | StoresChooseView.show(defaultM: storeModel) { [weak self] province,city,store in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.storeId = store.id |
| | | weakSelf.label_store.text = store.name |
| | | weakSelf.storeModel = HomeStoreModel(isVip: weakSelf.storeModel?.isVip ?? 0, storeId: store.id, name: store.name, lon: 0, lat: 0, province: province.name, provinceCode: province.code, city: city?.name ?? "", cityCode: city?.code ?? 0) |
| | | weakSelf.items.removeAll() |
| | | weakSelf.getStoreItemList() |
| | | } errorClouse: { [weak self] error in |
| | | alertError(msg: "定位获取失败") |
| | | self?.label_store.text = "定位获取失败" |
| | | } |
| | | } |
| | | |
| | | UserDefaults.standard.set(weakSelf.storeModel!.toJSONString(), forKey: "CurrentStore") |
| | | UserDefaults.standard.synchronize() |
| | | NotificationCenter.default.post(name: UpdateCurrentStore_Noti, object: nil, userInfo: nil) |
| | | @IBAction func scanAction(_ sender: UIButton) { |
| | | let codeVC = CommonScanQRCodeVC {[weak self] text, status in |
| | | if status{ |
| | | if let model = QRCodeModel.deserialize(from: text){ |
| | | if model.scan_type == .games{ |
| | | let gamesListVC = GamesListVC(model: model) |
| | | self?.push(vc: gamesListVC) |
| | | }else if model.scan_type == .yard{ |
| | | let vc = YardDetailVC(id: model.id!) |
| | | self?.push(vc: vc) |
| | | }else if model.scan_type == .course{ |
| | | let vc = CourseDetailVC(id: model.id!) |
| | | self?.push(vc: vc) |
| | | } |
| | | }else{ |
| | | alertError(msg: "识别失败") |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | push(vc: codeVC) |
| | | } |
| | | |
| | | override var preferredStatusBarStyle: UIStatusBarStyle{ |
| | | return .lightContent |
| | | } |
| | | |
| | | @IBAction func joinMemberAction(_ sender: UIButton) { |
| | | let joinMemberVC = JoinMemberIntroduceVC() |
| | | push(vc: joinMemberVC) |
| | | } |
| | | |
| | | |
| | | @IBAction func chooseStoresAction(_ sender: TapBtn) { |
| | | StoresChooseView.show(defaultM: storeModel) { [weak self] province,city,store in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.storeId = store.id |
| | | weakSelf.label_store.text = store.name |
| | | weakSelf.storeModel = HomeStoreModel(isVip: weakSelf.storeModel?.isVip ?? 0, storeId: store.id, name: store.name, lon: 0, lat: 0, province: province.name, provinceCode: province.code, city: city?.name ?? "", cityCode: city?.code ?? 0) |
| | | weakSelf.items.removeAll() |
| | | weakSelf.getStoreItemList() |
| | | |
| | | UserDefaults.standard.set(weakSelf.storeModel!.toJSONString(), forKey: "CurrentStore") |
| | | UserDefaults.standard.synchronize() |
| | | NotificationCenter.default.post(name: UpdateCurrentStore_Noti, object: nil, userInfo: nil) |
| | | |
| | | } |
| | | } |
| | | |
| | | override var preferredStatusBarStyle: UIStatusBarStyle{ |
| | | return .lightContent |
| | | } |
| | | } |
| | | |
| | | extension HomeVC:UICollectionViewDelegate,UICollectionViewDelegateWaterFlowLayout{ |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, colum section: Int) -> Int { |
| | | return 2 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacing section: Int) -> CGFloat { |
| | | return 10 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sectionInsetForItems section: Int) -> UIEdgeInsets { |
| | | return UIEdgeInsets(top: 0, left: 34, bottom: 14, right: 34) |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, itemWidth: CGFloat, caculateHeight indexPath: IndexPath) -> CGFloat { |
| | | let item = items[indexPath.row] |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | return m.cellHeight |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, colum section: Int) -> Int { |
| | | return 2 |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | return m.cellHeight |
| | | } |
| | | return 200 |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacing section: Int) -> CGFloat { |
| | | return 10 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sectionInsetForItems section: Int) -> UIEdgeInsets { |
| | | return UIEdgeInsets(top: 0, left: 34, bottom: 14, right: 34) |
| | | } |
| | | |
| | | var simpleModel:NormalSimpleModel? |
| | | if storeModel != nil{ |
| | | simpleModel = NormalSimpleModel(id: storeModel!.storeId, name: storeModel!.name) |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, itemWidth: CGFloat, caculateHeight indexPath: IndexPath) -> CGFloat { |
| | | let item = items[indexPath.row] |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | return m.cellHeight |
| | | } |
| | | |
| | | let item = items[indexPath.row] |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | switch m.type{ |
| | | case .course: |
| | | let vc = CourseListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .booking: |
| | | let vc = YardListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .activity: |
| | | let vc = ActivityListVC(cityModel: storeModel) |
| | | push(vc: vc) |
| | | case .video: |
| | | let vc = CourseOnlineListVC(position: 2) |
| | | vc.title = "看视频得奖励" |
| | | push(vc: vc) |
| | | case .coin: |
| | | let vc = CourseOnlineListVC(position: 1) |
| | | vc.title = "线上课得积分" |
| | | push(vc: vc) |
| | | case .ticket: |
| | | let vc = CoinStoreCenterVC(selectStore: simpleModel,type: .ticket) |
| | | push(vc: vc) |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | return m.cellHeight |
| | | } |
| | | return 200 |
| | | } |
| | | |
| | | case .wisdomCourt: |
| | | guard storeId != 0 else {alert(msg: "请先选择门店");return} |
| | | let vc = GamesVC() |
| | | push(vc: vc) |
| | | case .welfare: |
| | | if storeId != 0{ |
| | | Services.queryStoreFreeBenefit(id: storeId!).subscribe(onNext: {[weak self] data in |
| | | if let m = data.data{ |
| | | let vc = WelfareFreeVC(m) |
| | | self?.push(vc: vc) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | }else{ |
| | | alertError(msg: "当前门店获取失败") |
| | | } |
| | | case .none:break |
| | | } |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | jumpPage(model: m.name, page: m.page, type: m.type,id: m.turnId) |
| | | } |
| | | } |
| | | |
| | | var simpleModel:NormalSimpleModel? |
| | | if storeModel != nil{ |
| | | simpleModel = NormalSimpleModel(id: storeModel!.storeId, name: storeModel!.name) |
| | | } |
| | | |
| | | let item = items[indexPath.row] |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | switch m.type{ |
| | | case .worldcup: |
| | | let vc = WorldCupIntroVC() |
| | | push(vc: vc) |
| | | case .course: |
| | | let vc = CourseListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .booking: |
| | | let vc = YardListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .activity: |
| | | let vc = ActivityListVC(cityModel: storeModel) |
| | | push(vc: vc) |
| | | case .video: |
| | | let vc = CourseOnlineListVC(position: 2) |
| | | vc.title = "看视频得奖励" |
| | | push(vc: vc) |
| | | case .coin: |
| | | let vc = CourseOnlineListVC(position: 1) |
| | | vc.title = "线上课得积分" |
| | | push(vc: vc) |
| | | case .ticket: |
| | | let vc = CoinStoreCenterVC(selectStore: simpleModel,type: .ticket) |
| | | push(vc: vc) |
| | | |
| | | case .wisdomCourt: |
| | | guard storeId != 0 else {alert(msg: "请先选择门店");return} |
| | | let vc = GamesVC() |
| | | push(vc: vc) |
| | | case .welfare: |
| | | if storeId != 0{ |
| | | Services.queryStoreFreeBenefit(id: storeId!).subscribe(onNext: {[weak self] data in |
| | | if let m = data.data{ |
| | | let vc = WelfareFreeVC(m) |
| | | self?.push(vc: vc) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | }else{ |
| | | alertError(msg: "当前门店获取失败") |
| | | } |
| | | case .nothing: |
| | | break |
| | | } |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | jumpPage(model: m.name, page: m.page, type: m.type,id: m.turnId) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | extension HomeVC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeCCell", for: indexPath) as! HomeCCell |
| | | guard indexPath.row < items.count else {return cell} |
| | | let item = items[indexPath.row] |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeCCell", for: indexPath) as! HomeCCell |
| | | guard indexPath.row < items.count else {return cell} |
| | | let item = items[indexPath.row] |
| | | |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | cell.img.sd_setImage(with: URL(string: m.backgroundImage), placeholderImage: nil, options: .lowPriority) |
| | | } |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | cell.img.sd_setImage(with: URL(string: m.backgroundImage), placeholderImage: nil, options: .lowPriority) |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | cell.img.sd_setImage(with: URL(string: m.backgroundImage), placeholderImage: nil, options: .lowPriority) |
| | | } |
| | | cell.img.cornerRadius = 10 |
| | | return cell |
| | | } |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | cell.img.sd_setImage(with: URL(string: m.backgroundImage), placeholderImage: nil, options: .lowPriority) |
| | | } |
| | | cell.img.cornerRadius = 10 |
| | | return cell |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return items.count |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return items.count |
| | | } |
| | | } |
| | | |