| | |
| | | |
| | | private var layout:WaterFallFlowLayout! |
| | | @IBOutlet weak var label_store: UILabel! |
| | | private var items = Array<HomeStoreConfigModel>() |
| | | private var items = Array<Any>() |
| | | private var storeModel:HomeStoreModel? |
| | | private var storeId:Int? |
| | | private var currentLocal:CLLocation? |
| | |
| | | if let models = data.data{ |
| | | let imgs = models.compactMap({$0.img}) |
| | | self?.view_banner.setImages(images: imgs, type: .URL) { index in |
| | | //todo |
| | | |
| | | } |
| | | } |
| | |
| | | showHUD() |
| | | let w = (weakSelf.view.frame.width - 78.0) / 2.0 |
| | | for (_,model) in weakSelf.items.enumerated(){ |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: model.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | if let m = model as? HomeStoreConfigModel{ |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | |
| | | } completed: { image, data, error, status in |
| | | } completed: {[weak self] image, data, error, status in |
| | | if let img = image{ |
| | | i += 1 |
| | | model.cellHeight = w / (img.size.width / img.size.height) |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | }else{ |
| | | m.cellHeight = w / (m.type.defaultImg.size.width / m.type.defaultImg.size.height) |
| | | } |
| | | i += 1 |
| | | model.cellHeight = w / (model.type.defaultImg.size.width / model.type.defaultImg.size.height) |
| | | if i == weakSelf.items.count{ |
| | | self?.updateUI() |
| | | } |
| | | } |
| | | } |
| | | |
| | | print("Height:\(model.cellHeight)===\(model.type.rawValue)\n") |
| | | if let m = model as? HomeStoreTopBannerModel{ |
| | | SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage), options: .useNSURLCache) { _, _,_ in |
| | | |
| | | } completed: {[weak self] image, data, error, status in |
| | | if let img = image{ |
| | | m.cellHeight = w / (img.size.width / img.size.height) |
| | | i += 1 |
| | | if i == weakSelf.items.count{ |
| | | self?.updateUI() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private func updateUI(){ |
| | | //重置Layout,不然不更新 |
| | | self!.layout = WaterFallFlowLayout() |
| | | self!.layout.itemCount = self!.items.count |
| | | self!.layout.delegate = self |
| | | self!.layout.cols = 2 |
| | | self!.layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34) |
| | | self!.collectionView.collectionViewLayout = self!.layout |
| | | self!.collectionView.reloadData() |
| | | layout = WaterFallFlowLayout() |
| | | layout.itemCount = items.count |
| | | layout.delegate = self |
| | | layout.cols = 2 |
| | | layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34) |
| | | collectionView.collectionViewLayout = self.layout |
| | | collectionView.reloadData() |
| | | hiddenHUD() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private func startLocation(){ |
| | |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.storeId = storeId |
| | | weakSelf.label_store.text = storeName |
| | | weakSelf.storeModel = HomeStoreModel(isVip: 0, storeId: storeId, name: storeName, lon: 0, lat: 0) |
| | | weakSelf.items.removeAll() |
| | | weakSelf.getStoreItemList() |
| | | } |
| | |
| | | |
| | | extension HomeVC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let item = items[indexPath.row] |
| | | |
| | | switch item.type{ |
| | | 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 .course: |
| | | let vc = CourseListVC() |
| | | let vc = CourseListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .booking: |
| | | let vc = YardListVC() |
| | | let vc = YardListVC(selectStore: simpleModel) |
| | | push(vc: vc) |
| | | case .activity: |
| | | let vc = ActivityListVC() |
| | |
| | | } |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | jumpPage(name: 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 |
| | | let item = items[indexPath.row] |
| | | cell.img.sd_setImage(with: URL(string: item.backgroundImage), placeholderImage: item.type.defaultImg, options: .lowPriority) |
| | | |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | cell.img.sd_setImage(with: URL(string: m.backgroundImage), placeholderImage: m.type.defaultImg, 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 |
| | | } |
| | |
| | | extension HomeVC: WaterFallLayoutDelegate{ |
| | | func waterFlowLayout(_ waterFlowLayout: WaterFallFlowLayout, itemHeight indexPath: IndexPath) -> CGFloat { |
| | | let item = items[indexPath.row] |
| | | print("===\(item.cellHeight)") |
| | | return item.cellHeight |
| | | |
| | | if let m = item as? HomeStoreConfigModel{ |
| | | return m.cellHeight |
| | | } |
| | | |
| | | if let m = item as? HomeStoreTopBannerModel{ |
| | | return m.cellHeight |
| | | } |
| | | |
| | | return 0 |
| | | } |
| | | } |
| | | |