IHClassLightSettingView.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // IHClassLightSettingView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/7/24.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import PKHUD
  10. protocol ClassLightSettingViewDelegate : NSObjectProtocol{
  11. //设置灯
  12. func setClassLight(classLight : [[String : [String : String]]])
  13. }
  14. class IHClassLightSettingView: UIView {
  15. //var classLightDataSource = [["Full-on mode" : "100"],["Full-off mode" : "0"],["Attend class mode" : "100"],["Finish class mode" : "30"], ["Noon break mode" : "0"],["Self-study mode" : "100"],["Blackboard mode" : "100"],["Projection mode" : "50"]]
  16. // var blackboardDataSource = [["Full-on mode" : "100"],["Full-off mode" : "0"],["Attend class mode" : "100"],["Finish class mode" : "0"], ["Noon break mode" : "0"],["Self-study mode" : "0"],["Blackboard mode" : "100"],["Projection mode" : "0"]]
  17. // close_light string 全关亮度值
  18. // close_color string 全关色温值 Y
  19. // open_light string 全开亮度值 Y
  20. // open_color string 全开色温值 Y
  21. // att_class_light string 上课模式亮度值 Y
  22. // att_class_color string 上课模式色温值 Y
  23. // fin_class_light string 下课模式亮度值 Y
  24. // fin_class_color string 下课模式色温值 Y
  25. // break_light string 午休模式亮度值 Y
  26. // break_color string 午休模式色温值 Y
  27. // self_stu_light string 自习模式亮度值 Y
  28. // self_stu_color string 自习模式色温值 Y
  29. // blackboard_light string 板书模式亮度值 Y
  30. // blackboard_color string 板书模式色温值 Y
  31. // shadow_light string 投影模式亮度值 Y
  32. // shadow_color string 投影模式色温值
  33. private var source = ["Full-on mode","Full-off mode" ,"Attend class mode" ,"Finish class mode" , "Noon break mode","Self-study mode" ,"Blackboard mode" ,"Projection mode"]
  34. private var tableView : UITableView?
  35. private var classLightDataSource = [[String : [String : String]]]()
  36. // var devData:DevData?
  37. weak var delegate : ClassLightSettingViewDelegate?
  38. var classLightModel : ClassLightModelData?{
  39. didSet{
  40. if let open_light = classLightModel?.open_light,let open_color = classLightModel?.open_color,let close_light = classLightModel?.close_light,let close_color = classLightModel?.close_color,let att_class_light = classLightModel?.att_class_light,let att_class_color = classLightModel?.att_class_color,let fin_class_light = classLightModel?.fin_class_light,let fin_class_color = classLightModel?.fin_class_color,let break_light = classLightModel?.break_light,let break_color = classLightModel?.break_color, let self_stu_light = classLightModel?.self_stu_light,let self_stu_color = classLightModel?.self_stu_color,let blackboard_light = classLightModel?.blackboard_light,let blackboard_color = classLightModel?.blackboard_color,let shadow_light = classLightModel?.shadow_light, let shadow_color = classLightModel?.shadow_color {
  41. let arr1 = ["全开模式" : ["Brightness" : open_light,"Color temperature" : open_color]]
  42. let arr2 = ["全关模式" : ["Brightness" : close_light,"Color temperature" : close_color]]
  43. let arr3 = ["上课模式" : ["Brightness" : att_class_light,"Color temperature" : att_class_color]]
  44. let arr4 = ["下课模式" : ["Brightness" : fin_class_light,"Color temperature" : fin_class_color]]
  45. let arr5 = ["午休模式" : ["Brightness" : break_light,"Color temperature" : break_color]]
  46. let arr6 = ["自习模式" : ["Brightness" : self_stu_light,"Color temperature" : self_stu_color]]
  47. let arr7 = ["板书模式" : ["Brightness" : blackboard_light,"Color temperature" : blackboard_color]]
  48. let arr8 = ["投影模式" : ["Brightness" : shadow_light,"Color temperature" :shadow_color ]]
  49. classLightDataSource.append(arr1)
  50. classLightDataSource.append(arr2)
  51. classLightDataSource.append(arr3)
  52. classLightDataSource.append(arr4)
  53. classLightDataSource.append(arr5)
  54. classLightDataSource.append(arr6)
  55. classLightDataSource.append(arr7)
  56. classLightDataSource.append(arr8)
  57. }
  58. self.tableView?.reloadData()
  59. }
  60. }
  61. override init(frame: CGRect) {
  62. super.init(frame: frame)
  63. self.createUI()
  64. NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(KNOtificationClassLightReloadData), object: nil)
  65. }
  66. @objc func reloadData(noti : NSNotification){
  67. let dic = noti.userInfo
  68. let indexPath = dic?["indexPath"] as! IndexPath
  69. //1 : bightness 2: color templeture
  70. let choseBtnTag = dic?["choseBtnTag"] as! Int
  71. let choseValue = dic?["choseValue"] as! String
  72. var classLightDic = classLightDataSource[indexPath.row]
  73. var dataDic = classLightDic.values.first!
  74. if choseBtnTag == 1 {
  75. if choseValue == "自动" {
  76. dataDic.updateValue("101", forKey: "Brightness")
  77. }else{
  78. dataDic.updateValue(choseValue, forKey: "Brightness")
  79. }
  80. }else{
  81. dataDic.updateValue(choseValue, forKey: "Color temperature")
  82. }
  83. classLightDic.updateValue(dataDic, forKey: classLightDic.keys.first!)
  84. classLightDataSource[indexPath.row] = classLightDic
  85. self.tableView?.reloadRows(at: [indexPath], with: .automatic)
  86. }
  87. deinit {
  88. NotificationCenter.default.removeObserver(self)
  89. }
  90. required init?(coder: NSCoder) {
  91. fatalError("init(coder:) has not been implemented")
  92. }
  93. func createUI() {
  94. if KNavBarHeight == 64 {
  95. self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 70), style: .plain)
  96. }else {
  97. self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 34 - 70), style: .plain)
  98. }
  99. tableView?.dataSource = self
  100. tableView?.delegate = self
  101. tableView?.separatorStyle = .none
  102. tableView?.rowHeight = 120.0
  103. //self.tableView = tableView
  104. self.addSubview(tableView!)
  105. let between : CGFloat = 30.0
  106. let saveBtn = UIButton.init(frame: CGRect.init(x: between, y: tableView!.size.height + 20.0, width: KSCREENWIDTH - between * 2, height: 40))
  107. saveBtn.setTitle("保存", for: .normal)
  108. saveBtn.backgroundColor = UIColor.init(hexString: "#573F95")
  109. saveBtn.addTarget(self, action: #selector(saveValueBtn), for: .touchUpInside)
  110. saveBtn.layer.cornerRadius = 5
  111. saveBtn.layer.masksToBounds = true
  112. self.addSubview(saveBtn)
  113. }
  114. }
  115. extension IHClassLightSettingView{
  116. @objc func saveValueBtn(sender : UIButton) {
  117. // HUD.flash(.label("加载中..."), delay: 8.0)
  118. HUD.flash(.progress, delay: 8.0)
  119. self.delegate?.setClassLight(classLight: self.classLightDataSource)
  120. }
  121. }
  122. extension IHClassLightSettingView : UITableViewDelegate,UITableViewDataSource{
  123. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  124. // 4 教室灯,5 黑板灯
  125. // if self.devData?.type == "4" {
  126. // return self.classLightDataSource.count
  127. // }else{
  128. // return self.blackboardDataSource.count
  129. // }
  130. return self.classLightDataSource.count
  131. }
  132. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  133. let cell = IHClassLightSettingCell.classLightWithTableView(tableView: tableView,indexPath : indexPath)
  134. cell.indexPath = indexPath
  135. cell.dataSource = self.classLightDataSource[indexPath.row]
  136. // if self.devData?.type == "4"{
  137. // cell.dataSource = self.classLightDataSource[indexPath.row]
  138. // }else{
  139. // // cell.dataSource = self.blackboardDataSource[indexPath.row]
  140. // }
  141. return cell
  142. }
  143. }