IHClassLightingSettingManager.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // IHClassLightingSettingManager.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. class IHClassLightingSettingManager: NSObject {
  11. lazy var mainView: IHClassLightSettingView = {
  12. let mainView = IHClassLightSettingView.init(frame: self.vc!.view.bounds )
  13. mainView.delegate = self
  14. return mainView
  15. }()
  16. private weak var vc : UIViewController?
  17. func bindController(_ vc: UIViewController){
  18. self.vc = vc
  19. self.vc?.view.addSubview(mainView)
  20. let classLightVC = vc as! IHClassLightSettingCtr
  21. // mainView.devData = classLightVC.devData
  22. //获取教室灯
  23. getClassLightModel(id: (classLightVC.devData?.id)!)
  24. }
  25. }
  26. extension IHClassLightingSettingManager{
  27. fileprivate func getClassLightModel(id : String){
  28. // HUD.flash(.label("加载中..."), delay: 8.0)
  29. HUD.flash(.progress, delay: 8.0)
  30. IHClassLightService.share.getSchoolLightModel(id: id) { (classLight_info) in
  31. //获取数据 : ClassLight_info
  32. guard let classLightInfo = classLight_info else{return}
  33. HUD.flash(.label(classLightInfo.msg), delay: 1)
  34. if classLightInfo.code == "0000"{
  35. self.mainView.classLightModel = classLightInfo.result
  36. }
  37. }
  38. }
  39. }
  40. extension IHClassLightingSettingManager : ClassLightSettingViewDelegate{
  41. //设备灯
  42. func setClassLight(classLight: [[String : [String : String]]]) {
  43. var lightDataModel = ClassLightModelData.init()
  44. for i in 0..<classLight.count {
  45. let dic = classLight[i]
  46. let valueDic = dic.values.first!
  47. if dic.keys.first! == "全开模式" {
  48. lightDataModel.open_light = valueDic["Brightness"]!
  49. lightDataModel.open_color = valueDic["Color temperature"]!
  50. }
  51. if dic.keys.first! == "全关模式" {
  52. lightDataModel.close_light = valueDic["Brightness"]!
  53. lightDataModel.close_color = valueDic["Color temperature"]!
  54. }
  55. if dic.keys.first! == "上课模式" {
  56. lightDataModel.att_class_light = valueDic["Brightness"]!
  57. lightDataModel.att_class_color = valueDic["Color temperature"]!
  58. }
  59. if dic.keys.first! == "下课模式" {
  60. lightDataModel.fin_class_light = valueDic["Brightness"]!
  61. lightDataModel.fin_class_color = valueDic["Color temperature"]!
  62. }
  63. if dic.keys.first! == "午休模式" {
  64. lightDataModel.break_light = valueDic["Brightness"]!
  65. lightDataModel.break_color = valueDic["Color temperature"]!
  66. }
  67. if dic.keys.first! == "自习模式" {
  68. lightDataModel.self_stu_light = valueDic["Brightness"]!
  69. lightDataModel.self_stu_color = valueDic["Color temperature"]!
  70. }
  71. if dic.keys.first! == "板书模式" {
  72. lightDataModel.blackboard_light = valueDic["Brightness"]!
  73. lightDataModel.blackboard_color = valueDic["Color temperature"]!
  74. }
  75. if dic.keys.first! == "投影模式" {
  76. lightDataModel.shadow_light = valueDic["Brightness"]!
  77. lightDataModel.shadow_color = valueDic["Color temperature"]!
  78. }
  79. }
  80. let classLightVC = vc as! IHClassLightSettingCtr
  81. IHClassLightService.share.setSchoolLightModel(id: (classLightVC.devData?.id)!, close_light: lightDataModel.close_light, close_color: lightDataModel.close_color, open_light: lightDataModel.open_light, open_color: lightDataModel.open_color, att_class_light: lightDataModel.att_class_light, att_class_color: lightDataModel.att_class_color, fin_class_light: lightDataModel.fin_class_light, fin_class_color: lightDataModel.fin_class_color, break_light: lightDataModel.break_light, break_color: lightDataModel.break_color, self_stu_light: lightDataModel.self_stu_light, self_stu_color: lightDataModel.self_stu_color, blackboard_light: lightDataModel.blackboard_light, blackboard_color: lightDataModel.blackboard_color, shadow_light: lightDataModel.shadow_light, shadow_color: lightDataModel.shadow_color, compelete:{ (respone, code) in
  82. HUD.flash(.label(respone), delay: 1.0)
  83. })
  84. }
  85. }