IHRoomVCtr.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // IHRoomVCtr.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/14.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. class IHRoomVCtr: UIViewController {
  11. var hotelId :String?
  12. var buildId :String?
  13. var floorId:String?
  14. var roomId :String?
  15. var gatewayList : [GatewayData]?
  16. var totalItemWidth: CGFloat = 0 //总长度
  17. var segmentedDataSource:JXSegmentedBaseDataSource?
  18. var segmentedView = JXSegmentedView()
  19. lazy var listContainerView: JXSegmentedListContainerView! = {
  20. return JXSegmentedListContainerView(dataSource: self)
  21. }()
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. setNavigationBar()
  25. cinfigSegmentdView()
  26. }
  27. func cinfigSegmentdView() {
  28. // self.navigationBarTitle = "Room 1001"
  29. totalItemWidth = UIScreen.main.bounds.size.width - 20*2
  30. view.backgroundColor = .white
  31. let titles = ["所有", "灯控","HCL灯控","感应器","空气净化器"]
  32. let titleDataSource = JXSegmentedTitleDataSource()
  33. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
  34. titleDataSource.titles = titles
  35. titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
  36. titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
  37. titleDataSource.isTitleMaskEnabled = true
  38. titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
  39. titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
  40. titleDataSource.itemSpacing = 0
  41. titleDataSource.itemContentWidth = 120
  42. //titleDataSource.isItemSpacingAverageEnabled = false
  43. segmentedDataSource = titleDataSource
  44. segmentedView.dataSource = segmentedDataSource
  45. segmentedView.layer.masksToBounds = true
  46. segmentedView.layer.cornerRadius = 15
  47. segmentedView.backgroundColor = UIColor(hexString: "#F6F8F7")
  48. segmentedView.delegate = self
  49. view.addSubview(segmentedView)
  50. let indicator = JXSegmentedIndicatorBackgroundView()
  51. indicator.indicatorHeight = 25
  52. indicator.backgroundWidthIncrement = -10
  53. indicator.indicatorColor = UIColor(hexString: "#573F95")!
  54. indicator.layer.shadowColor = UIColor(hexString: "#573F95")!.cgColor
  55. indicator.layer.shadowRadius = 3
  56. indicator.layer.shadowOffset = CGSize.zero
  57. indicator.layer.shadowOpacity = 0.7
  58. segmentedView.indicators = [indicator]
  59. segmentedView.listContainer = listContainerView
  60. view.addSubview(listContainerView)
  61. }
  62. override func viewWillAppear(_ animated: Bool) {
  63. super.viewWillAppear(animated)
  64. //处于第一个item的时候,才允许屏幕边缘手势返回
  65. navigationController?.interactivePopGestureRecognizer?.isEnabled = (segmentedView.selectedIndex == 0)
  66. }
  67. override func viewWillDisappear(_ animated: Bool) {
  68. super.viewWillDisappear(animated)
  69. //离开页面的时候,需要恢复屏幕边缘手势,不能影响其他页面
  70. navigationController?.interactivePopGestureRecognizer?.isEnabled = true
  71. }
  72. override func viewDidLayoutSubviews() {
  73. super.viewDidLayoutSubviews()
  74. segmentedView.frame = CGRect(x: 20, y: 10, width: totalItemWidth, height: 30)
  75. listContainerView.frame = CGRect(x: 0, y: 50, width: view.bounds.size.width, height: view.bounds.size.height - 50)
  76. }
  77. }
  78. extension IHRoomVCtr{
  79. func setNavigationBar() {
  80. //导航栏的渲染方式
  81. let addItem = UIBarButtonItem(image: UIImage(named: "新增")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(addAction1))
  82. let setItem = UIBarButtonItem(image: UIImage(named: "模式设置")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(mapAction1))
  83. self.navigationItem.rightBarButtonItems = [setItem,addItem]
  84. }
  85. @objc func addAction1(){
  86. log.debug("点击了")
  87. let newEquipment = IHNewEquipmentVCtr()
  88. newEquipment.floorId = self.floorId
  89. newEquipment.roomId = self.roomId
  90. newEquipment.roomStyle = .oldRoom
  91. newEquipment.gatewayList = self.gatewayList
  92. newEquipment.navigationBarTitle = "新增设备"
  93. self.navigationController?.pushViewController(newEquipment, animated: true)
  94. }
  95. @objc func mapAction(){
  96. log.debug("点击了")
  97. let map = IHDashboardMapMainVCtr()
  98. self.navigationController?.pushViewController(map, animated: true)
  99. }
  100. @objc func mapAction1(){
  101. log.debug("点击了")
  102. let centralied = IHCentralizedVCtr()
  103. // vc.floorList = self.floorList
  104. centralied.isSetSencenModel = true
  105. centralied.roomId = self.roomId
  106. self.navigationController?.pushViewController(centralied, animated: true)
  107. }
  108. }
  109. extension IHRoomVCtr:JXSegmentedViewDelegate{
  110. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  111. if let dotDataSource = segmentedDataSource as? JXSegmentedDotDataSource {
  112. //先更新数据源的数据
  113. dotDataSource.dotStates[index] = false
  114. //再调用reloadItem(at: index)
  115. segmentedView.reloadItem(at: index)
  116. }
  117. log.debug("segmentedView - \(index)")
  118. NotificationCenter.default.post(name: NSNotification.Name(kIHRoomListManagerNoticationSegmentViewSelectedIndex), object: index)
  119. navigationController?.interactivePopGestureRecognizer?.isEnabled = (segmentedView.selectedIndex == 0)
  120. }
  121. }
  122. extension IHRoomVCtr:JXSegmentedListContainerViewDataSource{
  123. func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
  124. if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
  125. return titleDataSource.dataSource.count
  126. }
  127. return 0
  128. }
  129. func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
  130. let vc = IHRoomListVCtr()
  131. vc.hotelId = self.hotelId
  132. vc.buildId = self.buildId
  133. vc.floorId = self.floorId
  134. vc.roomId = self.roomId
  135. vc.devType = index
  136. return vc
  137. }
  138. }