123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // IHDashboardManager.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/10.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- let kNotificationIHDashboardManagerNotifyHotleInfo = "kNotificationIHDashboardManagerNotifyHotleInfo"
- class IHDashboardManager: NSObject ,IHViewManagerProtocolDelegate{
- // private var vc = UIViewController()
-
- private weak var vc : UIViewController?
- override init() {
- super.init()
- NotificationCenter.default.addObserver(self, selector: #selector(notifyHotleInfo(_:)), name: NSNotification.Name(kNotificationIHDashboardManagerNotifyHotleInfo), object: nil)
-
- NotificationCenter.default.addObserver(self, selector: #selector(reloadAddressNotify), name: NSNotification.Name(kNotificationIHAddressControllerReloadAddress), object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- @objc func notifyHotleInfo(_ notif:Notification) {
- let annotion = notif.object as! IHAnotation
- self.vc?.navigationBarTitle = annotion.name
- Intermediate.share.selectedCoordinate = annotion.coordinate
-
- }
- //通知修改酒店
- @objc func reloadAddressNotify() {
- self.vc?.navigationBarTitle = Intermediate.hotelName
- self.requestData(Intermediate.hotelId)
- }
-
-
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
-
- let info = IHHotelStorage.shareInstance.getHotelStore()
- //如果沙盒中没有存有 则 重新请求
- if info != nil {
- self.vc?.navigationBarTitle = Intermediate.hotelName
- self.requestData(Intermediate.hotelId)
- }else{ //沙盒中存有
- IHAddressService.share.getFirstHotel { (hotelId, hotelName) in
- if let hotelId = hotelId{
- IHHomeService.share.getAlarmCountBadgeNumber(hotelId) { (badgeNumber) in
- let item = self.vc?.navigationController?.tabBarController?.tabBar.items![3]
- if badgeNumber != "0"{
- item?.badgeValue = badgeNumber
- }else{
- item?.badgeValue = nil
- }
-
- }
- Intermediate.hotelId = hotelId
- self.vc?.navigationBarTitle = hotelName
- Intermediate.hotelName = hotelName!
- self.requestData(hotelId)
- }
- }
-
- }
- //请求网关列表
- self.mainView.gatwayListCallBack = { [unowned self] in
- // let gatewayVC = IHGatewayListVCtr()
- // self.vc.navigationController?.pushViewController(gatewayVC, animated: true)
-
- self.vc?.tabBarController?.selectedIndex = 2
- AppShare.tabbarSelected = true
- log.debug("self.mainView.gatwayListCallBack")
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentlistViewNotifySelectGateway), object: nil)
-
- }
- }
-
- func requestData(_ hotelId:String) {
- g_showProgress()
-
- let group = DispatchGroup()
- let queue1 = DispatchQueue(label: "getHotelWeather")
- queue1.async {
- //获取酒店天气
- IHHomeService.share.getHotelWeather(hotelId, requestSuccess: { (cond_code, cond_txt,averageAir,level) in
- self.mainView.cond_code = cond_code
- // self.mainView.cond_txt = cond_txt
- // self.mainView.averageAir = averageAir
- // self.mainView.level = level
- switch cond_txt{
- case "Rain" :
- self.mainView.cond_txt = "雨天"
- case "Cloudy" :
- self.mainView.cond_txt = "多云"
- case "Overcast":
- self.mainView.cond_txt = "阴天"
- case "Sunny/Clear":
- self.mainView.cond_txt = "晴天"
- default :
- self.mainView.cond_txt = cond_txt
- }
-
- if averageAir == "no data"{
- self.mainView.averageAir = "无数据"
- }else{
- self.mainView.averageAir = averageAir
- }
- switch level{
- case "Good":
- self.mainView.level = "好"
- case "Very good":
- self.mainView.level = "非常好"
- case "Unknown":
- self.mainView.level = "未知"
- default:
- self.mainView.level = level
- }
-
- }) {
-
- }
- }
-
- let queue2 = DispatchQueue(label: "getHotelviewData")
- queue2.async {
- //获取首页概览数据
- IHHomeService.share.getHomeData(hotelId: hotelId, requestSuccess: { (homeData) in
- NotificationCenter.default.post(name: NSNotification.Name(KNotifictionIHEquipmentViewGetHomeData), object: homeData)
- }) {
-
- }
- }
-
- let queue3 = DispatchQueue(label: "getHotelviewData")
- queue3.async {
- //获取酒店数据
- IHHomeService.share.getHotelviewData(hotelId: hotelId, requestSuccess: { (hotels) in
-
- Intermediate.share.hotels = hotels
-
- }) {
-
- }
- }
-
- //首页空气质量跟传感器
- let queue4 = DispatchQueue(label: "getRoomEnvStatus")
- queue4.async {
- IHHomeService.share.getRoomEnvStatus(hotelId) { (result) in
- self.mainView.envorentmentInfo = result
- NotificationCenter.default.post(name: NSNotification.Name(kNotificationIHAirQualityViewReloadAirData), object: result)
- }
- }
- group.notify(queue: DispatchQueue.main) {
- g_showSuccess()
- }
- }
-
- lazy var mainView: IHDashboardMainView = {
- let mainView = IHDashboardMainView()
- mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - KTabbarHeight)
- mainView.backgroundColor = .red
- return mainView
- }()
-
- func createUI() {
-
- setNavigationBar()
- self.vc?.view.addSubview(mainView)
- mainView.headerViewCallback = {
- log.debug("个人中心")
- let personalVC = IHPersonalCenterVCtr()
- self.vc?.navigationController?.pushViewController(personalVC, animated: true)
- }
- }
-
- func setNavigationBar() {
- //导航栏的渲染方式
- self.vc?.navigationBarTitle = " "
- let rightItem = UIBarButtonItem(image: UIImage(named: "map")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction))
- let leftItem = UIBarButtonItem(image: UIImage(named: "定位")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
- self.vc?.navigationItem.rightBarButtonItem = rightItem
- self.vc?.navigationItem.leftBarButtonItem = leftItem
-
- }
-
-
-
-
- func ih_viewDidLayoutSubviews() {
- mainView.d_viewDidLauyouSubView()
- }
-
- @objc func mapAction1(){
- log.debug("点击了")
- let picker = IHHotelPickerVCtr.shareInstance //全局使用,只初始化一次
- self.vc?.navigationController?.pushViewController(picker, animated: true)
- }
- @objc func mapAction(){
- log.debug("点击了")
- let map = IHDashboardMapMainVCtr()
-
- self.vc?.navigationController?.pushViewController(map, animated: true)
- }
- }
- extension IHDashboardManager:IHAddressControllerDelegate {
- func selectedAddress(address: String, addressID: String) {
- self.vc?.navigationBarTitle = address
- Intermediate.hotelId = addressID
- Intermediate.hotelName = address
- self.requestData(addressID)
- }
-
- }
|