123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // IHHotelPickerManager.swift
- // Inhealth
- //
- // Created by weclouds on 2020/3/11.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- class IHHotelPickerManager: NSObject ,IHViewManagerProtocolDelegate{
-
- var provincelist:[DropDownData]?
- /// 懒加载 创建
- lazy var hotelPicker: IHCountryPicker = {
- let picker = IHCountryPicker()
- picker.modalSize = (width: .full, height: .custom(size: 500))
- picker.modalPosition = .bottomCenter
- picker.cornerRadius = 32
- /// 该回调方法可以在本类任意地方写
- // picker.selectedAreaCompleted = { [weak self] (province, city, district) in
- // self?.addressLabel.text = province + " " + city + " " + district
- // }
- return picker
- }()
- //创建主view容器
- lazy var mainView: IHHotelPickerView = {
- let mainView = IHHotelPickerView()
- mainView.delegate = self
- return mainView
- }()
- private var searchFiled:UITextField!
- //私有变量,传递进来的绑定控制器
- private weak var vc : UIViewController?
- override init() {
- super.init()
- notificationRegister()
- }
- //绑定控制器,主要是 绑定viewdidload这个函数
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
-
-
- requestData()
- }
- //布局
- func createUI() {
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight )
- mainView.hotelName = Intermediate.hotelName
- mainView.countryName = Intermediate.countryName
- mainView.countryId = Intermediate.countryId
- self.getProvinceList(Intermediate.countryId)
- getCountriesList()
- self.vc?.view.addSubview(mainView)
- setNavgationBar()
- }
-
- @objc func tapMainView() {
- searchFiled.resignFirstResponder()
- }
- //请求数据
- func requestData() {
-
- }
-
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- func notificationRegister() {
-
- }
-
-
- @objc func itemNotify(_ notify:Notification) {
-
-
-
- }
-
- //获取国家列表
- func getCountriesList() {
- IHAddressService.share.getContryList(requestSuccess: { (countries) in
- self.mainView.countryList = countries
- }) {
-
- }
- }
- //获取省份列表
- func getProvinceList(_ countryId:String) {
- IHAddressService.share.getProvinceList(countryId, requestSuccess: { (provinces) in
- self.mainView.provicelist = provinces
- self.provincelist = provinces
- }) {
-
- }
- }
- func setNavgationBar() {
- let searchBtn = UIBarButtonItem(image: UIImage(named: "搜索"), style: .done, target: self, action: #selector(serachAction))
- self.vc?.navigationItem.rightBarButtonItem = searchBtn
- searchFiled = UITextField(frame: CGRect(x: 0, y: 0, width: 300, height: 44))
- searchFiled.placeholder = "请输入省份名"
- searchFiled.font = UIFont(name: Alibaba_PuHuiTi_Regular, size: 14)
- searchFiled.textColor = UIColor(hexString: "#333333")
- searchFiled.delegate = self
- self.vc?.navigationItem.titleView = searchFiled
- }
- @objc func serachAction(){
- //
- self.mainView.searchText = searchFiled.text
- searchFiled.resignFirstResponder()//注销第一响应者
-
- }
- }
- extension IHHotelPickerManager:IHHotelPickerViewDelegate{
-
- func headerPickerHistroyHotel(_ hotel: DropDownData) {
-
- let picker = IHHistroyHotelPicker()
- picker.modalSize = (width: .full, height: .custom(size: 300))
- picker.modalPosition = .bottomCenter
- picker.cornerRadius = 32
- /// 该回调方法可以在本类任意地方写
- // picker.selectedAreaCompleted = { [weak self] (province, city, district) in
- // self?.addressLabel.text = province + " " + city + " " + district
- // }
- picker.hotel = hotel
- picker.completion = {
- self.vc?.navigationController?.popViewController(animated: false)
- }
- self.vc?.present(picker, animated: true, completion: nil)
- }
-
-
-
-
- func headerPikcerCountry(_ countryId: String) {
- self.getProvinceList(countryId)
- }
- func headerPickHotel() {
-
- IHAreaService.share.getBuildNavData(hotelId: Intermediate.hotelId, requestSuccess: { (buildList) in
-
- //添加一个all
- let allBuild = DropDownData()
- allBuild.id = ""
- allBuild.name = "所有"
- var newlist = [DropDownData]()
- newlist.append(allBuild)
- for build in buildList{
- newlist.append(build)
- }
- let picker = IHFloorPicker()
- let pickerHeight = self.culPickerViewHeight(newlist.count)
- picker.modalSize = (width: .full, height: .custom(size: pickerHeight))
- picker.modalPosition = .bottomCenter
- picker.cornerRadius = 32
- picker.dismissOnTap = false
-
- self.vc?.present(picker, animated: true, completion: nil)
-
- picker.buildList = newlist
- picker.hotelName = Intermediate.hotelName
- picker.completion = {(floor) in
- self.vc?.navigationController?.popViewController(animated: false)
- NotificationCenter.default.post(name: NSNotification.Name(kNotificationIHAddressControllerReloadAddress), object: nil)
-
- }
- }) {
-
- }
- }
-
-
-
- func selectedProvince(_ provinceId: String) {
-
- IHAddressService.share.getCityeList(provinceId, requestSuccess: { (cityList) in
-
- let picker = IHCountryPicker()
- picker.modalSize = (width: .full, height: .custom(size: 500))
- picker.modalPosition = .bottomCenter
- picker.cornerRadius = 32
- if cityList?.count == 0{
- picker.cityId = provinceId
- }
- picker.cityList = cityList
- picker.completion = {
- self.vc?.navigationController?.popViewController(animated: false)
- }
-
- self.vc?.present(picker, animated: true, completion: nil)
-
- }) {
-
- }
- }
- func selectedHotel(_ indexPath: IndexPath) {
- }
-
- func culPickerViewHeight(_ floorCount: Int) ->Float {
- if floorCount == 0 {
- return 76 + 117
- }else{
- //计算行数
- let row : Int = floorCount / 4
- let contentViewHight = 30 * (row + 1) + 10 + 10 + 10 * row
- return 76 + 117 + Float(contentViewHight)
- }
- }
- }
- extension IHHotelPickerManager:UITextFieldDelegate{
- func textFieldDidBeginEditing(_ textField: UITextField) {
- //开始编辑
- }
- func textFieldDidEndEditing(_ textField: UITextField) {
- //结束编辑
- }
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- let currentText = searchFiled.text ?? ""
- let newText = (currentText as NSString).replacingCharacters(in: range, with: string)
- self.mainView.searchText = newText
- log.debug("搜索内容 - \(newText)")
- if newText == "" {
-
- }
- return true
- }
- }
- extension UILocalizedIndexedCollation{
-
- func partitionObjects(array:[AnyObject], collationStringSelector:Selector) -> ([AnyObject], [String]) {
- var unsortedSections = [[AnyObject]]()
-
- //1. Create a array to hold the data for each section
- for _ in self.sectionTitles {
- unsortedSections.append([]) //appending an empty array
- }
-
- //2. Put each objects into a section
- for item in array {
- let index:Int = self.section(for: item, collationStringSelector:collationStringSelector)
- unsortedSections[index].append(item)
- }
- //3. sorting the array of each sections
- var sectionTitles = [String]()
- var sections = [AnyObject]()
- for index in 0 ..< unsortedSections.count { if unsortedSections[index].count > 0 {
- sectionTitles.append(self.sectionTitles[index])
- sections.append(self.sortedArray(from: unsortedSections[index], collationStringSelector: collationStringSelector) as AnyObject)
- }
- }
- return (sections, sectionTitles)
- }
-
-
-
- }
|