IHSensorDeviceCell2.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // IHSensorDeviceCell2.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/10/30.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. let KNotifiIHSensorDeviceCell2SetStatus = "KNotifiIHSensorDeviceCell2SetStatus"
  10. class IHSensorDeviceCell2: UITableViewCell {
  11. @IBOutlet weak var leveLabel: UILabel!
  12. @IBOutlet weak var statusLabel: UILabel!
  13. @IBOutlet weak var connectStatusLabel: UILabel!
  14. @IBOutlet weak var DemoModeBtn: UIButton!
  15. override func awakeFromNib() {
  16. super.awakeFromNib()
  17. // Initialization code
  18. }
  19. var sensorData:SensorInfodata?{
  20. didSet{
  21. if let sensorData = self.sensorData {
  22. if let batteryLevel = sensorData.batteryLevel ,
  23. let batteryStatus = sensorData.batteryStatus,
  24. let online = sensorData.online,
  25. let wifiLevel = sensorData.wifiLevel{
  26. if batteryLevel == "" || batteryStatus == "" || online == "" || wifiLevel == ""{
  27. g_showHUD("No data")
  28. return
  29. }
  30. //NA不支持的意思
  31. self.leveLabel.text = "NA"
  32. if online == "0" {
  33. connectStatusLabel.text = "Off-line"
  34. }else if online == "1"{
  35. connectStatusLabel.text = "On-line"
  36. }
  37. statusLabel.text = "NA"
  38. //开关探头3秒巡检指令 status
  39. if sensorData.status == "0"{
  40. //关
  41. DemoModeBtn.isSelected = false
  42. DemoModeBtn.setImage(UIImage.init(named: "offSwitch"), for: .normal)
  43. }else{
  44. //开
  45. DemoModeBtn.isSelected = true
  46. DemoModeBtn.setImage(UIImage.init(named: "onSwitch_gray"), for: .normal)
  47. }
  48. }
  49. }
  50. }
  51. }
  52. deinit {
  53. NotificationCenter.default.removeObserver(self)
  54. }
  55. @IBAction func setStatusActionBtn(_ sender: UIButton) {
  56. sender.isSelected = !sender.isSelected
  57. var status = "0"
  58. if sensorData?.status == "0"{
  59. //打开
  60. status = "1"
  61. }else{
  62. //关闭
  63. status = "0"
  64. }
  65. NotificationCenter.default.post(name: NSNotification.Name(KNotifiIHSensorDeviceCell2SetStatus), object: nil, userInfo: ["setStatus" : status])
  66. }
  67. }