IHDashboardManager.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // IHDashboardManager.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/10.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. let kNotificationIHDashboardManagerNotifyHotleInfo = "kNotificationIHDashboardManagerNotifyHotleInfo"
  10. class IHDashboardManager: NSObject ,IHViewManagerProtocolDelegate{
  11. // private var vc = UIViewController()
  12. private weak var vc : UIViewController?
  13. override init() {
  14. super.init()
  15. NotificationCenter.default.addObserver(self, selector: #selector(notifyHotleInfo(_:)), name: NSNotification.Name(kNotificationIHDashboardManagerNotifyHotleInfo), object: nil)
  16. NotificationCenter.default.addObserver(self, selector: #selector(reloadAddressNotify), name: NSNotification.Name(kNotificationIHAddressControllerReloadAddress), object: nil)
  17. }
  18. deinit {
  19. NotificationCenter.default.removeObserver(self)
  20. }
  21. @objc func notifyHotleInfo(_ notif:Notification) {
  22. let annotion = notif.object as! IHAnotation
  23. self.vc?.navigationBarTitle = annotion.name
  24. Intermediate.share.selectedCoordinate = annotion.coordinate
  25. }
  26. //通知修改酒店
  27. @objc func reloadAddressNotify() {
  28. self.vc?.navigationBarTitle = Intermediate.hotelName
  29. self.requestData(Intermediate.hotelId)
  30. }
  31. func bindController(_ vc: UIViewController) {
  32. self.vc = vc
  33. createUI()
  34. let info = IHHotelStorage.shareInstance.getHotelStore()
  35. //如果沙盒中没有存有 则 重新请求
  36. if info != nil {
  37. self.vc?.navigationBarTitle = Intermediate.hotelName
  38. self.requestData(Intermediate.hotelId)
  39. }else{ //沙盒中存有
  40. IHAddressService.share.getFirstHotel { (hotelId, hotelName) in
  41. if let hotelId = hotelId{
  42. IHHomeService.share.getAlarmCountBadgeNumber(hotelId) { (badgeNumber) in
  43. let item = self.vc?.navigationController?.tabBarController?.tabBar.items![3]
  44. if badgeNumber != "0"{
  45. item?.badgeValue = badgeNumber
  46. }else{
  47. item?.badgeValue = nil
  48. }
  49. }
  50. Intermediate.hotelId = hotelId
  51. self.vc?.navigationBarTitle = hotelName
  52. Intermediate.hotelName = hotelName!
  53. self.requestData(hotelId)
  54. }
  55. }
  56. }
  57. //请求网关列表
  58. self.mainView.gatwayListCallBack = { [unowned self] in
  59. // let gatewayVC = IHGatewayListVCtr()
  60. // self.vc.navigationController?.pushViewController(gatewayVC, animated: true)
  61. self.vc?.tabBarController?.selectedIndex = 2
  62. AppShare.tabbarSelected = true
  63. log.debug("self.mainView.gatwayListCallBack")
  64. NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHEquipmentlistViewNotifySelectGateway), object: nil)
  65. }
  66. }
  67. func requestData(_ hotelId:String) {
  68. g_showProgress()
  69. let group = DispatchGroup()
  70. let queue1 = DispatchQueue(label: "getHotelWeather")
  71. queue1.async {
  72. //获取酒店天气
  73. IHHomeService.share.getHotelWeather(hotelId, requestSuccess: { (cond_code, cond_txt,averageAir,level) in
  74. self.mainView.cond_code = cond_code
  75. // self.mainView.cond_txt = cond_txt
  76. // self.mainView.averageAir = averageAir
  77. // self.mainView.level = level
  78. switch cond_txt{
  79. case "Rain" :
  80. self.mainView.cond_txt = "雨天"
  81. case "Cloudy" :
  82. self.mainView.cond_txt = "多云"
  83. case "Overcast":
  84. self.mainView.cond_txt = "阴天"
  85. case "Sunny/Clear":
  86. self.mainView.cond_txt = "晴天"
  87. default :
  88. self.mainView.cond_txt = cond_txt
  89. }
  90. if averageAir == "no data"{
  91. self.mainView.averageAir = "无数据"
  92. }else{
  93. self.mainView.averageAir = averageAir
  94. }
  95. switch level{
  96. case "Good":
  97. self.mainView.level = "好"
  98. case "Very good":
  99. self.mainView.level = "非常好"
  100. case "Unknown":
  101. self.mainView.level = "未知"
  102. default:
  103. self.mainView.level = level
  104. }
  105. }) {
  106. }
  107. }
  108. let queue2 = DispatchQueue(label: "getHotelviewData")
  109. queue2.async {
  110. //获取首页概览数据
  111. IHHomeService.share.getHomeData(hotelId: hotelId, requestSuccess: { (homeData) in
  112. NotificationCenter.default.post(name: NSNotification.Name(KNotifictionIHEquipmentViewGetHomeData), object: homeData)
  113. }) {
  114. }
  115. }
  116. let queue3 = DispatchQueue(label: "getHotelviewData")
  117. queue3.async {
  118. //获取酒店数据
  119. IHHomeService.share.getHotelviewData(hotelId: hotelId, requestSuccess: { (hotels) in
  120. Intermediate.share.hotels = hotels
  121. }) {
  122. }
  123. }
  124. //首页空气质量跟传感器
  125. let queue4 = DispatchQueue(label: "getRoomEnvStatus")
  126. queue4.async {
  127. IHHomeService.share.getRoomEnvStatus(hotelId) { (result) in
  128. self.mainView.envorentmentInfo = result
  129. NotificationCenter.default.post(name: NSNotification.Name(kNotificationIHAirQualityViewReloadAirData), object: result)
  130. }
  131. }
  132. group.notify(queue: DispatchQueue.main) {
  133. g_showSuccess()
  134. }
  135. }
  136. lazy var mainView: IHDashboardMainView = {
  137. let mainView = IHDashboardMainView()
  138. mainView.frame = CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - KTabbarHeight)
  139. mainView.backgroundColor = .red
  140. return mainView
  141. }()
  142. func createUI() {
  143. setNavigationBar()
  144. self.vc?.view.addSubview(mainView)
  145. mainView.headerViewCallback = {
  146. log.debug("个人中心")
  147. let personalVC = IHPersonalCenterVCtr()
  148. self.vc?.navigationController?.pushViewController(personalVC, animated: true)
  149. }
  150. }
  151. func setNavigationBar() {
  152. //导航栏的渲染方式
  153. self.vc?.navigationBarTitle = " "
  154. let rightItem = UIBarButtonItem(image: UIImage(named: "map")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction))
  155. let leftItem = UIBarButtonItem(image: UIImage(named: "定位")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
  156. self.vc?.navigationItem.rightBarButtonItem = rightItem
  157. self.vc?.navigationItem.leftBarButtonItem = leftItem
  158. }
  159. func ih_viewDidLayoutSubviews() {
  160. mainView.d_viewDidLauyouSubView()
  161. }
  162. @objc func mapAction1(){
  163. log.debug("点击了")
  164. let picker = IHHotelPickerVCtr.shareInstance //全局使用,只初始化一次
  165. self.vc?.navigationController?.pushViewController(picker, animated: true)
  166. }
  167. @objc func mapAction(){
  168. log.debug("点击了")
  169. let map = IHDashboardMapMainVCtr()
  170. self.vc?.navigationController?.pushViewController(map, animated: true)
  171. }
  172. }
  173. extension IHDashboardManager:IHAddressControllerDelegate {
  174. func selectedAddress(address: String, addressID: String) {
  175. self.vc?.navigationBarTitle = address
  176. Intermediate.hotelId = addressID
  177. Intermediate.hotelName = address
  178. self.requestData(addressID)
  179. }
  180. }