Commit de7c6458 authored by lujunye's avatar lujunye

地址列表,地址搜索

parent d0ff7a89
...@@ -388,3 +388,15 @@ func dictChangeString(sender:Dictionary<String, Any>) -> String{ ...@@ -388,3 +388,15 @@ func dictChangeString(sender:Dictionary<String, Any>) -> String{
return str return str
} }
extension String{
static let random_str_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
static func randomStr(len : Int) -> String{
var ranStr = ""
for _ in 0..<len {
let index = Int(arc4random_uniform(UInt32(random_str_characters.count)))
ranStr.append(random_str_characters[random_str_characters.index(random_str_characters.startIndex, offsetBy: index)])
}
return ranStr
}
}
...@@ -12,7 +12,20 @@ import MAMapKit ...@@ -12,7 +12,20 @@ import MAMapKit
import SwiftyJSON import SwiftyJSON
import SwiftDate import SwiftDate
class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource,JiTuoWuXinXiViewDelegate,JiPaiFangShiViewControllerDelegate,ZengZhiServicesViewControllerDelegate,AdressSelectCellDelegate,DZGLViewControllerDelegate,XinZengDiZhiViewControllerDelegate,TitleAndTFBtnCellDelegate,WenDuCellDelegate,LogisticalSelectViewDelegate, UIPickerViewDataSource, UIPickerViewDelegate, GLAlertSelectViewDelegate{ class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource,JiTuoWuXinXiViewDelegate,JiPaiFangShiViewControllerDelegate,ZengZhiServicesViewControllerDelegate,AdressSelectCellDelegate,DZGLViewControllerDelegate,XinZengDiZhiViewControllerDelegate,TitleAndTFBtnCellDelegate,WenDuCellDelegate,LogisticalSelectViewDelegate, UIPickerViewDataSource, UIPickerViewDelegate, GLAlertSelectViewDelegate,CLLocationManagerDelegate, CityListViewControllerDelegate{
func CityListViewControllerLocSelect(loc: cityListDataModel) {
selectLoc = loc.name!
locBtn.setTitle(" " + loc.name!, for: .normal)
locBtn.sizeToFit()
locBtn.snp.updateConstraints({ (make) in
make.right.equalTo(-15)
make.bottom.equalTo(self.navbar.snp_bottom).offset(-7)
make.height.equalTo(30)
make.width.equalTo(self.locBtn.bounds.size.width)
})
}
//时间选择背景 //时间选择背景
var bgBtn:UIButton? var bgBtn:UIButton?
...@@ -277,34 +290,75 @@ class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableVie ...@@ -277,34 +290,75 @@ class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableVie
@IBOutlet weak var rightBtn: UIButton! @IBOutlet weak var rightBtn: UIButton!
@objc func locSelect(){ @objc func locSelect(){
print("locSelect")
cityList(["user_token":UserToken as Any,"nonce_str":String.randomStr(len: 30) as Any], success: { (data) in
let model = data as! cityListModel
if model.data!.count > 0 {
let vc = CityListViewController()
vc.adrDatas = model.data!
vc.locatStr = self.selectLoc
vc.delegate = self
self.navigationController?.pushViewController(vc, animated: true)
}
}) { (err) in
}
}
var manger:CLLocationManager = CLLocationManager()
var selectLoc = ""
lazy var geoCoder: CLGeocoder = {
return CLGeocoder()
}()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
manger.stopUpdatingLocation()
geoCoder.reverseGeocodeLocation(locations.last!) { (pls: [CLPlacemark]?, error: Error?) in
if error == nil {
print("反地理编码成功")
guard let plsResult = pls else {return}
let firstPL = plsResult.first
print(firstPL?.postalAddress?.city)
if self.selectLoc.count == 0 {
self.locBtn.isUserInteractionEnabled = false
self.locBtn.setImage(UIImage(named: "dzdingwei"), for: .normal)
self.locBtn.setTitleColor(UIColor(named: "蓝色字体颜色"), for: .normal)
self.locBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
self.locBtn.addTarget(self, action: #selector(self.locSelect), for: .touchUpInside)
self.locBtn.setTitle(" " + (firstPL?.postalAddress?.city)!, for: .normal)
self.selectLoc = (firstPL?.postalAddress?.city)!
self.locBtn.sizeToFit()
self.view.addSubview(self.locBtn)
self.locBtn.snp_makeConstraints({ (make) in
make.right.equalTo(-15)
make.bottom.equalTo(self.navbar.snp_bottom).offset(-7)
make.height.equalTo(30)
make.width.equalTo(self.locBtn.bounds.size.width)
})
}
}else {
print("错误")
}
}
} }
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
getDay()
locBtn.isUserInteractionEnabled = false
navbar.title = "运单列表" navbar.title = "运单列表"
self.view.addSubview(navbar) self.view.addSubview(navbar)
locBtn.setImage(UIImage(named: "dzdingwei"), for: .normal) manger.delegate = self
manger.requestAlwaysAuthorization()
manger.requestWhenInUseAuthorization()
manger.startUpdatingLocation()
locBtn.setTitle(" " + "请选择", for: .normal) getDay()
locBtn.setTitleColor(UIColor(named: "蓝色字体颜色"), for: .normal)
locBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
locBtn.sizeToFit()
locBtn.addTarget(self, action: #selector(locSelect), for: .touchUpInside)
self.view.addSubview(locBtn)
locBtn.snp_makeConstraints({ (make) in
make.right.equalTo(-15)
make.bottom.equalTo(navbar.snp_bottom).offset(-7)
make.height.equalTo(30)
make.width.equalTo(locBtn.bounds.size.width)
})
SetTopFrame(view: topBtnView, height: 44) SetTopFrame(view: topBtnView, height: 44)
...@@ -328,11 +382,11 @@ class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableVie ...@@ -328,11 +382,11 @@ class XiaYunDanViewController: BaseViewController,UITableViewDelegate,UITableVie
var pickup_time : String? = "" var pickup_time : String? = ""
var day : Int? = 0 //0 今天 1 明天 2 后天 var day : Int? = 0 //0 今天 1 明天 2 后天
var timeData:appointmentTimeDataModel? = nil var timeData:appointmentTimeDataModel? = nil
let UserToken = UserDefaults.standard.value(forKey: "user_token")
func lenyunAppointmentTime() { func lenyunAppointmentTime() {
HUD.flash(.progress) HUD.flash(.progress)
let UserToken = UserDefaults.standard.value(forKey: "user_token")
appointmentTime(["user_token":UserToken as Any], success: { (data) in appointmentTime(["user_token":UserToken as Any], success: { (data) in
let dataModel = data as! appointmentTimeModel let dataModel = data as! appointmentTimeModel
self.timeData = dataModel.data self.timeData = dataModel.data
......
...@@ -61,7 +61,12 @@ class YunDanXiangQingViewController: BaseViewController,UITableViewDelegate,UITa ...@@ -61,7 +61,12 @@ class YunDanXiangQingViewController: BaseViewController,UITableViewDelegate,UITa
listView.register(UINib(nibName: "TitleAndLblCell", bundle: nil), forCellReuseIdentifier: "TitleAndLblCell") listView.register(UINib(nibName: "TitleAndLblCell", bundle: nil), forCellReuseIdentifier: "TitleAndLblCell")
loadData() loadData()
self.bottomH.constant = 83
if ScreenHeight < 896 {
self.bottomH.constant = 49
}
} }
@IBOutlet weak var bottomH: NSLayoutConstraint! @IBOutlet weak var bottomH: NSLayoutConstraint!
......
...@@ -7,23 +7,118 @@ ...@@ -7,23 +7,118 @@
// //
import UIKit import UIKit
protocol CityListViewControllerDelegate {
func CityListViewControllerLocSelect(loc:cityListDataModel)
}
class CityListViewController: BaseViewController ,UITableViewDelegate,UITableViewDataSource, UISearchBarDelegate, SearchBarViewDelegate{
//MAKR:--调起搜索后添加个蒙版本
var delegate:CityListViewControllerDelegate?
var keyword = ""
var blackBtnView:UIButton! = nil
var searchList:UITableView!
var searchArr:Array<cityListDataModel> = []
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("点击搜索进行--")
searchBar.resignFirstResponder()
keyword = searchBar.text!
searchArr.removeAll()
for item in adrDatas {
if (item.name?.contains(keyword))! || (item.name_en?.contains(keyword.localizedLowercase))!{
searchArr.append(item)
}
}
if searchList == nil {
searchList = UITableView()
self.view.addSubview(searchList)
searchList.snp.makeConstraints { (make) in
make.top.equalTo(topView.snp.bottom)
make.left.right.bottom.equalToSuperview()
}
searchList.delegate = self
searchList.dataSource = self
searchList.register(UINib(nibName: "TitleContentCell", bundle: nil), forCellReuseIdentifier: "TitleContentCell")
}
searchList.isHidden = false
searchList.reloadData()
}
//MARK:--取消搜索代理
func clearSearchAction() {
print("取消搜索代理了--")
}
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
print("编辑即将结束了--")
removeBlackBtnView()
if searchBar.text?.count == 0 && keyword.count != 0{
keyword = searchBar.text!
}
if searchBar.text!.count == 0 {
searchList.isHidden = true
}
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
print("调起搜索后添加个蒙版本")
blackBtnView = UIButton ()
blackBtnView.backgroundColor = UIColor.init(named: "提示视图背景色")
self.view.addSubview(blackBtnView)
blackBtnView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(topView!.snp_bottom)
}
blackBtnView.addTarget(self, action: #selector(removeBlackBtnView), for: .touchUpInside)
return true
}
@objc func removeBlackBtnView(){
if blackBtnView != nil {
blackBtnView.removeFromSuperview()
searchBr.resignFirstResponder()
}
}
class CityListViewController: BaseViewController ,UITableViewDelegate,UITableViewDataSource{
@IBOutlet weak var locLbl: UILabel!
@IBOutlet weak var listView: UITableView! @IBOutlet weak var listView: UITableView!
@IBOutlet weak var topView: UIView! @IBOutlet weak var topView: UIView!
var locatStr = ""
let adHeaders:[String] = ["A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
var adrDatas:Array<cityListDataModel> = []
var datas:Array<Dictionary<String,Array<cityListDataModel>>> = []
var adHeaders:[String] = ["A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] var searchBr:SearchBarView!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
navbar.title = "城市列表" navbar.title = "城市列表"
locLbl.text = locatStr
for chart in adHeaders {
var arr:Array<cityListDataModel> = []
for item in adrDatas {
if "\(item.name_en!.first!)" == chart.localizedLowercase {
arr.append(item)
}
}
if arr.count > 0 {
var dict:Dictionary<String,Array<cityListDataModel>> = Dictionary()
dict[chart] = arr
datas.append(dict)
}
}
self.view.addSubview(navbar) self.view.addSubview(navbar)
SetTopFrame(view: topView, height: 50) SetTopFrame(view: topView, height: 50)
listView.separatorStyle = .none listView.separatorStyle = .none
listView.register(UINib(nibName: "TitleContentCell", bundle: nil), forCellReuseIdentifier: "TitleContentCell") listView.register(UINib(nibName: "TitleContentCell", bundle: nil), forCellReuseIdentifier: "TitleContentCell")
let searchBr = SearchBarView.init() searchBr = SearchBarView.init()
searchBr.delegate = self
searchBr.delegateL = self
topView.addSubview(searchBr) topView.addSubview(searchBr)
searchBr.snp.makeConstraints { (make) in searchBr.snp.makeConstraints { (make) in
make.left.equalTo(10) make.left.equalTo(10)
...@@ -33,30 +128,63 @@ class CityListViewController: BaseViewController ,UITableViewDelegate,UITableVie ...@@ -33,30 +128,63 @@ class CityListViewController: BaseViewController ,UITableViewDelegate,UITableVie
} }
searchBr.placeholderStr = "请输入城市名称或拼音" searchBr.placeholderStr = "请输入城市名称或拼音"
searchBr.cornerRadius = 35/2.0 searchBr.cornerRadius = 35/2.0
var titlesArr:Array<String> = []
listView.customIndexView(indexTitles: adHeaders) for item in datas {
titlesArr.append(item.keys.first!)
}
listView.customIndexView(indexTitles: titlesArr)
listView.indexView = CustomIndexView() listView.indexView = CustomIndexView()
} }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath) print(indexPath)
if tableView == searchList {
delegate?.CityListViewControllerLocSelect(loc: searchArr[indexPath.row])
}else{
let item = datas[indexPath.section]
let key = item.keys.first
let arr = item[key!]
delegate?.CityListViewControllerLocSelect(loc: arr![indexPath.row])
}
self.navigationController?.popViewController(animated: true)
} }
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 45 return 45
} }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5 if tableView == searchList {
return searchArr.count
}
if datas.count == 0 {
return 0
}
let dict = datas[section]
let arr = dict[dict.keys.first!]
return arr!.count
} }
func numberOfSections(in tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
return adHeaders.count; if tableView == searchList {
return 1
}
return datas.count;
} }
@IBAction func back(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TitleContentCell") as! TitleContentCell let cell = tableView.dequeueReusableCell(withIdentifier: "TitleContentCell") as! TitleContentCell
cell.contentLbl.isHidden = true cell.contentLbl.isHidden = true
if tableView == searchList {
let secno = indexPath.section let item = searchArr[indexPath.row]
cell.titleLbl?.text = self.adHeaders[secno]+String(indexPath.item) cell.titleLbl.text = item.name
}else{
let dict = datas[indexPath.section]
let key = dict.keys.first
let arr = dict[key!]
let item = arr![indexPath.row]
cell.titleLbl?.text = item.name
}
return cell return cell
} }
...@@ -68,8 +196,8 @@ class CityListViewController: BaseViewController ,UITableViewDelegate,UITableVie ...@@ -68,8 +196,8 @@ class CityListViewController: BaseViewController ,UITableViewDelegate,UITableVie
let view = UIView() let view = UIView()
view.backgroundColor = UIColor.init(named: "app底色") view.backgroundColor = UIColor.init(named: "app底色")
let cityLbl = UILabel() let cityLbl = UILabel()
let headers = self.adHeaders
cityLbl.text = headers[section] cityLbl.text = self.datas[section].keys.first
cityLbl.textColor = UIColor.init(named: "灰色字体颜色") cityLbl.textColor = UIColor.init(named: "灰色字体颜色")
cityLbl.font = UIFont.systemFont(ofSize: 11) cityLbl.font = UIFont.systemFont(ofSize: 11)
view.addSubview(cityLbl) view.addSubview(cityLbl)
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CityListViewController" customModule="TestClass" customModuleProvider="target"> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CityListViewController" customModule="TestClass" customModuleProvider="target">
<connections> <connections>
<outlet property="listView" destination="m37-8o-DjS" id="ZAF-AI-0qc"/> <outlet property="listView" destination="m37-8o-DjS" id="ZAF-AI-0qc"/>
<outlet property="locLbl" destination="qHG-ov-SKf" id="hbc-e6-UaS"/>
<outlet property="topView" destination="vCi-ZI-P2x" id="M0Z-eu-pbV"/> <outlet property="topView" destination="vCi-ZI-P2x" id="M0Z-eu-pbV"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections> </connections>
...@@ -48,18 +49,28 @@ ...@@ -48,18 +49,28 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Abe-oY-g1U"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Abe-oY-g1U">
<rect key="frame" x="0.0" y="30" width="414" height="45"/> <rect key="frame" x="0.0" y="30" width="414" height="45"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="广州" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3pq-KF-qmk"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qHG-ov-SKf">
<rect key="frame" x="15" y="13" width="27" height="16"/> <rect key="frame" x="15" y="15" width="33" height="16"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/> <fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" name="标题字颜色"/> <color key="textColor" name="标题字颜色"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mda-E8-YM7">
<rect key="frame" x="0.0" y="0.0" width="414" height="45"/>
<connections>
<action selector="back:" destination="-1" eventType="touchUpInside" id="pvA-dm-rAH"/>
</connections>
</button>
</subviews> </subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints> <constraints>
<constraint firstItem="3pq-KF-qmk" firstAttribute="top" secondItem="Abe-oY-g1U" secondAttribute="top" constant="13" id="Fwx-FJ-COu"/> <constraint firstItem="mda-E8-YM7" firstAttribute="top" secondItem="Abe-oY-g1U" secondAttribute="top" id="42C-BF-Xei"/>
<constraint firstItem="qHG-ov-SKf" firstAttribute="top" secondItem="Abe-oY-g1U" secondAttribute="top" constant="15" id="7aY-44-xeq"/>
<constraint firstAttribute="trailing" secondItem="mda-E8-YM7" secondAttribute="trailing" id="9o9-K5-50f"/>
<constraint firstItem="mda-E8-YM7" firstAttribute="leading" secondItem="Abe-oY-g1U" secondAttribute="leading" id="A8J-3X-dJu"/>
<constraint firstItem="qHG-ov-SKf" firstAttribute="leading" secondItem="Abe-oY-g1U" secondAttribute="leading" constant="15" id="NdU-Iu-uK8"/>
<constraint firstAttribute="height" constant="45" id="aSn-ym-FV6"/> <constraint firstAttribute="height" constant="45" id="aSn-ym-FV6"/>
<constraint firstItem="3pq-KF-qmk" firstAttribute="leading" secondItem="Abe-oY-g1U" secondAttribute="leading" constant="15" id="nyA-8i-7f6"/> <constraint firstAttribute="bottom" secondItem="mda-E8-YM7" secondAttribute="bottom" id="v1e-Wg-8EQ"/>
</constraints> </constraints>
</view> </view>
</subviews> </subviews>
......
...@@ -87,9 +87,10 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo ...@@ -87,9 +87,10 @@ class ToAndFormSelectViewController: BaseViewController, MAMapViewDelegate, CLLo
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
let searchBr = SearchBarView.init() let searchBr = SearchBarView.init()
navBgView.addSubview(searchBr) navBgView.addSubview(searchBr)
searchBr.snp.makeConstraints { (make) in searchBr.snp.makeConstraints { (make) in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment