123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- //
- // IHFloorMapSelectedView.swift
- // Inhealth
- //
- // Created by weclouds on 2020/1/14.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- protocol IHFloorMapSelectedViewDelegate : NSObjectProtocol {
- func selected(build:DropDownData,floor:RoomListData)
- }
- class IHFloorMapSelectedView: UIView {
- weak var delegate :IHFloorMapSelectedViewDelegate?
- var hotelId :String? = "0"
- var buildId:String? = "0"
- var buildListData : [DropDownData]?{
- didSet{
- }
- }
- deinit {
- log.debug("IHFloorMapSelectedView销毁")
- }
- var floorList:[RoomListData]?
- var selectedBuildIndex:Int? = 0
- var selectedFloorIndex:Int? = 0
-
- lazy var pickerView: UIPickerView = {
- let pickerView = UIPickerView(frame: CGRect(x: 0, y: 45, width: KSCREENWIDTH, height: 180))
- pickerView.delegate = self
- pickerView.dataSource = self
- return pickerView
- }()
- var bottomView:UIView?
- var cancelButton :UIButton?
- var confirmButton :UIButton?
-
- convenience init(buildListData:[DropDownData]) {
- self.init()
- if buildListData .count > 0{
- self.buildListData = buildListData
- self.pickerView.reloadComponent(0)
- if let datalist = self.buildListData {
-
- //默认后去第一个楼房的楼层
- let firstBuild = datalist[0]
- self.getFloorList(firstBuild.id!)
- self.buildId = firstBuild.id
-
- }
- }
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func show() {
- self.pickerView.selectRow(0, inComponent: 0, animated: false)
- selectedBuildIndex = 0
-
- UIApplication.shared.keyWindow?.addSubview(self)
- self.alpha = 0
- UIView.animate(withDuration: 0.3) {
- self.alpha = 1
- }
- }
- func dismiss() {
- UIView.animate(withDuration: 0.3, animations: {
- self.alpha = 0
- }) { (finished) in
- self.removeFromSuperview()
- }
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- dismiss()
- }
- }
- extension IHFloorMapSelectedView{
-
- func createUI() {
- self.backgroundColor = UIColor.black.withAlphaComponent(0.3)
- self.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT)
- let whiteView = UIView(frame: CGRect(x: 0, y: KSCREENHEIGHT - 260, width: KSCREENWIDTH, height: 260))
- whiteView.backgroundColor = UIColor.white
- addSubview(whiteView)
- //按钮所在区域
- let viewBg = UIView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: 45 ))
- whiteView.addSubview(viewBg)
-
- //创建取消 确定按钮
- let cancelButton = UIButton(type: .custom)
- cancelButton.frame = CGRect(x: 20, y: 0, width: 50, height: 45)
- cancelButton.setTitle("取消", for: .normal)
- cancelButton.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 13)
- cancelButton.setTitleColor(UIColor.darkGray, for: .normal)
- cancelButton.addTarget(self, action: #selector(cancelButtonAction), for: .touchUpInside)
- viewBg.addSubview(cancelButton)
-
- let confirmButton = UIButton(type: .custom)
- confirmButton.frame = CGRect(x:KSCREENWIDTH - 70, y: 0, width: 50, height: 45)
- confirmButton.setTitle("确定", for: .normal)
- confirmButton.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 13)
- confirmButton.setTitleColor(UIColor.darkGray, for: .normal)
- confirmButton.addTarget(self, action: #selector(confirmButtonAction), for: .touchUpInside)
- viewBg.addSubview(confirmButton)
-
- whiteView.addSubview(self.pickerView)
- }
-
-
- @objc func cancelButtonAction() {
-
- dismiss()
- }
- @objc func confirmButtonAction() {
- if let delegate = self.delegate {
- let build = self.buildListData![selectedBuildIndex!]
- let floor = self.floorList![selectedFloorIndex!]
- delegate.selected(build: build, floor: floor)
- }
- dismiss()
- }
-
-
-
- func requestData() {
- IHAreaService.share.getBuildNavData(hotelId: nil, requestSuccess: { (dataList) in
- self.buildListData = dataList
- }) {
-
- }
- }
-
- func getFloorList(_ buildId:String) {
-
- IHAreaService.share.getRoomListData(buildId: buildId, keyworkds: nil, requestSuccess: { (roomlist) in
- self.floorList = roomlist
- self.pickerView.reloadComponent(1)
- self.pickerView.selectRow(0, inComponent: 1, animated: true)
- self.selectedFloorIndex = 0
-
- }) {
-
- }
- }
- }
- extension IHFloorMapSelectedView: UIPickerViewDataSource,UIPickerViewDelegate{
-
- func numberOfComponents(in pickerView: UIPickerView) -> Int {
- return 2
- }
- func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
- if component == 0 {
- return self.buildListData?.count ?? 0
- }else if component == 1{
- return self.floorList?.count ?? 0
- }
- return 0
- }
- func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
- return 30
- }
- func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
- if component == 0 {
- let buildLabel = UILabel(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH / 2, height: 30))
- buildLabel.textColor = UIColor(hexString: "222222")
- buildLabel.font = UIFont(name: PingFangSC_Regular, size: 15)
- buildLabel.textAlignment = .center
- let model = self.buildListData![row]
- buildLabel.text = model.name
- return buildLabel
- }else if component == 1{
- let floorLabel = UILabel(frame: CGRect(x: KSCREENWIDTH / 2, y: 0, width: KSCREENWIDTH / 2, height: 30))
- floorLabel.textColor = UIColor(hexString: "222222")
- floorLabel.font = UIFont(name: PingFangSC_Regular, size: 15)
- floorLabel.textAlignment = .center
- let model = self.floorList![row]
- floorLabel.text = model.name
- return floorLabel
- }
- return UIView()
- }
-
- func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
- if component == 0 {
- selectedBuildIndex = row
- let build = self.buildListData![row]
- getFloorList(build.id!)
- } else {
- selectedFloorIndex = row
- }
- }
- }
|