IHEquipmentlistView.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. //
  2. // IHEquipmentlistView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/18.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import SwipeCellKit
  11. import ESPullToRefresh
  12. let kNotifactionIHEquipmentlistViewNotifySelectGateway = "kNotifactionIHEquipmentlistViewNotifySelectGateway"
  13. protocol IHEquipmentlistViewDelegate : NSObjectProtocol{
  14. //func equipmentlistViewdidSelectedItemAt(_ index: Int)
  15. func equipmentlistViewdidSelectedItemAt(_ index : Int,floorId : String?,roomId : String?) //选择每个 标题
  16. func equipmentListDeleteDevice(_ devType : String,devId:String,segmentIndex:Int)
  17. func equipmentSetting(_ devData:DevData,segmentIndex:Int)
  18. func equipmentHistory(_ devData:DevData,segmentIndex:Int)
  19. func gatewayUpdate(_ gateway:GatewayData,segmentIndex:Int)
  20. func gatewaySetting(_ gateway:GatewayData,segmentIndex:Int)
  21. func gatewayDelegate(_ gateway:GatewayData,segmentIndex:Int)
  22. func equipmentListSelected(_ gateway:GatewayData?)
  23. func equipmentListSelected(_ devData:DevData?)
  24. // func tableviewBottonEsgetMoreData(_index: Int) //上拉刷新
  25. //func tableviewHeaderEsReloadData() //下拉刷新
  26. func tableviewHeaderEsReloadData(floorId : String?,roomId : String?)//上拉刷新
  27. func tableviewBottonEsgetMoreData(floorId : String?,roomId : String?)//下拉刷新
  28. func selectFloorRoom(_ index : Int,floorId: String?,roomId : String?)//楼层或房间
  29. }
  30. class IHEquipmentlistView: UIView {
  31. weak var delegate : IHEquipmentlistViewDelegate?
  32. var devDataList:[DevData]?{
  33. didSet{
  34. isFloor = false
  35. isRoom = false
  36. self.tableView.reloadData()
  37. }
  38. }
  39. var gatewayList:[GatewayData]?{
  40. didSet{
  41. if AppShare.tabbarSelected == true {
  42. self.devDataList = nil//首页跳转的时候,需要删除其他数据
  43. self.segmentedView.selectItemAt(index: 5)
  44. self.segmentedView.listContainer?.didClickSelectedItem(at: 5)//列表滚动
  45. AppShare.tabbarSelected = false
  46. }
  47. self.tableView.reloadData()
  48. }
  49. }
  50. let titles = ["全部", "灯控","HCL灯控","感应器","空气净化器","网关"]
  51. let schoolTitles = ["全部","教室灯","黑板灯","面板","窗帘","网关"]
  52. var currentIndex : Int? = 0
  53. var totalItemWidth: CGFloat = 0 //总长度
  54. var segmentedDataSource:JXSegmentedBaseDataSource?
  55. var schoolBackView : UIView?
  56. private var floorList : [String]? //所有楼层
  57. //private var roomList : [String]? //每层的所有房间
  58. var classRoomList : [String]? //每个楼层的所有教室
  59. var currentFloorId : String? //当前楼层的id
  60. var currentRoomId : String? //当前房间的id
  61. var floorBtn : UIButton? //楼层
  62. var roomBtn : UIButton? //房间
  63. // var floorAndRooms = [[String : [String]]]() //楼层对应的所有教室
  64. var floorAndRooms = [(floor : String , classRoomName : [String])]() //楼层对应的所有教室
  65. var segmentedView = JXSegmentedView()
  66. var isFloor = false
  67. var isRoom = false
  68. var coverBtn : UIButton?
  69. var isFilter : Bool = false
  70. var totalList : [DevData]?
  71. var totalGateWayList : [GatewayData]?
  72. var floorValue : String = "所有"
  73. var classRoomValue : String = "所有"
  74. var oldCurrentIndex = 0
  75. //编辑的cell
  76. var editingIndexPath : IndexPath?
  77. //每层所有房间的模型
  78. var floorRoomList : [FloorRoom]?{
  79. didSet{
  80. var list = [String]()
  81. for room in floorRoomList! {
  82. if room.number != nil || room.number != ""{
  83. list.append(room.number!)
  84. }
  85. }
  86. classRoomList = list
  87. }
  88. }
  89. //楼层的模型
  90. var areaFloorList : [AreaFloor]?{
  91. didSet{
  92. //var list = ["所有"]
  93. var list = [String]()
  94. for floor in areaFloorList! {
  95. if floor.name != nil || floor.name != ""{
  96. list.append(floor.name!)
  97. }
  98. }
  99. floorList = list
  100. }
  101. }
  102. var isSchool : Bool? = false{
  103. didSet{
  104. // cinfigSegmentdView()
  105. let titleDataSource = JXSegmentedTitleDataSource()
  106. self.setNeedsLayout()
  107. if isSchool == true{
  108. //学校
  109. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(schoolTitles.count)
  110. titleDataSource.titles = schoolTitles
  111. }else{
  112. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
  113. titleDataSource.titles = titles
  114. }
  115. titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
  116. titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
  117. titleDataSource.isTitleMaskEnabled = true
  118. titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
  119. titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
  120. titleDataSource.itemSpacing = 0
  121. titleDataSource.itemContentWidth = 120
  122. segmentedDataSource = titleDataSource
  123. segmentedView.dataSource = segmentedDataSource
  124. segmentedView.reloadData()
  125. }
  126. }
  127. lazy var tableView: UITableView = {
  128. let tableView = UITableView(frame: .zero, style: .plain)
  129. tableView.delegate = self
  130. tableView.dataSource = self
  131. tableView.allowsSelection = true
  132. tableView.separatorStyle = .none
  133. tableView.register(UINib(nibName: "IHEquipmentListCell", bundle: nil), forCellReuseIdentifier: "cell")
  134. return tableView
  135. }()
  136. override init(frame: CGRect) {
  137. super.init(frame: frame)
  138. createSchoolFloorAndRoomPicker()
  139. cinfigSegmentdView()
  140. addSubview(tableView)
  141. NotificationCenter.default.addObserver(self, selector: #selector(notifySelectGateway), name: NSNotification.Name(kNotifactionIHEquipmentlistViewNotifySelectGateway), object: nil)
  142. let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
  143. let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
  144. //下拉刷新
  145. tableView.es.addPullToRefresh(animator: header) {[unowned self] in
  146. log.debug("下ll拉加载更多")
  147. self.delegate?.tableviewHeaderEsReloadData(floorId: self.currentFloorId, roomId: self.currentRoomId)
  148. }
  149. //上拉加载更多
  150. tableView.es.addInfiniteScrolling(animator: footer) {[unowned self] in
  151. log.debug("上拉加载更多")
  152. //上拉刷新
  153. self.delegate?.tableviewBottonEsgetMoreData(floorId: self.currentFloorId, roomId: self.currentRoomId)
  154. }
  155. }
  156. func endReflesh(){
  157. tableView.es.stopPullToRefresh()
  158. tableView.es.stopLoadingMore()
  159. }
  160. required init?(coder: NSCoder) {
  161. fatalError("init(coder:) has not been implemented")
  162. }
  163. @objc func notifySelectGateway() {
  164. self.segmentedView.selectItemAt(index: 5)
  165. self.segmentedView.listContainer?.didClickSelectedItem(at: 5)//列表滚动
  166. }
  167. override func layoutSubviews() {
  168. super.layoutSubviews()
  169. if isSchool == true {
  170. //学校
  171. schoolBackView?.isHidden = false
  172. schoolBackView?.frame = CGRect(x: 20, y: 10, width: KSCREENWIDTH - 40, height: 30)
  173. segmentedView.frame = CGRect(x: 20, y: 50, width: totalItemWidth, height: 30)
  174. tableView.frame = CGRect(x: 0, y: 80, width: KSCREENWIDTH, height: KSCREENHEIGHT - 80 - KNavBarHeight - KTabbarHeight)
  175. }else{
  176. segmentedView.frame = CGRect(x: 20, y: 10, width: totalItemWidth, height: 30)
  177. tableView.frame = CGRect(x: 0, y: 50, width: KSCREENWIDTH, height: KSCREENHEIGHT - 50 - KNavBarHeight - KTabbarHeight)
  178. }
  179. if self.editingIndexPath != nil {
  180. configSwipeButtons()
  181. }
  182. }
  183. }
  184. extension IHEquipmentlistView{
  185. //楼层与教室
  186. private func createSchoolFloorAndRoomPicker(){
  187. schoolBackView = UIView.init()
  188. schoolBackView?.backgroundColor = UIColor.init(hexString: "#F6F8F7")
  189. let w : CGFloat = KSCREENWIDTH - 40 - 140
  190. let h : CGFloat = 30
  191. setFloorAndClassRoom(x: 0, w: 140, h: h, content: "楼层", superView: schoolBackView!,tag : 1)
  192. setFloorAndClassRoom(x: 140, w: w, h: h, content: "教室", superView: schoolBackView!,tag : 2)
  193. self.addSubview(schoolBackView!)
  194. schoolBackView?.isHidden = true
  195. }
  196. private func setFloorAndClassRoom(x : CGFloat,w : CGFloat,h : CGFloat, content : String,superView : UIView,tag : Int){
  197. let floorBackView = UIView.init(frame: CGRect.init(x: x, y: 0, width: w, height: h))
  198. let floorLabel = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: h))
  199. floorLabel.text = content
  200. floorLabel.sizeToFit()
  201. floorLabel.size.height = h
  202. floorLabel.font = UIFont.systemFont(ofSize: 14.0)
  203. let floorBtn = UIButton.init(frame: CGRect.init(x: floorLabel.size.width + 4, y: 2, width: w - floorLabel.size.width - 17, height: h - 4))
  204. floorBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14.0)
  205. floorBtn.setTitleColor(.black, for: .normal)
  206. floorBtn.tag = tag
  207. floorBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14.0)
  208. floorBtn.setTitle("所有", for: .normal)
  209. floorBtn.addTarget(self, action: #selector(chooseFloor), for: .touchUpInside)
  210. floorBtn.backgroundColor = .white
  211. floorBtn.layer.cornerRadius = 8
  212. floorBtn.layer.masksToBounds = true
  213. floorBtn.setImage(UIImage.init(named: "xialaIcon"), for: .normal)
  214. floorBtn.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 4)
  215. floorBtn.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 10)
  216. floorBtn.semanticContentAttribute = .forceRightToLeft
  217. floorBtn.contentHorizontalAlignment = .center
  218. floorBackView.addSubview(floorLabel)
  219. floorBackView.addSubview(floorBtn)
  220. if tag == 1{
  221. self.floorBtn = floorBtn
  222. }else{
  223. self.roomBtn = floorBtn
  224. }
  225. superView.addSubview(floorBackView)
  226. }
  227. @objc private func chooseFloor(btn : UIButton){
  228. //btn.tag == 1 : 楼层, btn.tag == 2 : 教室
  229. if btn.tag == 1 {
  230. isFloor = true
  231. isRoom = false
  232. }
  233. if btn.tag == 2 {
  234. isRoom = true
  235. isFloor = false
  236. }
  237. let window = UIApplication.shared.keyWindow
  238. let coverBtn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT))
  239. coverBtn.addTarget(self, action: #selector(hideChooseFloorCover), for: .touchUpInside)
  240. coverBtn.backgroundColor = UIColor.init(white: 0.5, alpha: 0.5)
  241. window?.addSubview(coverBtn)
  242. let p = btn.convert(btn.frame.origin, to: coverBtn)
  243. let schoolTableView = UITableView.init(frame: CGRect.init(x: 0, y: p.y + 30, width: 170, height: 120))
  244. if btn.tag == 1{
  245. schoolTableView.frame.origin.x = 10
  246. }
  247. if btn.tag == 2{
  248. schoolTableView.frame.origin.x = KSCREENWIDTH - 180
  249. }
  250. schoolTableView.delegate = self
  251. schoolTableView.dataSource = self
  252. // schoolTableView.backgroundColor = .red
  253. coverBtn.addSubview(schoolTableView)
  254. self.coverBtn = coverBtn
  255. schoolTableView.reloadData()
  256. }
  257. @objc private func hideChooseFloorCover(btn : UIButton){
  258. btn.removeFromSuperview()
  259. isFloor = false
  260. isRoom = false
  261. }
  262. func cinfigSegmentdView() {
  263. totalItemWidth = UIScreen.main.bounds.size.width - 20*2
  264. backgroundColor = .white
  265. // let titles = [ "Lights","Circadian Lights","Sensor","Air Purifiers"]
  266. let titleDataSource = JXSegmentedTitleDataSource()
  267. if self.isSchool == true{
  268. //学校
  269. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(schoolTitles.count)
  270. titleDataSource.titles = schoolTitles
  271. }else{
  272. titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
  273. titleDataSource.titles = titles
  274. }
  275. titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
  276. titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
  277. titleDataSource.isTitleMaskEnabled = true
  278. titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
  279. titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
  280. titleDataSource.itemSpacing = 0
  281. titleDataSource.itemContentWidth = 120
  282. //titleDataSource.isItemSpacingAverageEnabled = false
  283. segmentedDataSource = titleDataSource
  284. segmentedView.dataSource = segmentedDataSource
  285. segmentedView.layer.masksToBounds = true
  286. segmentedView.layer.cornerRadius = 15
  287. segmentedView.backgroundColor = UIColor(hexString: "#F6F8F7")
  288. segmentedView.delegate = self
  289. addSubview(segmentedView)
  290. let indicator = JXSegmentedIndicatorBackgroundView()
  291. indicator.indicatorHeight = 25
  292. indicator.backgroundWidthIncrement = -10
  293. indicator.indicatorColor = UIColor(hexString: "#573F95")!
  294. indicator.layer.shadowColor = UIColor(hexString: "#573F95")!.cgColor
  295. indicator.layer.shadowRadius = 3
  296. indicator.layer.shadowOffset = CGSize.zero
  297. indicator.layer.shadowOpacity = 0.7
  298. segmentedView.indicators = [indicator]
  299. }
  300. }
  301. extension IHEquipmentlistView:JXSegmentedViewDelegate{
  302. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  303. delegate?.equipmentlistViewdidSelectedItemAt(index, floorId: self.currentFloorId, roomId: self.currentRoomId)
  304. self.currentIndex = index
  305. if let dotDataSource = segmentedDataSource as? JXSegmentedDotDataSource {
  306. //先更新数据源的数据
  307. dotDataSource.dotStates[index] = false
  308. //再调用reloadItem(at: index)
  309. segmentedView.reloadItem(at: index)
  310. }
  311. }
  312. }
  313. extension IHEquipmentlistView:UITableViewDelegate,UITableViewDataSource{
  314. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  315. if isFloor == true {
  316. let floorListCount = self.floorList?.count ?? 0
  317. return floorListCount
  318. }else if isRoom == true {
  319. let roomListCount = self.classRoomList?.count ?? 0
  320. return roomListCount
  321. }else if currentIndex == 0 {
  322. let devCount = self.devDataList?.count ?? 0
  323. let gatewayListCount = self.gatewayList?.count ?? 0
  324. let totalCount = devCount + gatewayListCount
  325. return totalCount
  326. }else if currentIndex == 5{
  327. let gatewayListCount = self.gatewayList?.count ?? 0
  328. return gatewayListCount
  329. }else{
  330. return self.devDataList?.count ?? 0
  331. }
  332. }
  333. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  334. //return 135
  335. if isRoom == true || isFloor == true {
  336. return 40
  337. }else {
  338. return 135
  339. }
  340. }
  341. //iOS 11 将进入此方法 actions.performsFirstActionWithFullSwipe = NO 可以控制是否自动删除。
  342. func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  343. // if isRoom != true || isFloor != true {
  344. // return nil
  345. // }
  346. log.debug("左滑")
  347. #warning("快速移动的时候,如不加此方法,就有可能不执行layoutsubviews")
  348. self.tableView(self.tableView, willBeginEditingRowAt: indexPath)
  349. let deleteAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  350. completionHandler(true)
  351. log.debug("删除")
  352. if self.currentIndex == 0{
  353. if let devDataList = self.devDataList {
  354. if indexPath.row < devDataList.count {
  355. if let delegate = self.delegate{
  356. let devData = self.devDataList![indexPath.row]
  357. delegate.equipmentListDeleteDevice(devData.devType!, devId: devData.id!, segmentIndex: self.currentIndex ?? 0)
  358. }
  359. }else{
  360. if let delegate = self.delegate {
  361. // delegate.gatewayUpdate(segmentIndex: self.currentIndex ?? 5)
  362. let gateway = self.gatewayList![indexPath.row - devDataList.count ]
  363. delegate.gatewayDelegate(gateway, segmentIndex: self.currentIndex ?? 0)
  364. }
  365. }
  366. }
  367. }else if self.currentIndex == 5{
  368. if let delegate = self.delegate {
  369. let gateway = self.gatewayList![indexPath.row ]
  370. delegate.gatewayDelegate(gateway, segmentIndex: self.currentIndex ?? 5)
  371. }
  372. }else{
  373. if let delegate = self.delegate{
  374. let devData = self.devDataList![indexPath.row]
  375. delegate.equipmentListDeleteDevice(devData.devType!, devId: devData.id!, segmentIndex: self.currentIndex ?? 0)
  376. }
  377. }
  378. //处理事件
  379. }
  380. deleteAction.backgroundColor = UIColor(hexString: "#EBEFF2")
  381. let historyAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  382. completionHandler(true)
  383. //处理事件0
  384. log.debug("历史数据")
  385. if self.currentIndex == 0{
  386. if let devDataList = self.devDataList {
  387. if indexPath.row < devDataList.count {
  388. if let delegate = self.delegate{
  389. let data = self.devDataList![indexPath.row]
  390. delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
  391. }
  392. }else{
  393. if let delegate = self.delegate {
  394. let data = self.gatewayList![indexPath.row - devDataList.count ]
  395. delegate.gatewayUpdate(data, segmentIndex: self.currentIndex ?? 0)
  396. }
  397. }
  398. }
  399. }else if self.currentIndex == 5{
  400. if let delegate = self.delegate {
  401. let data = self.gatewayList![indexPath.row]
  402. delegate.gatewayUpdate(data, segmentIndex: self.currentIndex ?? 5)
  403. }
  404. }else{
  405. if let delegate = self.delegate{
  406. let data = self.devDataList![indexPath.row]
  407. delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
  408. }
  409. }
  410. }
  411. //#31D4C1 #0A82CF
  412. historyAction.backgroundColor = UIColor(hexString: "#31D4C1")
  413. let settingAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  414. completionHandler(true)
  415. if self.currentIndex == 0{
  416. if let devDataList = self.devDataList {
  417. if indexPath.row < devDataList.count {
  418. if let delegate = self.delegate{
  419. let data = self.devDataList![indexPath.row]
  420. delegate.equipmentSetting(data, segmentIndex: self.currentIndex ?? 0)
  421. }
  422. }else{
  423. if let delegate = self.delegate{
  424. let data = self.gatewayList![indexPath.row - devDataList.count ]
  425. delegate.gatewaySetting(data, segmentIndex: self.currentIndex ?? 5)
  426. }
  427. }
  428. }
  429. }else if self.currentIndex == 5{
  430. if let delegate = self.delegate {
  431. let data = self.gatewayList![indexPath.row ]
  432. delegate.gatewaySetting(data, segmentIndex: self.currentIndex ?? 5)
  433. }
  434. }else{
  435. log.debug("设置")
  436. if let delegate = self.delegate{
  437. let data = self.devDataList![indexPath.row]
  438. delegate.equipmentSetting(data, segmentIndex: self.currentIndex ?? 0)
  439. }
  440. }
  441. //处理事件
  442. }
  443. //#05CFAB
  444. settingAction.backgroundColor = UIColor(hexString: "#573F95")
  445. let actions = UISwipeActionsConfiguration(actions: [settingAction,historyAction,deleteAction])
  446. actions.performsFirstActionWithFullSwipe = false
  447. return actions
  448. }
  449. func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  450. if isRoom == true || isFloor == true {
  451. return false
  452. }else{
  453. return true
  454. }
  455. //return true
  456. }
  457. func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
  458. editingIndexPath = indexPath
  459. log.debug("移动移动")
  460. setNeedsLayout() // 触发layoutSubviews()
  461. }
  462. //取消选中
  463. func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
  464. editingIndexPath = nil
  465. // log.debug("didEndEditingRowAt")
  466. }
  467. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  468. if isFloor == true || isRoom == true {
  469. let schoolCell = "schoolCell"
  470. var cell = tableView.dequeueReusableCell(withIdentifier: schoolCell)
  471. if cell == nil{
  472. cell = UITableViewCell.init(style: .default, reuseIdentifier: schoolCell)
  473. }
  474. var lists = [String]()
  475. if isFloor == true {
  476. lists = self.floorList!
  477. }else{
  478. lists = self.classRoomList!
  479. }
  480. cell?.textLabel?.text = lists[indexPath.row]
  481. cell?.textLabel?.font = UIFont.systemFont(ofSize: 14.0)
  482. cell?.textLabel?.textAlignment = .center
  483. return cell!
  484. }else{
  485. let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHEquipmentListCell
  486. cell.selectionStyle = .none
  487. if currentIndex == 0 {
  488. if let devDataList = self.devDataList {
  489. if indexPath.row < devDataList.count {
  490. cell.devData = devDataList[indexPath.row]
  491. }else{//0 1 2 3 4 5
  492. // 3 - 3 = 0
  493. cell.gateway = self.gatewayList?[ indexPath.row - devDataList.count ]
  494. }
  495. }
  496. }else if currentIndex == 5 {
  497. //网关
  498. cell.gateway = self.gatewayList?[indexPath.row]
  499. }else {
  500. //每个按钮
  501. cell.devData = devDataList![indexPath.row]
  502. }
  503. return cell
  504. }
  505. }
  506. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  507. if isFloor == true || isRoom == true{
  508. if isFloor == true {
  509. //加载楼层的所有房间
  510. let floorData = self.areaFloorList![indexPath.row]
  511. if floorData.id != currentFloorId{
  512. roomBtn?.setTitle("所有", for: .normal)
  513. }
  514. currentFloorId = floorData.id
  515. //delegate?.selectFloorRoom(floorId: floorData.id!)
  516. delegate?.selectFloorRoom(self.currentIndex!,floorId: currentFloorId, roomId: nil)
  517. currentRoomId = nil
  518. floorBtn?.setTitle(floorData.name, for: .normal)
  519. }
  520. if isRoom == true {
  521. //加载房间
  522. let roomData = self.floorRoomList![indexPath.row]
  523. currentRoomId = roomData.id
  524. delegate?.selectFloorRoom(self.currentIndex!,floorId: currentFloorId, roomId: currentRoomId)
  525. roomBtn?.setTitle(roomData.number, for: .normal)
  526. }
  527. self.coverBtn?.removeFromSuperview()
  528. }else if currentIndex == 0 {
  529. if let devDataList = self.devDataList {
  530. if indexPath.row < devDataList.count {
  531. if let delegate = self.delegate {
  532. let device = self.devDataList![indexPath.row]
  533. delegate.equipmentListSelected(device)
  534. }
  535. }else{
  536. if let delegate = self.delegate {
  537. let gateway = self.gatewayList![indexPath.row - devDataList.count]
  538. delegate.equipmentListSelected(gateway)
  539. }
  540. }
  541. }
  542. }else if currentIndex == 5 {
  543. if let delegate = self.delegate {
  544. let gateway = self.gatewayList![indexPath.row]
  545. delegate.equipmentListSelected(gateway)
  546. }
  547. }else {
  548. if let delegate = self.delegate {
  549. let device = self.devDataList![indexPath.row]
  550. delegate.equipmentListSelected(device)
  551. }
  552. }
  553. }
  554. func configSwipeButtons() {
  555. // log.debug("重新绘制 ")
  556. //iOS 11 层级 UITableView -> UISwipActionPull
  557. var swipeButtons : [UIView]?
  558. if #available(iOS 11, *) {
  559. swipeButtons = self.tableView.getSwipeButtonView()
  560. }else{
  561. // iOS 8-10: 画UITableView->UITableViewCell->UITableVIewCellDeleteConfirmationView
  562. let tabCell = self.tableView.cellForRow(at: self.editingIndexPath!)
  563. swipeButtons = tabCell?.getSwipeButtonView()
  564. }
  565. // log.debug("子控件 -- \(swipeButtons)")
  566. if swipeButtons?.count == 0 || swipeButtons == nil {
  567. return
  568. }
  569. for i in 0..<(swipeButtons?.count)!{
  570. let button = swipeButtons![i] as! UIButton
  571. if i == 0 {
  572. //ic_delete_bg
  573. configSwipeButton(button, backgroundImage: UIImage(named: "删除")!)
  574. }else if i == 1{
  575. if currentIndex == 0 {
  576. if let devDataList = self.devDataList {
  577. if self.editingIndexPath!.row < devDataList.count {
  578. //ic_hitory_bg
  579. configSwipeButton(button, backgroundImage: UIImage(named: "历史")!)
  580. }else{
  581. configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  582. }
  583. }
  584. }else if currentIndex == 5{
  585. configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  586. }else {
  587. //ic_hitory_bg
  588. configSwipeButton(button, backgroundImage: UIImage(named: "历史")!)
  589. }
  590. }else{
  591. //ic_setting_bg
  592. configSwipeButton(button, backgroundImage: UIImage(named: "设置-紫")!)
  593. }
  594. }
  595. }
  596. func configSwipeButton(_ button: UIButton,backgroundImage:UIImage) {
  597. button.layer.cornerRadius = 5
  598. button.layer.masksToBounds = true
  599. button.setBackgroundImage(backgroundImage, for: .normal)
  600. button.setBackgroundImage(backgroundImage, for: .selected)
  601. button.titleLabel?.font = UIFont(name: PingFangSC_Medium, size: 11)
  602. let frame = button.frame
  603. button.frame = CGRect(x: frame.origin.x + 5 , y: frame.origin.y + 10, width: frame.size.width - 10, height: frame.size.height - 20)
  604. log.debug("frame\(button.frame)")
  605. }
  606. }