123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- //
- // IHClassLightSettingView.swift
- // Inhealth
- //
- // Created by weclouds on 2020/7/24.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- protocol ClassLightSettingViewDelegate : NSObjectProtocol{
- //设置灯
- func setClassLight(classLight : [[String : [String : String]]])
- }
- class IHClassLightSettingView: UIView {
-
- //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"]]
-
-
- // 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"]]
-
- // close_light string 全关亮度值
- // close_color string 全关色温值 Y
- // open_light string 全开亮度值 Y
- // open_color string 全开色温值 Y
- // att_class_light string 上课模式亮度值 Y
- // att_class_color string 上课模式色温值 Y
- // fin_class_light string 下课模式亮度值 Y
- // fin_class_color string 下课模式色温值 Y
- // break_light string 午休模式亮度值 Y
- // break_color string 午休模式色温值 Y
- // self_stu_light string 自习模式亮度值 Y
- // self_stu_color string 自习模式色温值 Y
- // blackboard_light string 板书模式亮度值 Y
- // blackboard_color string 板书模式色温值 Y
- // shadow_light string 投影模式亮度值 Y
- // shadow_color string 投影模式色温值
-
- 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"]
- private var tableView : UITableView?
- private var classLightDataSource = [[String : [String : String]]]()
- // var devData:DevData?
- weak var delegate : ClassLightSettingViewDelegate?
- var classLightModel : ClassLightModelData?{
- didSet{
- 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 {
- let arr1 = ["全开模式" : ["Brightness" : open_light,"Color temperature" : open_color]]
- let arr2 = ["全关模式" : ["Brightness" : close_light,"Color temperature" : close_color]]
- let arr3 = ["上课模式" : ["Brightness" : att_class_light,"Color temperature" : att_class_color]]
- let arr4 = ["下课模式" : ["Brightness" : fin_class_light,"Color temperature" : fin_class_color]]
- let arr5 = ["午休模式" : ["Brightness" : break_light,"Color temperature" : break_color]]
- let arr6 = ["自习模式" : ["Brightness" : self_stu_light,"Color temperature" : self_stu_color]]
- let arr7 = ["板书模式" : ["Brightness" : blackboard_light,"Color temperature" : blackboard_color]]
- let arr8 = ["投影模式" : ["Brightness" : shadow_light,"Color temperature" :shadow_color ]]
-
- classLightDataSource.append(arr1)
- classLightDataSource.append(arr2)
- classLightDataSource.append(arr3)
- classLightDataSource.append(arr4)
- classLightDataSource.append(arr5)
- classLightDataSource.append(arr6)
- classLightDataSource.append(arr7)
- classLightDataSource.append(arr8)
- }
-
- self.tableView?.reloadData()
- }
- }
-
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- self.createUI()
-
- NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(KNOtificationClassLightReloadData), object: nil)
-
-
- }
- @objc func reloadData(noti : NSNotification){
- let dic = noti.userInfo
- let indexPath = dic?["indexPath"] as! IndexPath
- //1 : bightness 2: color templeture
- let choseBtnTag = dic?["choseBtnTag"] as! Int
- let choseValue = dic?["choseValue"] as! String
-
- var classLightDic = classLightDataSource[indexPath.row]
- var dataDic = classLightDic.values.first!
- if choseBtnTag == 1 {
- if choseValue == "自动" {
- dataDic.updateValue("101", forKey: "Brightness")
- }else{
- dataDic.updateValue(choseValue, forKey: "Brightness")
- }
-
- }else{
- dataDic.updateValue(choseValue, forKey: "Color temperature")
- }
- classLightDic.updateValue(dataDic, forKey: classLightDic.keys.first!)
- classLightDataSource[indexPath.row] = classLightDic
-
- self.tableView?.reloadRows(at: [indexPath], with: .automatic)
- }
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func createUI() {
-
- if KNavBarHeight == 64 {
- self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 70), style: .plain)
- }else {
- self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 34 - 70), style: .plain)
- }
-
- tableView?.dataSource = self
- tableView?.delegate = self
- tableView?.separatorStyle = .none
- tableView?.rowHeight = 120.0
- //self.tableView = tableView
- self.addSubview(tableView!)
-
- let between : CGFloat = 30.0
- let saveBtn = UIButton.init(frame: CGRect.init(x: between, y: tableView!.size.height + 20.0, width: KSCREENWIDTH - between * 2, height: 40))
- saveBtn.setTitle("保存", for: .normal)
- saveBtn.backgroundColor = UIColor.init(hexString: "#573F95")
- saveBtn.addTarget(self, action: #selector(saveValueBtn), for: .touchUpInside)
- saveBtn.layer.cornerRadius = 5
- saveBtn.layer.masksToBounds = true
- self.addSubview(saveBtn)
-
- }
-
- }
- extension IHClassLightSettingView{
- @objc func saveValueBtn(sender : UIButton) {
- // HUD.flash(.label("加载中..."), delay: 8.0)
- HUD.flash(.progress, delay: 8.0)
- self.delegate?.setClassLight(classLight: self.classLightDataSource)
- }
- }
- extension IHClassLightSettingView : UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // 4 教室灯,5 黑板灯
- // if self.devData?.type == "4" {
- // return self.classLightDataSource.count
- // }else{
- // return self.blackboardDataSource.count
- // }
- return self.classLightDataSource.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = IHClassLightSettingCell.classLightWithTableView(tableView: tableView,indexPath : indexPath)
- cell.indexPath = indexPath
- cell.dataSource = self.classLightDataSource[indexPath.row]
-
- // if self.devData?.type == "4"{
- // cell.dataSource = self.classLightDataSource[indexPath.row]
- // }else{
- // // cell.dataSource = self.blackboardDataSource[indexPath.row]
- // }
-
-
- return cell
- }
-
- }
|