//
|
// 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"))
|
}
|
}
|