From 858bd6df13a6a6415d12d8e60141575574646f58 Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期一, 24 七月 2023 18:23:48 +0800
Subject: [PATCH] 新增

---
 WanPai/Root/Search/VC/SearchVC.swift |   95 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/WanPai/Root/Search/VC/SearchVC.swift b/WanPai/Root/Search/VC/SearchVC.swift
index 77fbcf7..d0e515b 100644
--- a/WanPai/Root/Search/VC/SearchVC.swift
+++ b/WanPai/Root/Search/VC/SearchVC.swift
@@ -11,11 +11,35 @@
 class SearchVC: BaseVC {
     @IBOutlet weak var scrollView: UIScrollView!
     @IBOutlet weak var banner_collectionView: UICollectionView!
+    @IBOutlet weak var label_empty: UILabel!
+    @IBOutlet weak var view_container: UIView!
 
+    private var models = [StartClouseExploreModel]()
+    private lazy var mapView:MAMapView = {
+        let map = MAMapView()
+        map.delegate = self
+        map.isShowsUserLocation = true
+        map.userTrackingMode = .none
+        map.isZoomEnabled = true
+        map.isScrollEnabled = true
+        return map
+    }()
+
+    override func viewDidDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+    }
 
     override func viewDidLoad() {
         super.viewDidLoad()
         scrollView.contentInsetAdjustmentBehavior = .never
+
+        Services.exploreHome().subscribe(onNext: {[weak self] data in
+            if let models = data.data,models.count > 0{
+                self?.models = models
+                self?.loadMap()
+                self?.banner_collectionView.reloadData()
+            }
+        }).disposed(by: disposeBag)
     }
 
 
@@ -25,6 +49,29 @@
         banner_collectionView.register(UINib(nibName: "SearchBannerCCell", bundle: nil), forCellWithReuseIdentifier: "_SearchBannerCCell")
     }
 
+
+    private func loadMap(){
+        label_empty.isHidden = true
+        view_container.addSubview(mapView)
+        mapView.frame = CGRect(origin: .zero, size: view_container.size)
+
+        for v in models{
+            let point = MAPointAnnotation()
+            point.coordinate = CLLocationCoordinate2D(latitude: v.latitude, longitude:v.longitude)
+            point.title = v.storeAddr
+            v.annotation = point
+        }
+
+        let points = models.map({$0.annotation}) as! [MAPointAnnotation]
+        mapView.addAnnotations(points)
+        mapView.showAnnotations(points, animated: true)
+        mapView.selectAnnotation(points.first!, animated: true)
+    }
+
+    override func viewDidLayoutSubviews() {
+        super.viewDidLayoutSubviews()
+        view_container.cornerRadius = 10
+    }
 
     @IBAction func customerAction(_ sender: Any) {
         let vc = CustomerListVC()
@@ -38,18 +85,27 @@
 
 extension SearchVC:UICollectionViewDelegate{
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        let vc = SearchStoreListVC()
+        let model = models[indexPath.row]
+        let vc = SearchStoreDetailVC(id: model.storeId)
         push(vc: vc)
+    }
+
+    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
+        let page = Int(scrollView.contentOffset.x / JQ_ScreenW)
+        let model = models[page]
+        mapView.selectAnnotation(model.annotation, animated: true)
     }
 }
 
 extension SearchVC:UICollectionViewDataSource{
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 5
+        return models.count
     }
 
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_SearchBannerCCell", for: indexPath) as! SearchBannerCCell
+        let model = models[indexPath.row]
+        cell.startClouseExploreItemModel = model
         return cell
     }
 }
@@ -68,3 +124,38 @@
         return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.6541)
     }
 }
+
+extension SearchVC:MAMapViewDelegate{
+    func mapViewDidStopLocatingUser(_ mapView: MAMapView!) {
+        print("--->停止")
+    }
+
+    func mapView(_ mapView: MAMapView!, didUpdate userLocation: MAUserLocation!, updatingLocation: Bool) {
+        print("--->更新")
+    }
+
+    func mapViewWillStartLocatingUser(_ mapView: MAMapView!) {
+        print("--->开始")
+    }
+
+    func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
+        if annotation is MAPointAnnotation{
+            var pointView =  mapView.dequeueReusableAnnotationView(withIdentifier: "point")
+            if pointView == nil{
+                pointView = MAAnnotationView(annotation: annotation, reuseIdentifier: "point")
+            }
+            pointView?.canShowCallout = true
+            pointView?.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#f54444"))
+            return pointView
+        }
+        return nil
+    }
+
+    func mapView(_ mapView: MAMapView!, didSelect view: MAAnnotationView!) {
+        view.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#2980ff"))
+    }
+
+    func mapView(_ mapView: MAMapView!, didDeselect view: MAAnnotationView!) {
+        view.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#f54444"))
+    }
+}

--
Gitblit v1.7.1