无故事王国
2023-09-26 c86ac49db2969495ec21fae2a27956cad9499752
WanPai/Root/Home/VC/HomeVC.swift
@@ -44,7 +44,7 @@
        super.viewDidLoad()
        viewModel.configure(collectionView,needMore: false)
//      startLocation()
      startLocation()
        viewModel.dataSource.subscribe(onNext: {[weak self] data in
            guard let weakSelf = self else { return }
@@ -52,19 +52,19 @@
            weakSelf.items = data
            let group = DispatchGroup()
            for m in weakSelf.items{
                let queue = DispatchQueue(label: "1")
                queue.async(group: group) {
                    group.enter()
                    m.radio = m.type.defaultImg.size.width / m.type.defaultImg.size.height //默认比例
                    SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage),options: .scaleDownLargeImages,progress: nil) { image, data, error, status in
                        if let i = image{
                            m.radio = i.size.width / i.size.height
                        }
                        group.leave()
                    }
                }
            }
//            for m in weakSelf.items{
//                let queue = DispatchQueue(label: "1")
//                queue.async(group: group) {
//                    group.enter()
//                    m.radio = m.type.defaultImg.size.width / m.type.defaultImg.size.height //默认比例
//                    SDWebImageDownloader.shared.downloadImage(with: URL(string: m.backgroundImage),options: .scaleDownLargeImages,progress: nil) { image, data, error, status in
//                        if let i = image{
//                            m.radio = i.size.width / i.size.height
//                        }
//                        group.leave()
//                    }
//                }
//            }
         Services.homeInfo2(storeId: weakSelf.viewModel.storeId.value).subscribe(onNext: {data in
            
@@ -124,20 +124,31 @@
        collectionView.dataSource = self
        collectionView.backgroundColor = .white
        collectionView.register(UINib(nibName: "HomeCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeCCell")
        collectionView.jq_setEmptyView("无数据", image: UIImage(named: "icon_empty"), foregroundColor: .gray, clouse: nil)
      collectionView.jq_setEmptyView("无数据", image: UIImage(named: "icon_LOGO")?.jq_imageWithTintColor(color: .gray), foregroundColor: .gray, clouse: nil)
    }
    private func getStoreInfo(){
        Services.homeInfo().subscribe(onNext: {[weak self] data in
            if let m = data.data{
            self?.storeModel = m
                self?.label_store.text = m.name.isEmpty ? "门店获取失败":m.name
                var text = "欢迎来到 快乐运动俱乐部"
                if m.isVip == 0{text.append("\n加入我们 成为会员")}
                self?.label_vipInfo.text = text
            var text = "欢迎来到 快乐运动俱乐部"
                if m.storeId != 0{
                    self?.viewModel.storeId.accept(m.storeId)
               if let storeStr = UserDefaults.standard.object(forKey: "CurrentStore") as? String{
                  if let deserModel = HomeStoreModel.deserialize(from: storeStr){
                     self?.label_store.text = deserModel.name.isEmpty ? "门店获取失败":deserModel.name
                     self?.viewModel.storeId.accept(deserModel.storeId)
                     self?.storeModel = deserModel
                     if deserModel.isVip == 0{text.append("\n加入我们 成为会员")}
                     self?.label_vipInfo.text = text
                  }
               }else{
                  self?.viewModel.storeId.accept(m.storeId)
                  self?.label_store.text = m.name.isEmpty ? "门店获取失败":m.name
                  UserDefaults.standard.set(m.toJSONString(), forKey: "CurrentStore")
                  UserDefaults.standard.synchronize()
                  self?.storeModel = m
                  if m.isVip == 0{text.append("\n加入我们 成为会员")}
                  self?.label_vipInfo.text = text
               }
                    self?.viewModel.beginRefresh()
                }else{
                    self?.defaultData()