IHAirView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // IHAirView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/18.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. protocol IHAirViewDelegate : NSObjectProtocol{
  10. func air_switchDataType(_ index: Int,purifierId:String)
  11. func air_adjustSwitch(_ purifierId: String, status: String, level: String)
  12. func air_ctrolGear(_ purifierId: String, level: String)
  13. }
  14. class IHAirView: UIView {
  15. weak var delegate : IHAirViewDelegate?
  16. var reportData: PurifierReportData?{
  17. didSet{
  18. self.tableView.reloadData()
  19. #warning("在Air purifiers的History Score点击选择时第一次选不上")
  20. // let indexP = IndexPath(row: 0, section: 0)
  21. // self.tableView.reloadRows(at: [indexP], with: .fade)
  22. }
  23. }
  24. var airData : PurifierInfodata?{
  25. didSet{
  26. self.tableView.reloadData()
  27. }
  28. }
  29. lazy var tableView: UITableView = {
  30. let tableView = UITableView(frame: CGRect.zero, style: .plain)
  31. tableView.delegate = self
  32. tableView.dataSource = self
  33. tableView.separatorStyle = .none
  34. tableView.register(UINib(nibName: "IHAirFirstCell", bundle: nil), forCellReuseIdentifier: "firstcell")
  35. tableView.register(UINib(nibName: "IHAirAdjustCell", bundle: nil), forCellReuseIdentifier: "aircell")
  36. return tableView
  37. }()
  38. override init(frame: CGRect) {
  39. super.init(frame: frame)
  40. backgroundColor = .white
  41. addSubview(tableView)
  42. }
  43. required init?(coder: NSCoder) {
  44. fatalError("init(coder:) has not been implemented")
  45. }
  46. override func layoutSubviews() {
  47. super.layoutSubviews()
  48. tableView.frame = self.bounds
  49. }
  50. }
  51. extension IHAirView: UITableViewDelegate,UITableViewDataSource {
  52. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  53. return 2
  54. }
  55. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  56. if indexPath.row == 0 {
  57. let cell = tableView.dequeueReusableCell(withIdentifier: "firstcell") as! IHAirFirstCell
  58. cell.airData = self.airData
  59. cell.reportData = self.reportData
  60. cell.delegate = self
  61. cell.selectionStyle = .none
  62. return cell
  63. }else{
  64. let cell = tableView.dequeueReusableCell(withIdentifier: "aircell") as! IHAirAdjustCell
  65. cell.airData = self.airData
  66. cell.delegate = self
  67. cell.selectionStyle = .none
  68. return cell
  69. }
  70. }
  71. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  72. if indexPath.row == 0 {
  73. //隐藏了一个view,减70
  74. return self.airData?.alarmStatus == "1" ? 420 : 420 - 60 - 70
  75. }else{
  76. return 650
  77. }
  78. }
  79. }
  80. extension IHAirView : IHAirFirstCellDelegate,IHAirAdjustCellDelegate{
  81. func ctrolGear(_ purifierId: String, level: String) {
  82. if let delegate = self.delegate {
  83. delegate.air_ctrolGear(purifierId, level: level)
  84. }
  85. }
  86. func cellSwitchDataType(_ index: Int,purifierId:String) {
  87. if let delegate = self.delegate {
  88. delegate.air_switchDataType(index, purifierId: purifierId)
  89. }
  90. }
  91. func adjustSwitch(_ purifierId: String, status: String, level: String) {
  92. if let delegate = self.delegate {
  93. delegate.air_adjustSwitch(purifierId, status: status, level: level)
  94. }
  95. }
  96. }