123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864 |
- //
- // IHNewEquipmentView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/14.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- struct EquipmentInfo {
- var floorId:String?
- var roomId:String?
- var deviceType:String?
- var deviceName:String?
- var deviceID:String? //
- var imagePath :String? //存储图片地址
- var deviceImage:UIImage? //存储设备图片
- var inspecTime :String? //巡检时间
- var lightMode:String? //灯控类型
- var type : String? // 学校 设备类型(4 教室灯,5 黑板灯,6 窗帘,7 面板)
- var gatewayId : String? //网关id
- var lightId : String? //编辑时,有值
-
- }
- enum EquipmentError {
- case success
- case lackImage //缺少图片
- case lackDeviceName // 缺少设备名称
- case lackDeviceID // 缺少设备id
- case lackFloorId
- case lackRoomId //缺少房间
- case lackInspecTime // 缺少巡检时间
- }
- protocol IHNewEquipmentViewDelegate : NSObjectProtocol{
- func selectedPhoto()
- ///保存设备信息
- func storageDeviceInformation(_ infomation:EquipmentInfo?,error:EquipmentError)
- func scanQRCode()
-
- }
- let kNotifactionIHNewEquipmentViewUploadImageFinished = "kNotifactionIHNewEquipmentViewUploadImageFinished"
- let kIHNewEquipmentViewNotificationGetDeviceImage = "kIHNewEquipmentViewNotificationGetDeviceImage"
- class IHNewEquipmentView: UIView {
-
- fileprivate var isEditDeviceType = false
- //只读
- var isBeginEdit:Bool? {
- return isEditContent()
- }
- //是否学校
- var isSchool : String = "0"
- var tempImage:UIImage?
- var devType:String? = "0"
- weak var delegate : IHNewEquipmentViewDelegate?
- //所有的网关
- var gatewayList :[GatewayData]?{
- didSet{
- if let gatewayList = self.gatewayList{
- self.gatewayIdLabel.text = gatewayList.first?.gatewayId
- }
- }
- }
- var devData :DevData?{
- didSet{
-
- if let devData = self.devData {
- if let image = devData.image,let type = devData.devType,let name = devData.name,let devId = devData.deviceId,let roomNumber = devData.number,let floor = devData.floor ,let roomId = devData.roomId , let floorId = devData.floorId,let gatewayId = devData.gatewayId {
- self.devType = type
-
- DeviceImage.netImage(url: image, placeholder: "Sensor--Device Information")
- DeviceImage.contentMode = .scaleToFill // 平铺
- deviceNameLabel.text = name
- deviceID.text = devId
- if type == "1" {
- deviceTypelabel.text = "灯控"
-
- }else if type == "2"{
- deviceTypelabel.text = "HCL灯控"
- }else if type == "3"{
- deviceTypelabel.text = "感应器"
-
- }else if type == "4"{
- deviceTypelabel.text = "空气净化器"
-
- }
- if type == "1" || type == "2" {
- self.LightModeBox.isHidden = false
- if let mode = devData.mode {
- var modeString = ""
- if mode == "0" {
- modeString = "WE-L10"
- }else if mode == "1"{
- modeString = "WE-L20"
- }else if mode == "2"{
- modeString = "WE-CL10"
- }else if mode == "3"{
- modeString = "WE-CL20"
- }else if mode == "4"{
- modeString = "WE-L10-EP"
- }else if mode == "5"{
- modeString = "WE-L20-EP"
- }else if mode == "6"{
- modeString = "WE-CL10-EP"
- }
- self.modeStr = modeString
- self.lightModeLabel.text = modeString
- }
-
- }else{
- self.LightModeBox.isHidden = true
- }
- floorLabel.text = floor
- roomLabel.text = roomNumber
- self.roomStr = roomNumber
- self.floorStr = floor
- self.imagePath = image
- self.roomId = roomId
- self.floorId = floorId
- self.gatewayIdLabel.text = gatewayId
- }
- }
- }
- }
-
- var gateway:GatewayData?{
- didSet{
- if let gateway = self.gateway {
- if let gatewayName = gateway.network_name,let deviceId = gateway.gatewayId,let floor = gateway.floor,let floorId = gateway.floor,let roomNumber = gateway.roomNumber,let roomId = gateway.roomId,let inspecTime = gateway.inspecTime{
- DeviceImage.image = UIImage(named: "gateway_Information")
- DeviceImage.contentMode = .scaleToFill // 平铺
- deviceNameLabel.text = gatewayName
- deviceID.text = deviceId
- deviceTypelabel.text = "网关"
- floorLabel.text = floor
- roomLabel.text = roomNumber
- self.roomStr = roomNumber
- self.floorStr = floor
- let time = Int(inspecTime)
- var inspecTimeString = ""
- if time! < 60 {
- inspecTimeString = inspecTime + "min"
- }else if time == 60 {
- inspecTimeString = "1hour"
- }else{
- inspecTimeString = "\(time! / 60)hours"
- }
-
- inspectionCycleLabel.text = inspecTimeString
- self.inspecTimeStr = inspecTimeString
- self.imagePath = "-"
- self.roomId = roomId
- self.floorId = floorId
- self.saveInspecTime = inspecTime
-
- }
- }
- }
- }
- var equipmentStyle:NewEquipmentRoomStyle? {
- didSet{
- if let style = self.equipmentStyle {
- switch style {
- case .newRoom:
- log.debug("新建房间")
- self.roomBox.isHidden = true
- deviceTypeBox.isUserInteractionEnabled = true
- self.typeViewTopToImageConstraint.constant = 30
- self.gatewayBox.isHidden = true
- case .oldRoom:
- log.debug("在room里设置")
- self.roomBox.isHidden = true
- deviceTypeBox.isUserInteractionEnabled = true
- self.typeViewTopToImageConstraint.constant = 30
-
- case .equipmentList:
- log.debug("设备列表新建设备")
- self.roomBox.isHidden = false
- rightPoint.isHidden = false
- self.InspectionBox.isHidden = true
- self.typeViewTopToImageConstraint.constant = 170
- self.InspectionBox.isUserInteractionEnabled = false
- if self.isSchool == "0" {
- //不是学校里隐藏
- self.gatewayBox.isHidden = true
- }else{
- //学校- 可以交互
- self.gatewayBox.isUserInteractionEnabled = true
- }
- case .equipmentEdit:
- log.debug("编辑设备")
- self.roomBox.isHidden = false
- rightPoint.isHidden = true
- deviceTypeBox.isUserInteractionEnabled = false
- self.typeViewTopToImageConstraint.constant = 170
- // self.InspectionBox.isUserInteractionEnabled = false
- if self.isSchool == "0" {
- //不是学校里隐藏
- self.gatewayBox.isHidden = true
- }else{
- //学校
- self.gatewayImage.isHidden = true
- }
- case .gatewayEdit:
- log.debug("编辑网关")
- self.DeviceImage.isUserInteractionEnabled = false
- deviceTypeBox.isUserInteractionEnabled = false
- rightPoint.isHidden = true
- self.uploadImageIcon.isHidden = true
- self.roomBox.isHidden = false
- self.LightModeBox.isHidden = true
- self.InspectionBox.isHidden = false
- self.InspectionBox.isUserInteractionEnabled = true
- self.typeViewTopToImageConstraint.constant = 170
- }
- }
- }
- }
-
- var floorList:[RoomListData]?{
- didSet{
- floorNames = IHCentrlizedService.share.getFloorNameList(from: self.floorList)
-
- if self.equipmentStyle == .equipmentEdit || self.equipmentStyle == .gatewayEdit {
-
- }else{
- floorLabel.text = floorNames?.first
- }
-
-
- if floorNames != nil || floorNames!.count > 0 {
- floorLabel.reset()
- //获取第一层楼的房间列表
- roomNames = IHCentrlizedService.share.getFirstRooms(self.floorList)
- // if self.equipmentStyle != .equipmentEdit || self.equipmentStyle != .gatewayEdit {
- //
- // }else{
- // roomLabel.text = roomNames?.first
- // }
-
- //改
- if self.equipmentStyle != .equipmentEdit || self.equipmentStyle != .gatewayEdit {
- roomLabel.text = roomNames?.first
- }
-
- if self.equipmentStyle != .equipmentEdit {
- //第一个房间id
- self.roomId = IHCentrlizedService.share.getFirstRoomID(self.floorList)
- }
- }else{
- floorLabel.isEmpty("Please chose Floor")
- }
- //f
- if self.equipmentStyle != .equipmentEdit {
- selectedFloor = self.floorList?.first // 默认选择第一个
- }
-
- }
- }
- var saveInspecTime:String? = "5"
- var floorId:String?
- var roomId:String?
- var floorStr :String?
- var roomStr :String?
- var modeStr :String? = "WE-L10"
- var inspecTimeStr:String?
- var selectedFloor: RoomListData?{
- didSet{
- self.floorId = self.selectedFloor?.id
- }
- }
-
- var floorNames :[String]?
-
- var roomNames :[String]?
-
- @IBOutlet weak var LightModeBox: UIView!
- @IBOutlet weak var lightModeLabel: UILabel!
-
- @IBOutlet weak var InspectionBox: UIView!
- @IBOutlet weak var inspectionCycleLabel: UILabel!
-
- @IBOutlet weak var roomBox: UIView!
-
- @IBOutlet weak var floorBox: UIView!
-
-
- @IBOutlet weak var roomView: UIView!
-
- @IBOutlet weak var roomLabel: UILabel!
-
- @IBOutlet weak var floorLabel: UILabel!
-
- @IBOutlet weak var typeViewTopToImageConstraint: NSLayoutConstraint!
-
- @IBOutlet weak var DeviceImage: UIImageView!
-
- @IBOutlet weak var uploadImageIcon: UIImageView!
-
- @IBOutlet weak var deviceTypeBox: UIView!
-
- @IBOutlet weak var deviceTypelabel: UILabel!
-
- @IBOutlet weak var deviceNameLabel: UITextField!
-
- @IBOutlet weak var deviceID: UITextField!
-
- @IBOutlet weak var rightPoint: UIImageView!
-
- @IBOutlet weak var gatewayBox: UIView!
-
- @IBOutlet weak var gatewayIdLabel: UILabel!
-
- @IBOutlet weak var gatewayImage: UIImageView!
- var isPickImageFinished:Bool? = false
-
- var imagePath :String?
- override func awakeFromNib() {
- super.awakeFromNib()
- notifacionRegister() //注册通知
- setupUI()
- addGesture()
-
- }
-
- override func layoutSubviews() {
- super.layoutSubviews()
-
- if isSchool == "1"{
- //devData
- if let devData = self.devData{
- //4 教室灯,5 黑板灯,6 窗帘,7 面板)
- switch devData.type {
- case "4":
- self.deviceTypelabel.text = "教室灯"
- case "5":
- self.deviceTypelabel.text = "黑板灯"
- case "6":
- self.deviceTypelabel.text = "窗帘"
- default:
- self.deviceTypelabel.text = "面板"
- }
-
- }
- self.lightModeLabel.text = "EL-DP02-1200-LY"
- if self.equipmentStyle == .equipmentEdit{
- self.gatewayBox.frame = self.InspectionBox.frame
- }
- }
- }
-
- deinit {
- //注销通知
- notifactionUnRegister()
- }
-
- @IBAction func preseveAction(_ sender: Any) {
- var error = EquipmentError.success
- var deviceInfo = EquipmentInfo()
- log.debug("selectedFloor?.name - \(selectedFloor?.name) === selectedFloor?.id - \(selectedFloor?.id) - \(self.floorId)")
- if self.deviceNameLabel.text == nil || self.deviceNameLabel.text == " "{
- HUD.flash(.label("设备名称不能为空"), delay: 0.7)
- return
- }
- if self.deviceID.text == nil || self.deviceID.text! == " "{
- HUD.flash(.label("设备ID不能为空"), delay: 0.7)
- return
- }
- //&& self.floorId != nil && self.roomId != nil
- if self.deviceNameLabel.text != nil && self.deviceNameLabel.text != " " &&
- self.deviceID.text != nil && self.deviceID.text != " " {
- error = .success
- deviceInfo.imagePath = self.imagePath
- deviceInfo.deviceType = self.devType
- deviceInfo.deviceName = self.deviceNameLabel.text
- deviceInfo.deviceID = self.deviceID.text
- deviceInfo.deviceImage = self.DeviceImage.image
- deviceInfo.floorId = self.floorId
- deviceInfo.roomId = self.roomId
- //选网关
- if gatewayList?.count ?? 0 > 0{
- for gateItem in gatewayList!{
- if self.floorId == gateItem.floorId{
- deviceInfo.gatewayId = gateItem.gatewayId
- }
- }
- }
-
- }
-
- if self.equipmentStyle != .oldRoom && self.equipmentStyle != .newRoom {
- if self.floorId != nil && self.roomId != nil {
-
- }
-
- if self.roomId == nil {
- error = .lackRoomId
- }
- if self.floorId == nil {
- error = .lackFloorId
- }
- }
- //
-
- if self.deviceID.text == "" || self.deviceID.text == nil {
- error = .lackDeviceID
- }
-
- //self.deviceNameLabel.text?.isBlanck == true 判断是否空格情况
- if self.deviceNameLabel.text == "" || self.deviceNameLabel.text == nil || self.deviceNameLabel.text?.isBlanck == true {
- error = .lackDeviceName
- }
- //先判断这个
- if isSchool == "0"{
- if self.devType != "4"{
- if self.devType == "0" || self.devType == "1" {
- var lightMode = "0"
- //"WE-L10","WE-L20","WE-CL10","WE-CL20" "WE-L10-EP","WE-L20-EP","WE-CL10-EP"
- if self.modeStr == "WE-L10" {
- lightMode = "0"
- }else if self.modeStr == "WE-L20" {
- lightMode = "1"
- }else if self.modeStr == "WE-CL10" {
- lightMode = "2"
- }else if self.modeStr == "WE-CL20" {
- lightMode = "3"
- }else if self.modeStr == "WE-L10-EP" {
- lightMode = "4"
- }else if self.modeStr == "WE-L20-EP" {
- lightMode = "5"
- }else if self.modeStr == "WE-CL10-EP" {
- lightMode = "6"
- }
- deviceInfo.lightMode = lightMode
- }
- if self.devType == "2"{
- switch self.modeStr {
- case "IH-SR01":
- deviceInfo.lightMode = "0"
- case "IH-SR02":
- deviceInfo.lightMode = "1"
- case "IH-SR03":
- deviceInfo.lightMode = "2"
- case "IH-SR04":
- deviceInfo.lightMode = "3"
- default:
- deviceInfo.lightMode = "4"
- }
- }
- if self.devType == "3"{
- switch self.modeStr {
- case "IH-AP01":
- deviceInfo.lightMode = "0"
- case "IH-AP02":
- deviceInfo.lightMode = "1"
- default:
- deviceInfo.lightMode = "2"
- }
- }
-
- }
- }else{
- //学校
-
- if self.gatewayIdLabel.text == "" {
- HUD.flash(.label("未绑定网关"), delay: 0.7)
- return
- }
- deviceInfo.gatewayId = self.gatewayIdLabel.text
-
- if self.deviceTypelabel.text == "教室灯"{
- //设备型号(教室灯 0=>EL-DP02-1200-LY,1=>EL-DP03-1200-LY,2=>EL-WKDP03-1200-LY,黑板灯 0=>EL-HZJ01-1200-LY)
- if self.lightModeLabel.text == "EL-DP02-1200-LY" {
- deviceInfo.lightMode = "0"
- }else if self.lightModeLabel.text == "EL-DP03-1200-LY" {
- deviceInfo.lightMode = "1"
- }else {
- deviceInfo.lightMode = "2"
- }
- deviceInfo.type = "4"
- }
- if self.deviceTypelabel.text == "黑板灯" {
- deviceInfo.lightMode = "0"
- deviceInfo.type = "5"
- }
- if self.deviceTypelabel.text == "窗帘"{
- deviceInfo.type = "6"
- deviceInfo.lightMode = "0"
- }
- if self.deviceTypelabel.text == "面板"{
- deviceInfo.type = "7"
- deviceInfo.lightMode = "0"
- }
- }
- if self.equipmentStyle == .equipmentEdit {
-
- if self.imagePath == nil{
- // error = .lackImage
- self.imagePath = ""
- }
- }else if self.equipmentStyle == .gatewayEdit{
- print("No problem")
- } else{
- if isPickImageFinished == false{
- // error = .lackImage
- self.imagePath = ""
- }
- }
-
- if self.equipmentStyle == .gatewayEdit {
- if self.saveInspecTime == nil {
- error = .lackInspecTime
- }else{
- deviceInfo.inspecTime = self.saveInspecTime
- }
- }
- if isSchool == "1" && self.equipmentStyle == .equipmentEdit{
- //编辑时lightId有值
- deviceInfo.lightId = self.devData?.id
- }
-
- if let delegate = self.delegate {
-
- delegate.storageDeviceInformation(deviceInfo, error: error)
- }
-
- }
-
-
- @IBAction func qrCodeAction(_ sender: Any) {
- ///点击了
- log.debug("打开二维码")
- if let delegate = self.delegate {
- delegate.scanQRCode()
- }
- }
-
- }
- //私有方法
- extension IHNewEquipmentView{
- func setupUI() {
- isPickImageFinished = false
- DeviceImage.isUserInteractionEnabled = true
- uploadImageIcon.isUserInteractionEnabled = true
- let tapImageV = UITapGestureRecognizer(target: self, action: #selector(tapDeviceImage))
- let tapImageV2 = UITapGestureRecognizer(target: self, action: #selector(tapDeviceImage))
- DeviceImage.addGestureRecognizer(tapImageV)
- uploadImageIcon.addGestureRecognizer(tapImageV2)
-
- DeviceImage.contentMode = .scaleAspectFill
- }
-
- fileprivate func isEditContent() -> Bool {
-
- var isEditDevice = false
- var isEditdeviceName = false
- let isPickImage = isPickImageFinished
- let isEditDevType = self.isEditDeviceType
- if self.deviceID.text != "" {
- isEditDevice = true
- }else{
- isEditDevice = false
- }
-
- if self.deviceNameLabel.text != "" {
- isEditdeviceName = true
- }else{
- isEditdeviceName = false
- }
- if isEditDevice == true || isEditdeviceName == true || isPickImage == true || isEditDevType == true {
- return true
- }else{
- return false
- }
-
- }
- }
- ///通知
- extension IHNewEquipmentView{
- func notifactionUnRegister() {
- NotificationCenter.default.removeObserver(self)
- }
- func notifacionRegister() {
- NotificationCenter.default.addObserver(self, selector: #selector(notifyDeviceId), name: NSNotification.Name(kNotifactionIHNewEquipmentManagerscanFinished), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(notifyDeviceIcon(_:)), name: NSNotification.Name(kIHNewEquipmentViewNotificationGetDeviceImage), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(notifyImagePath), name: NSNotification.Name(kNotifactionIHNewEquipmentViewUploadImageFinished), object: nil)
- }
- @objc func notifyDeviceId(_ notif:Notification) {
- log.debug(notif.object)
- let deviceId = notif.object as! String
- self.deviceID.text = deviceId
- }
-
- @objc func notifyDeviceIcon(_ notif:Notification) {
- let image = notif.object as! UIImage
- self.DeviceImage.image = image
- tempImage = image //切换的时候保存
-
- }
-
- @objc func notifyImagePath(_ notif:Notification) {
- let path = notif.object as! String
- isPickImageFinished = true
- self.imagePath = path
- }
- }
- ///添加手势
- extension IHNewEquipmentView{
- func addGesture() {
- let tapDeviceType = UITapGestureRecognizer(target: self, action: #selector(pickDeviceType))
- deviceTypeBox.addGestureRecognizer(tapDeviceType)
-
- let floorTap = UITapGestureRecognizer(target: self, action: #selector(tapFloorBoxAction))
- floorBox.addGestureRecognizer(floorTap)
-
- let roomTap = UITapGestureRecognizer(target: self, action: #selector(tapRoomBoxAction))
- roomBox.addGestureRecognizer(roomTap)
- //灯控型号
- let modeTap = UITapGestureRecognizer(target: self, action: #selector(tapModeAction))
- LightModeBox.addGestureRecognizer(modeTap)
- //巡检时间
- let inspectionTap = UITapGestureRecognizer(target: self, action: #selector(tapInspectionAction))
- InspectionBox.addGestureRecognizer(inspectionTap)
- //选择网关
- let gatewayIdTap = UITapGestureRecognizer(target: self, action: #selector(tapGatewayidAtion))
- gatewayBox.addGestureRecognizer(gatewayIdTap)
-
- }
-
-
- @objc func tapDeviceImage(){
- log.debug("tapDeviceImage")
- if let delegate = self.delegate {
- delegate.selectedPhoto()
- }
- }
-
- @objc func pickDeviceType(){
- var titleArr : [String] = []
- if isSchool == "1" {
- //学校
- titleArr = ["教室灯","黑板灯","面板","窗帘"]
- if self.equipmentStyle == .equipmentList || self.equipmentStyle == .equipmentEdit {
- titleArr = ["教室灯","黑板灯","面板","窗帘","网关"]
- }
- }else{
- //酒店
- //titleArr = ["lights","circadian lights","sensor","air purifiers"]
- titleArr = ["灯控","HCL灯控","感应器","空气净化器"]
- if self.equipmentStyle == .equipmentList || self.equipmentStyle == .equipmentEdit {
- titleArr = ["灯控","HCL灯控","感应器","空气净化器","网关"]
- }
- }
- let pick = THScrollChooseView(question: titleArr, withDefaultDesc: titleArr.first)
- pick?.confirmBlock = {(selectedIndex) in
- log.debug(" title = \(titleArr[selectedIndex])")
- self.deviceTypelabel.text = titleArr[selectedIndex]
- self.isEditDeviceType = true
- self.devType = "\(selectedIndex)"
- // if selectedIndex == 0 || selectedIndex == 1 {
- // self.LightModeBox.isHidden = false
- // }else{
- // self.LightModeBox.isHidden = true
- // }
- if selectedIndex == 4{
- //网关没有模式
- self.LightModeBox.isHidden = true
- }else{
- //其它设备都有模式
- self.LightModeBox.isHidden = false
- if selectedIndex == 2{
- self.lightModeLabel.text = "IH-SR01"
- }else if selectedIndex == 3{
- self.lightModeLabel.text = "IH-AP01"
- }
- }
- if self.equipmentStyle == .equipmentList || self.equipmentStyle == .equipmentEdit {
- if selectedIndex == 4 {
- self.DeviceImage.isUserInteractionEnabled = false
- //gateway_Information ic_gateway_edit
- self.DeviceImage.image = UIImage(named: "gateway_Information")
- self.uploadImageIcon.isHidden = true
- self.InspectionBox.isHidden = false
- }else{
- self.DeviceImage.isUserInteractionEnabled = true
-
- self.DeviceImage.image = self.tempImage ?? UIImage(named: "Sensor--Device Information")
- self.uploadImageIcon.isHidden = false
- self.InspectionBox.isHidden = true
- }
- }
- }
- pick?.show()
- }
-
-
- @objc func tapFloorBoxAction() {
-
- let titleArr = self.floorNames
- let pick = THScrollChooseView(question: titleArr, withDefaultDesc:self.floorStr ?? titleArr?.first)
- pick?.confirmBlock = {(selectedIndex) in
- log.debug(" title = \(titleArr?[selectedIndex] ?? "")")
- let floor = self.floorList?[selectedIndex]
-
- self.floorLabel.text = floor?.name
- self.selectedFloor = floor
- self.roomId = floor?.roomList?.first?.id //切换之后立即获取第一个房间id
- //获取房间
- self.roomNames = IHCentrlizedService.share.getRoomNameList(from: floor?.roomList)
- self.roomLabel.text = self.roomNames?.first
- if self.floorNames != nil || self.floorNames!.count > 0 {
- self.floorLabel.reset()
- }else{
- self.floorLabel.isEmpty("Please chose Floor")
- }
- //获取第一层楼的房间列表
-
-
- }
- pick?.show()
- }
-
- @objc func tapRoomBoxAction() {
- log.debug(" tapRoomBoxAction")
- let titleArr = self.roomNames
- let pick = THScrollChooseView(question: titleArr, withDefaultDesc: self.roomStr ?? titleArr?.first)
- if titleArr?.count == 0 {
- g_showHUD("这层没有添加的房间!")
- return
- }
- pick?.confirmBlock = {(selectedIndex) in
-
- // log.debug(" title = \(titleArr?[selectedIndex] ?? " ")")
- self.roomId = IHCentrlizedService.share.getRoomId(from: self.selectedFloor, roomIndex: selectedIndex)
- self.roomLabel.text = titleArr?[selectedIndex]
- }
- pick?.show()
- }
-
- @objc func tapModeAction() {
- log.debug(" tapModeAction")
- var titleArr : [String] = []
- if isSchool == "1"{
- //学校
- //设备型号(教室灯 0=>EL-DP02-1200-LY,1=>EL-DP03-1200-LY,2=>EL-WKDP03-1200-LY,黑板灯 0=>EL-HZJ01-1200-LY)
- if self.deviceTypelabel.text == "教室灯" {
- titleArr = ["EL-DP02-1200-LY","EL-DP03-1200-LY","EL-WKDP03-1200-LY"]
- } else if (self.deviceTypelabel.text == "黑板灯"){
- titleArr = ["EL-HZJ01-1200-LY"]
- }
-
- }else{
- //酒店
- if self.devType! == "0"{
- //lights
- titleArr = ["WE-L10","WE-L20","WE-CL10","WE-CL20","WE-L10-EP","WE-L20-EP","WE-CL10-EP","IH-DM1","IH-DM2","IH-DM3","IH-DE1","IH-DE2","IH-DE3"]
- }else if self.devType! == "1"{
- //hcl lights
- titleArr = ["WE-L10","WE-L20","IH-DL1 ","IH-DL2","IH-DL3","IH-DL4","IH-DL5","IH-PL1","IH-PL2","IH-PL3","IH-DM1","IH-DM2","IH-DM3","IH-DE1","IH-DE2","IH-DE3"]
- }else if self.devType! == "2"{
- //aq sensors
- titleArr = ["IH-SR01","IH-SR02","IH-SR03","IH-SR04","IH-SR05"]
- }else{
- //air purifiers
- //设备型号(0 IH-AP01,1 IH-AP02,2 IH-AP03)
- titleArr = ["IH-AP01","IH-AP02","IH-AP03"]
- }
- }
-
- let pick = THScrollChooseView(question:titleArr, withDefaultDesc: self.modeStr ?? titleArr.first)
- pick?.confirmBlock = {(selectedIndex) in
- // log.debug(" title = \(titleArr?[selectedIndex] ?? " ")")
- // self.roomId = IHCentrlizedService.share.getRoomId(from: self.selectedFloor, roomIndex: selectedIndex)
- self.lightModeLabel.text = titleArr[selectedIndex]
- self.modeStr = titleArr[selectedIndex]
- }
- pick?.show()
- }
-
- @objc func tapInspectionAction() {
- log.debug(" tapInspectionAction")
- let titleArr = ["5min","10min","30min","1hour","3hours","6hours","12hours","24hours"]
- let pick = THScrollChooseView(question:titleArr, withDefaultDesc: self.inspecTimeStr ?? titleArr.first)
- pick?.confirmBlock = {(selectedIndex) in
- // log.debug(" title = \(titleArr?[selectedIndex] ?? " ")")
- self.roomId = IHCentrlizedService.share.getRoomId(from: self.selectedFloor, roomIndex: selectedIndex)
- self.inspectionCycleLabel.text = titleArr[selectedIndex]
- switch selectedIndex {
- case 0:
- self.saveInspecTime = "5"
- case 1:
- self.saveInspecTime = "10"
- case 2:
- self.saveInspecTime = "30"
- case 3:
- self.saveInspecTime = "60"
- case 4:
- self.saveInspecTime = "180"
- case 5:
- self.saveInspecTime = "360"
- case 6:
- self.saveInspecTime = "720"
- case 7:
- self.saveInspecTime = "1440"
- default:
- break
- }
- }
- pick?.show()
- }
-
- @objc func tapGatewayidAtion(){
- //所有的网关 gatewayList equipmentList
- if isSchool == "1" && self.equipmentStyle! == .equipmentList{
- //新建设备并且是学校时
- guard let gatewayList = self.gatewayList else {
- return
- }
- var titleArr = [String]()
- for gateway in gatewayList {
- if let gatewayId = gateway.gatewayId{
- titleArr.append(gatewayId)
- }
- }
-
- let pick = THScrollChooseView(question: titleArr, withDefaultDesc: titleArr.first)
-
- pick?.confirmBlock = {(selectedIndex) in
-
- self.gatewayIdLabel.text = titleArr[selectedIndex]
-
- }
- pick?.show()
- }
- }
- }
|