无故事王国
2023-10-17 77041c81c325c0bc88c94dc28d732f656cc4c885
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
//  SearchVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/8.
//
 
import UIKit
import JQTools
 
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!
    @IBOutlet weak var btn_special: UIButton!
    @IBOutlet weak var btn_userLocal: UIButton!
        //    @IBOutlet weak var cons_CollectionAspect: NSLayoutConstraint!
 
    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()
            }else{
 
            }
        }).disposed(by: disposeBag)
    }
 
 
    override func setUI() {
        banner_collectionView.delegate = self
        banner_collectionView.dataSource = self
        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 (index,v) in models.enumerated(){
            let point = MAPointAnnotation()
            point.coordinate = CLLocationCoordinate2D(latitude: v.latitude, longitude:v.longitude)
            point.title = v.storeName
            v.index = index
            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)
        view_container.bringSubviewToFront(btn_userLocal)
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        view_container.cornerRadius = 10
    }
 
    @IBAction func customerAction(_ sender: Any) {
        let vc = CustomerListVC()
        push(vc: vc)
    }
 
    @IBAction func privilegeAction(_ sender: UIButton) {
        let vc = JoinMemberIntroduceVC()
        push(vc: vc)
    }
 
    @IBAction func userLocationAction(_ sender: Any) {
        let userCoordinate = mapView.userLocation.coordinate
        mapView.setCenter(userCoordinate, animated: true)
    }
    
 
    @IBAction func aboutMinProgram(_ sender: Any) {
 
        CommonAlertView.show(title: "提示", content: "即将打开小程序,是否继续?") { status in
            if status{
                let miniProgam = WXLaunchMiniProgramReq.object()
                miniProgam.userName = WeChatMinProgram
                #if DEBUG
                miniProgam.miniProgramType = .preview
                #else
                miniProgam.miniProgramType = .release
                #endif
                miniProgam.path = WeChatMinProgramPath
                WXApi.send(miniProgam) { s in
                    if !s{
                        alert(msg: "打开失败")
                    }
                }
            }
        }
    }
 
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .darkContent
    }
}
 
extension SearchVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        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 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
    }
}
 
 
extension SearchVC:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.6541)
    }
}
 
extension SearchVC:MAMapViewDelegate{
 
    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"))
    }
}