IHEquipmentView.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // IHEquipmentView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/11.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXPagingView
  10. let KNotifictionIHEquipmentViewGetHomeData = "KNotifictionIHEquipmentViewGetHomeData"
  11. struct EquipmentViewCellModel {
  12. var title:String?
  13. var icon:String?
  14. var value:String?
  15. var isAlert:Bool?
  16. }
  17. class IHEquipmentView: UIView ,UIScrollViewDelegate{
  18. var gateWayCallback:(()->Void)?//网关回调,进入网关列表
  19. fileprivate var tempDataSouce : [EquipmentViewCellModel]? = [EquipmentViewCellModel]()
  20. fileprivate var constants : [EquipmentViewCellModel]? = [EquipmentViewCellModel]()
  21. var dataSource:[String]?{
  22. didSet{
  23. relaodData()
  24. }
  25. }
  26. lazy var tableView: UITableView = {
  27. let tableView = UITableView(frame:self.bounds, style: .plain)
  28. tableView.dataSource = self
  29. tableView.delegate = self
  30. return tableView
  31. }()
  32. var listViewDidScrollCallback: ((UIScrollView) -> ())?
  33. override init(frame: CGRect) {
  34. super.init(frame: frame)
  35. addSubview(tableView)
  36. self.backgroundColor = UIColor.white
  37. self.tableView.backgroundColor = UIColor.white
  38. tableView.separatorStyle = .none
  39. tableView.register(UINib(nibName: "IHEquipmentCell", bundle: nil), forCellReuseIdentifier: "cell")
  40. initConstantsData()
  41. NotificationCenter.default.addObserver(self, selector: #selector(notifyHomeData), name: NSNotification.Name(KNotifictionIHEquipmentViewGetHomeData), object: nil)
  42. }
  43. deinit {
  44. NotificationCenter.default.removeObserver(self)
  45. }
  46. @objc func notifyHomeData(_ notify:Notification) {
  47. let data = notify.object as! HomeData
  48. self.dataSource = [data.deviceCount!,data.netCount!,data.classroomLightCount!,data.blackboardLightCount!,data.panelDeviceCount!,data.curtainDeviceCount!,data.lightCount!,data.cicLightCount!,data.sensorCount!,data.airPurCount!,data.alarmCount!]
  49. }
  50. required init?(coder: NSCoder) {
  51. fatalError("init(coder:) has not been implemented")
  52. }
  53. override func layoutSubviews() {
  54. super.layoutSubviews()
  55. // tableView.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width, height: 60 * 11)
  56. tableView.frame = self.bounds
  57. self.tableView.reloadData()
  58. }
  59. //初始化常量
  60. func initConstantsData() {
  61. let model1 = EquipmentViewCellModel(title: "设备总数", icon: "所有设备", value: "", isAlert: false)
  62. let model2 = EquipmentViewCellModel(title: "故障数", icon: "告警", value: "", isAlert: true)
  63. let model3 = EquipmentViewCellModel(title: "普通灯数", icon: "Ordinary light", value: "", isAlert: false)
  64. let model4 = EquipmentViewCellModel(title: "HCL灯控数", icon: "Circadian light", value: "", isAlert: false)
  65. let model5 = EquipmentViewCellModel(title: "感应器数", icon: "Sensor", value: "", isAlert: false)
  66. let model6 = EquipmentViewCellModel(title: "空气净化器数", icon: "空气净化器-设备默认图", value: "", isAlert: false)
  67. let model7 = EquipmentViewCellModel(title: "网关数", icon: "网关", value: "1", isAlert: false)
  68. let model8 = EquipmentViewCellModel(title: "窗帘", icon: "窗帘", value: "", isAlert: false)
  69. let model9 = EquipmentViewCellModel(title: "面板", icon: "面板", value: "", isAlert: false)
  70. let model10 = EquipmentViewCellModel(title: "黑板灯", icon: "黑板灯", value: "", isAlert: false)
  71. let model11 = EquipmentViewCellModel(title: "教室灯", icon: "灯控", value: "", isAlert: false)
  72. constants?.append(model1)
  73. constants?.append(model7)
  74. constants?.append(model11)
  75. constants?.append(model10)
  76. constants?.append(model9)
  77. constants?.append(model8)
  78. // constants?.append(model7)
  79. constants?.append(model3)
  80. constants?.append(model4)
  81. constants?.append(model5)
  82. constants?.append(model6)
  83. constants?.append(model2)
  84. // constants?.append(model1)
  85. // constants?.append(model7)
  86. // constants?.append(model3)
  87. // constants?.append(model4)
  88. // constants?.append(model5)
  89. // constants?.append(model6)
  90. //
  91. // //FIX: 2020.2.17 yalerts移动到air purifiers 下面
  92. // constants?.append(model2)
  93. }
  94. func relaodData() {
  95. tempDataSouce?.removeAll()
  96. for i in 0..<(constants?.count)! {
  97. let constant = constants![i]
  98. let value = dataSource![i]
  99. let model = EquipmentViewCellModel(title: constant.title, icon: constant.icon, value: value, isAlert: constant.isAlert)
  100. tempDataSouce?.append(model)
  101. }
  102. self.tableView.reloadData()
  103. }
  104. }
  105. extension IHEquipmentView : UITableViewDataSource,UITableViewDelegate{
  106. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  107. return tempDataSouce!.count
  108. }
  109. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  110. let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHEquipmentCell
  111. cell.model = tempDataSouce![indexPath.row]
  112. cell.selectionStyle = .none
  113. return cell
  114. }
  115. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  116. return 60
  117. }
  118. //防跳动
  119. func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
  120. return 60
  121. }
  122. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  123. self.listViewDidScrollCallback?(scrollView)
  124. }
  125. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  126. if indexPath.row == 1 {
  127. log.debug("didSelectRowAt")
  128. if let block = self.gateWayCallback {
  129. block()
  130. }
  131. }
  132. }
  133. }
  134. extension IHEquipmentView : JXPagingViewListViewDelegate{
  135. func listView() -> UIView {
  136. return self
  137. }
  138. func listScrollView() -> UIScrollView {
  139. self.tableView
  140. }
  141. func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
  142. self.listViewDidScrollCallback = callback
  143. }
  144. }