|
@@ -0,0 +1,184 @@
|
|
|
+//
|
|
|
+// PublishAddressPOIView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/6/17.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import RxSwift
|
|
|
+import RxCocoa
|
|
|
+
|
|
|
+class PublishAddressPOIView: BaseView {
|
|
|
+
|
|
|
+ typealias DidSelectBlock = (_ latitude:String,_ longitude:String,_ address:String) -> Void
|
|
|
+ var didSelectBlock : DidSelectBlock?
|
|
|
+
|
|
|
+ var suggestionList : Array<BMKSuggestionInfo>?
|
|
|
+
|
|
|
+ var locationAddress: String? {
|
|
|
+ didSet {
|
|
|
+ tableView.reloadSections([0], with: UITableView.RowAnimation.fade)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// 纬度
|
|
|
+ var latitude : String = LocationModel.shared().getLocationModel()?.latitude ?? "34.20840377740726"
|
|
|
+ /// 经度
|
|
|
+ var longitude : String = LocationModel.shared().getLocationModel()?.longitude ?? "108.96265686107972"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ override func setupViews() {
|
|
|
+
|
|
|
+ addSubview(searchBgView)
|
|
|
+
|
|
|
+ searchBgView.addSubview(bottomLine)
|
|
|
+ searchBgView.addSubview(addressLabel)
|
|
|
+ addSubview(tableView)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ searchBgView.snp.makeConstraints { (make) in
|
|
|
+ make.top.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(kScaleValue(value: 60))
|
|
|
+ }
|
|
|
+ bottomLine.snp.makeConstraints { (make) in
|
|
|
+ make.left.right.bottom.equalToSuperview()
|
|
|
+ make.height.equalTo(0.5)
|
|
|
+ }
|
|
|
+
|
|
|
+ addressLabel.snp.remakeConstraints { (make) in
|
|
|
+ make.centerY.equalTo(searchBgView.snp.centerY)
|
|
|
+ make.left.equalTo(kScaleValue(value: 8))
|
|
|
+ }
|
|
|
+
|
|
|
+ tableView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(searchBgView.snp.bottom)
|
|
|
+ make.left.right.bottom.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var searchBgView: UIView = {
|
|
|
+ let searchBgView = UIView()
|
|
|
+ searchBgView.backgroundColor = kffffffColor
|
|
|
+ return searchBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var addressLabel: UILabel = {
|
|
|
+ let addressLabel = UILabel()
|
|
|
+ addressLabel.text = LocationModel.shared().getLocationModel()?.city ?? "西安市"
|
|
|
+ addressLabel.textColor = k999999Color
|
|
|
+ addressLabel.font = kScaleRegularFont14
|
|
|
+ return addressLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+// private lazy var searchTextField: UITextField = {
|
|
|
+// let searchTextField = UITextField()
|
|
|
+// searchTextField.placeholder = "输入地理位置"
|
|
|
+// searchTextField.tintColor = kFFA42FColor
|
|
|
+// searchTextField.textColor = k333333Color
|
|
|
+// searchTextField.returnKeyType = .done
|
|
|
+// searchTextField.font = kScaleRegularFont14
|
|
|
+// searchTextField.borderStyle = .none
|
|
|
+// searchTextField.rx.text.orEmpty.changed.subscribe(onNext: { (text) in
|
|
|
+//
|
|
|
+// BaiduMapManager.shared.suggestionSearchPoi(cityname:LocationModel.shared().getLocationModel()?.city ?? "西安市", keyword: text)
|
|
|
+// BaiduMapManager.shared.suggestionSearchSuccessBlock = {
|
|
|
+// [weak self] (suggestionList:Array<BMKSuggestionInfo>) in
|
|
|
+// self?.suggestionList = suggestionList
|
|
|
+// self?.tableView.reloadSections([1], with: UITableView.RowAnimation.fade)
|
|
|
+// }
|
|
|
+// }).disposed(by: disposeBag)
|
|
|
+// return searchTextField
|
|
|
+// }()
|
|
|
+
|
|
|
+ private lazy var bottomLine: UILabel = {
|
|
|
+ let bottomLine = UILabel()
|
|
|
+ bottomLine.backgroundColor = kf5f5f5Color
|
|
|
+ return bottomLine
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var tableView: UITableView = {
|
|
|
+ let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.plain)
|
|
|
+ tableView.delegate = self
|
|
|
+ tableView.dataSource = self
|
|
|
+ tableView.backgroundColor = kffffffColor
|
|
|
+ tableView.estimatedRowHeight = kScaleValue(value: 48)
|
|
|
+ tableView.separatorStyle = .none
|
|
|
+ return tableView
|
|
|
+ }()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - UITableViewDataSource,UITableViewDelegate
|
|
|
+extension PublishAddressPOIView:UITableViewDataSource,UITableViewDelegate {
|
|
|
+
|
|
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
+ switch section {
|
|
|
+ case 0:
|
|
|
+ return 1
|
|
|
+ case 1:
|
|
|
+ if self.suggestionList != nil {
|
|
|
+ return self.suggestionList!.count
|
|
|
+ }else {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
+ let cell = AddressPOITableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ switch indexPath.section {
|
|
|
+ case 0:
|
|
|
+ cell.locationAddress = locationAddress
|
|
|
+ cell.refreshButtonBlock = {
|
|
|
+ BaiduMapManager.shared.startLocation()
|
|
|
+ BaiduMapManager.shared.locationSuccessBlock = {
|
|
|
+ [weak self] in
|
|
|
+ let locationModel = LocationModel.shared().getLocationModel()
|
|
|
+ self?.locationAddress = locationModel?.toString()
|
|
|
+ }
|
|
|
+ BaiduMapManager.shared.locationFalseBlock = {
|
|
|
+ SwiftProgressHUD.shared().showText("定位失败\n重新定位", textAlignment: NSTextAlignment.center)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ cell.suggestionInfo = self.suggestionList?[indexPath.row]
|
|
|
+ break
|
|
|
+ }
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+
|
|
|
+ if let didSelectBlock = self.didSelectBlock {
|
|
|
+ switch indexPath.section {
|
|
|
+ case 0:
|
|
|
+ didSelectBlock(self.latitude,self.longitude,self.locationAddress ?? "")
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ let locationModel = LocationModel.shared().getLocationModel()
|
|
|
+ let suggestionList = self.suggestionList?[indexPath.row]
|
|
|
+ let city = suggestionList?.city ?? ""
|
|
|
+ let district = suggestionList?.district ?? ""
|
|
|
+ let key = suggestionList?.key ?? ""
|
|
|
+ let latitude = "\(suggestionList?.location.latitude ?? 0)"
|
|
|
+ let longitude = "\(suggestionList?.location.longitude ?? 0)"
|
|
|
+ let toString = locationModel!.province + city + district + key
|
|
|
+ didSelectBlock(latitude,longitude,toString)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|