123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- //
- // IHIHRoomListCell.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/14.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- //import TKSwitcherCollection
- protocol IHRoomListCellDelegate : NSObjectProtocol {
-
-
- func oprationSwitch(_ id: String, devType:String,status:String,currentIndex:IndexPath)
- }
- class IHIHRoomListCell: UICollectionViewCell {
-
- weak var delegate : IHRoomListCellDelegate?
- var currentIndexPath :IndexPath?
-
- var model:DevData?{
- didSet{
- if let model = self.model {
- if let devId = model.id,
- let status = model.status,
- let alarmStatus = model.alarmStatus ,
- let name = model.name,
- let devType = model.devType,
- let level = model.level,
- let light = model.light,
- let color = model.color,
- let online = model.online
- {
- self.devId = devId
- self.devType = devType
- self.devNameLabel.text = name
- if alarmStatus == "1" { //故障有
-
- self.bgView.image = UIImage(named: "故障状态")
- // self.switchBtn.setImage(UIImage(named: "offSwitch"), for: .normal)
-
- self.switchBtn.isSelected = true
- self.switchBtn.setBackgroundImage(UIImage(named: "启用状态-1"), for: .normal)
- }else if alarmStatus == "0"{ //故障无
-
-
- if status == "1" { //开
- setOnlineStatus()
- self.bgView.image = UIImage(named: "启用状态")
- }else if status == "0"{//关
- setOfflineStaus()
- self.bgView.image = UIImage(named: "关闭状态")
- }
- }
-
- if devType == "1"{
- self.devTypeLabel.text = "灯控"
-
- self.switchBtn.isHidden = false
- self.lightnessLabel.text = light + "%"
- }else if devType == "2"{
- self.devTypeLabel.text = "HCL灯控"
- self.switchBtn.isHidden = false
- self.lightnessLabel.text = light + "%"
- }else if devType == "3"{
- self.devTypeLabel.text = "感应器"
- self.switchBtn.isHidden = true
-
- if online == "0"{
- self.lightnessLabel.text = "离线"
- }else if online == "1"{
- self.lightnessLabel.text = "在线"
- }
-
- }else if devType == "4"{
- self.devTypeLabel.text = "空气净化器"
- self.switchBtn.isHidden = false
- var airLevel = ""
- if level == "1" {
- airLevel = "低档"
- }else if level == "2"{
- airLevel = "中档"
- }else if level == "3"{
- airLevel = "高档"
- }
- self.lightnessLabel.text = airLevel
- }
- }
- }
- }
- }
- private var devId :String?
- private var devType:String? = "1"
- @IBOutlet weak var bgView: UIImageView!
-
- @IBOutlet weak var repairIcon: UIImageView!
-
-
- @IBOutlet weak var devNameLabel: UILabel!
-
- @IBOutlet weak var devTypeLabel: UILabel!
-
- @IBOutlet weak var lightnessLabel: UILabel!
-
- // @IBOutlet weak var exchangeSwitch: TKExchangeSwitch!
-
-
- @IBOutlet weak var switchBtn: UIButton!
-
- override func awakeFromNib() {
- super.awakeFromNib()
- self.switchBtn.setBackgroundImage(UIImage(named: "onSwitch"), for: .selected)
- self.switchBtn.setBackgroundImage(UIImage(named: "offSwitch"), for: .normal)
- switchBtn.addTarget(self, action: #selector(switchAction(sender:)), for: .touchUpInside)
-
- }
-
-
-
- func setOnlineStatus() {
- self.switchBtn.isSelected = true
- self.switchBtn.setBackgroundImage(UIImage(named: "onSwitch"), for: .selected)
- self.devNameLabel.textColor = UIColor(hexString: "#FFFFFF")
- self.devTypeLabel.textColor = UIColor(hexString: "#FFFFFF")
- self.lightnessLabel.textColor = UIColor(hexString: "#FFFFFF")
- }
- func setOfflineStaus() {
- self.switchBtn.setBackgroundImage(UIImage(named: "offSwitch"), for: .normal)
- self.switchBtn.isSelected = false
- self.devNameLabel.textColor = UIColor(hexString: "#333333")
- self.devTypeLabel.textColor = UIColor(hexString: "#333333")
- self.lightnessLabel.textColor = UIColor(hexString: "#333333")
-
- }
- @objc func switchAction(sender:UIButton) {
- sender.isSelected = !sender.isSelected
- let status = sender.isSelected == true ? "1" : "0"
- if let delegate = self.delegate {
- delegate.oprationSwitch(self.devId!, devType: self.devType!, status: status, currentIndex: self.currentIndexPath!)
- }
- }
- }
|