123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // IHSensorManager.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/17.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- class IHSensorManager: NSObject ,IHViewManagerProtocolDelegate{
- lazy var mainView: IHSensorView = {
- let mainView = IHSensorView()
- return mainView
- }()
- // private var vc = UIViewController()
-
- private weak var vc : UIViewController?
-
- override init() {
- super.init()
- NotificationCenter.default.addObserver(self, selector: #selector(reloadNotify), name: NSNotification.Name(kNotificationIHNewEquipmentManagerEditEquipmentReload), object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- @objc func reloadNotify(_ notif:Notification){
- let sensor = self.vc as! IHSensorVCtr
- sensor.navigationBarTitle = notif.object as? String
- requestData(sensor.devId!)
- }
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- //IHSensorDeviceCell2
- NotificationCenter.default.addObserver(self, selector: #selector(changeSensorStatus), name: NSNotification.Name(KNotifiIHSensorDeviceCell2SetStatus), object: nil)
-
- let sensor = self.vc as! IHSensorVCtr
- requestData(sensor.devId!)
- createUI()
- }
- @objc private func changeSensorStatus(noti : Notification){
-
- let status = noti.userInfo?["setStatus"] as? String
- let sensor = self.vc as! IHSensorVCtr
- //开关探头3秒巡检指令
- HUD.flash(.progress, onView: nil, delay: 15) { (_) in
- HUD.flash(.label("Request timeout"), delay: 0.7)
- }
- IHSensorService.share.sensorSet_status(sensor.devId!, status: status!) { (msg, code) in
- if code != "0000"{
- DispatchQueue.main.async {
- HUD.flash(.label(msg), delay: 0.8)
- }
- self.requestData(sensor.devId!)
- }
- }
- }
-
- func requestData(_ devId:String) {
- IHSensorService.share.getSensorData(sensorId: devId, requestSuccess: { (sensordata) in
-
- self.mainView.sensorData = sensordata
-
- }) {
-
- }
- }
- func createUI() {
- // self.vc.navigationBarTitle = "Sensor-A"
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight)
- self.vc?.view.addSubview(mainView)
- setNavigationBar()
- }
-
- func setNavigationBar() {
- //导航栏的渲染方式
- let searchItem = UIBarButtonItem(image: UIImage(named: "历史数据")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
- let setItem = UIBarButtonItem(image: UIImage(named: "设置")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(modeSetAction))
- self.vc?.navigationItem.rightBarButtonItems = [searchItem,setItem]
- }
-
- @objc func modeSetAction() {
- let eqment = IHNewEquipmentVCtr()
- eqment.roomStyle = .equipmentEdit
- let aVC = self.vc as! IHSensorVCtr
- eqment.devData = aVC.dataSource
- eqment.navigationBarTitle = aVC.dataSource?.name
- self.vc?.navigationController?.pushViewController(eqment, animated: true)
-
- }
- @objc func mapAction1(){
- log.debug("点击了")
-
- HUD.show(.progress)
- HUD.hide(afterDelay: 20) { (isSuccess) in
- if isSuccess == true{
- g_showHUD("请求超时")
- }
- }
- let historyvc = IHRoomLightHistoryVCtr()
- let sensor = self.vc as! IHSensorVCtr
- historyvc.devId = sensor.devId!
- historyvc.devType = "3"
- IHSensorService.share.getSensorHistory(sensor.devId!, date_type: "0", requestSuccess: { (history) in
- HUD.hide()
- historyvc.sensorHistory = history
- self.vc?.navigationController?.pushViewController(historyvc, animated: true)
- }) {
- g_showHUD("该感应器没有历史数据")
- }
-
-
-
-
- }
- }
|