123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // IHClassRoomManager.swift
- // Inhealth
- //
- // Created by weclouds on 2020/6/12.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- //亮度
- let kNotifactionClassLightUpdateBright = "kNotifactionClassLightUpdateBright"
- //色温
- let kNotifactionClassLightUpdateTempColor = "kNotifactionClassLightUpdateTempColor"
- //开关
- let kNotifactionClassLightUpdateSwitch = "kNotifactionClassLightUpdateSwitch"
- class IHClassRoomManager: NSObject {
- lazy var mainView: IHClassRoomView = {
- let mainView = IHClassRoomView.init(frame: self.vc!.view.bounds )
- mainView.delegate = self
-
- return mainView
- }()
-
- // private var vc = UIViewController()
- private weak var vc : UIViewController?
-
- func bindController(_ vc: UIViewController){
- self.vc = vc
- self.vc?.view.addSubview(mainView)
- let classRoomVC = vc as! IHClassRoomCtr
-
- // createUI()
- //
- // let arealistVC = vc as! IHAreaListVCtr
- // mainView.roomList = arealistVC.roomList
- //亮度
- NotificationCenter.default.addObserver(self, selector: #selector(notiUpdateLightBright), name: Notification.Name(kNotifactionClassLightUpdateBright), object: nil)
- //色温
- NotificationCenter.default.addObserver(self, selector: #selector(notiUpdateTempColor), name: Notification.Name(kNotifactionClassLightUpdateTempColor), object: nil)
- //开关
- NotificationCenter.default.addObserver(self, selector: #selector(notiUpdateSwitch), name: Notification.Name(kNotifactionClassLightUpdateSwitch), object: nil)
-
- getDeviceList(roomId: classRoomVC.roomId)
- }
-
- func createUI() {
- //按8的尺寸
- // mainView.frame = self.vc.view.bounds
- // //设置图片
- // let backImageView = UIImageView.init(frame: mainView.frame)
- // backImageView.image = UIImage.init(named: "关灯背景图")
- // mainView.addSubview(backImageView)
- // self.vc.view.addSubview(mainView)
-
-
- }
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- }
- extension IHClassRoomManager : IHClassRoomViewDelegate{
- //调灯的色温
- // func clickLight(_index: Int) {
- // //IHLampControlVCtr
- // let vc = IHLampControlVCtr()
- // var d = DevData.init()
- //// 2033
- // d.id = "2033"
- // vc.dataSource = d
- // vc.isClassRoom = true
- // self.vc.navigationController?.pushViewController(vc, animated: true)
- // }
-
- //调单个灯的色温与亮度
- func clickLight(lightDevice: ShoolDeviceList) {
- let vc = IHLampControlVCtr()
- vc.shoolDevice = lightDevice
- var dev = DevData.init()
- dev.id = lightDevice.id
- vc.dataSource = dev
- vc.isClassRoom = true
- self.vc?.navigationController?.pushViewController(vc, animated: true)
- }
-
- //更换灯的位置
- func chargeLight(lists: [ShoolDeviceList]) {
- changeLightLocation(lights :lists )
- }
-
- //窗帘的开关
- func curtainSetOnOff(curtainDevice: ShoolDeviceList,respone:@escaping ((_ msg : String)->Void)) {
-
- changeCurtainState(curtainDevice: curtainDevice, respone: respone)
- }
- }
- //网络请求
- extension IHClassRoomManager {
- //所有设备
- func getDeviceList(roomId : String) {
- IHClassRoomService.share.getDeviceList(roomId: roomId, requstSuccess: { (shoolDivListArr) in
- log.debug("-网络请求-教室设备\(shoolDivListArr)")
- //return shoolDivListArr
- self.mainView.shoolDivListArr = shoolDivListArr
-
- }) {
- HUD.flash(.error, delay: 1.5)
- }
- }
-
- //更换设备位置
- func changeLightLocation(lights : [ShoolDeviceList]) {
-
- var locations = [[String:String]]()
- for light in lights {
- let dic = ["id":light.id!,"location":light.location!]
- locations.append(dic)
- }
-
-
- IHClassRoomService.share.saveLight(infoList: locations, requstSuccess: { (msg) in
- log.debug("----\(msg)")
- if(msg == "0000"){
- HUD.flash(.success, delay: 1)
- }
- }) {
- HUD.flash(.error, delay: 1.5)
- }
- }
-
- //窗帘的开关
- func changeCurtainState(curtainDevice : ShoolDeviceList,respone:@escaping (_ msg : String)->()) {
- guard let id = curtainDevice.id else {
- return
- }
- guard var status = curtainDevice.status else {
- return
- }
- if status == "1" {
- status = "0"
- }else{
- status = "1"
- }
- IHClassRoomService.share.curtainOnOff(id: id, status: status, requstSuccess: { (msg,code) in
- log.debug("窗帘的开关")
- //respone(msg)
- // HUD.flash(.label(msg), delay: 1.5)
- if(code == "0000"){
- //如果成功的话,改变现在的状态
- let classRoomVC = self.vc as! IHClassRoomCtr
- self.getDeviceList(roomId: classRoomVC.roomId)
-
- }else{
- //如果没有成功的话,就恢复到没有的样子
- self.mainView.shoolDivListArr = self.mainView.shoolDivListArr
- }
-
- }) {
- HUD.flash(.error, delay: 1.5)
- }
- }
-
-
- //灯的全开与全关 模式类型(1 全开模式,2 全关模式,3 投影模式,4 自习模式,5 板书模式,7 上课模式,8 下课模式,9 午休模式)
- func lights_set_off(type: String) {
- let classRoomVC = vc as! IHClassRoomCtr
- IHClassRoomService.share.setLights_on_off(roomId: classRoomVC.roomId, type: type, success: { (msg,code) in
- log.debug("----")
- if(code == "0000"){
- //如果成功的话,改变现在的状态
- let classRoomVC = self.vc as! IHClassRoomCtr
- self.mainView.isSuccess = true
- self.getDeviceList(roomId: classRoomVC.roomId)
-
- }else{
- //如果没有成功的话,就恢复到没有的样子
- //self.mainView.shoolDivListArr = self.mainView.shoolDivListArr
- self.mainView.isSuccess = false
- }
- }) {
- HUD.flash(.error, delay: 1.5)
- }
-
- //IHClassRoomService.share.setLights_on_off(roomId: classRoomVC.roomId, type: type,requestFail:@escaping (()->Void),success:@escaping (_ msg : String)->())
- }
-
- func setClassLightColor(classDevices: [ShoolDeviceList]) {
- IHClassRoomService.share.lightsColor(classDevices: classDevices)
-
- }
- }
- //通知的方法
- extension IHClassRoomManager{
- //亮度
- @objc func notiUpdateLightBright(infor : Notification) {
- log.debug("-通知的方法--")
- let classRoomVC = self.vc as! IHClassRoomCtr
- self.getDeviceList(roomId: classRoomVC.roomId)
- }
- //色温
- @objc func notiUpdateTempColor(infor : Notification) {
- log.debug("-通知的方法--")
- let classRoomVC = self.vc as! IHClassRoomCtr
- self.getDeviceList(roomId: classRoomVC.roomId)
- }
- //开关
- @objc func notiUpdateSwitch(infor : Notification) {
- log.debug("-通知的方法--")
- let classRoomVC = self.vc as! IHClassRoomCtr
- self.getDeviceList(roomId: classRoomVC.roomId)
- }
-
-
- }
|