123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- //
- // IHEquipmentlistView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/18.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import SwipeCellKit
- import ESPullToRefresh
- let kNotifactionIHEquipmentlistViewNotifySelectGateway = "kNotifactionIHEquipmentlistViewNotifySelectGateway"
- protocol IHEquipmentlistViewDelegate : NSObjectProtocol{
- //func equipmentlistViewdidSelectedItemAt(_ index: Int)
- func equipmentlistViewdidSelectedItemAt(_ index : Int,floorId : String?,roomId : String?) //选择每个 标题
- func equipmentListDeleteDevice(_ devType : String,devId:String,segmentIndex:Int)
- func equipmentSetting(_ devData:DevData,segmentIndex:Int)
- func equipmentHistory(_ devData:DevData,segmentIndex:Int)
- func gatewayUpdate(_ gateway:GatewayData,segmentIndex:Int)
- func gatewaySetting(_ gateway:GatewayData,segmentIndex:Int)
- func gatewayDelegate(_ gateway:GatewayData,segmentIndex:Int)
- func equipmentListSelected(_ gateway:GatewayData?)
- func equipmentListSelected(_ devData:DevData?)
- // func tableviewBottonEsgetMoreData(_index: Int) //上拉刷新
- //func tableviewHeaderEsReloadData() //下拉刷新
-
- func tableviewHeaderEsReloadData(floorId : String?,roomId : String?)//上拉刷新
- func tableviewBottonEsgetMoreData(floorId : String?,roomId : String?)//下拉刷新
- func selectFloorRoom(_ index : Int,floorId: String?,roomId : String?)//楼层或房间
- }
- class IHEquipmentlistView: UIView {
- weak var delegate : IHEquipmentlistViewDelegate?
-
- var devDataList:[DevData]?{
- didSet{
- isFloor = false
- isRoom = false
- self.tableView.reloadData()
- }
- }
-
- var gatewayList:[GatewayData]?{
- didSet{
- if AppShare.tabbarSelected == true {
- self.devDataList = nil//首页跳转的时候,需要删除其他数据
- self.segmentedView.selectItemAt(index: 5)
- self.segmentedView.listContainer?.didClickSelectedItem(at: 5)//列表滚动
- AppShare.tabbarSelected = false
- }
- self.tableView.reloadData()
- }
- }
-
-
- let titles = ["全部", "灯控","HCL灯控","感应器","空气净化器","网关"]
- let schoolTitles = ["全部","教室灯","黑板灯","面板","窗帘","网关"]
- var currentIndex : Int? = 0
- var totalItemWidth: CGFloat = 0 //总长度
- var segmentedDataSource:JXSegmentedBaseDataSource?
- var schoolBackView : UIView?
- private var floorList : [String]? //所有楼层
- //private var roomList : [String]? //每层的所有房间
-
- var classRoomList : [String]? //每个楼层的所有教室
- var currentFloorId : String? //当前楼层的id
- var currentRoomId : String? //当前房间的id
- var floorBtn : UIButton? //楼层
- var roomBtn : UIButton? //房间
- // var floorAndRooms = [[String : [String]]]() //楼层对应的所有教室
- var floorAndRooms = [(floor : String , classRoomName : [String])]() //楼层对应的所有教室
- var segmentedView = JXSegmentedView()
-
- var isFloor = false
- var isRoom = false
- var coverBtn : UIButton?
- var isFilter : Bool = false
- var totalList : [DevData]?
- var totalGateWayList : [GatewayData]?
- var floorValue : String = "所有"
- var classRoomValue : String = "所有"
- var oldCurrentIndex = 0
- //编辑的cell
- var editingIndexPath : IndexPath?
- //每层所有房间的模型
- var floorRoomList : [FloorRoom]?{
- didSet{
- var list = [String]()
- for room in floorRoomList! {
- if room.number != nil || room.number != ""{
- list.append(room.number!)
- }
- }
- classRoomList = list
-
- }
- }
- //楼层的模型
- var areaFloorList : [AreaFloor]?{
- didSet{
-
- //var list = ["所有"]
- var list = [String]()
- for floor in areaFloorList! {
- if floor.name != nil || floor.name != ""{
- list.append(floor.name!)
- }
- }
- floorList = list
- }
- }
- var isSchool : Bool? = false{
- didSet{
- // cinfigSegmentdView()
-
- let titleDataSource = JXSegmentedTitleDataSource()
- self.setNeedsLayout()
- if isSchool == true{
- //学校
- titleDataSource.itemContentWidth = totalItemWidth/CGFloat(schoolTitles.count)
- titleDataSource.titles = schoolTitles
- }else{
- titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
- titleDataSource.titles = titles
- }
- titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
- titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
- titleDataSource.isTitleMaskEnabled = true
- titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
- titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
- titleDataSource.itemSpacing = 0
- titleDataSource.itemContentWidth = 120
-
- segmentedDataSource = titleDataSource
- segmentedView.dataSource = segmentedDataSource
- segmentedView.reloadData()
- }
- }
-
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: .zero, style: .plain)
- tableView.delegate = self
- tableView.dataSource = self
- tableView.allowsSelection = true
- tableView.separatorStyle = .none
- tableView.register(UINib(nibName: "IHEquipmentListCell", bundle: nil), forCellReuseIdentifier: "cell")
- return tableView
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- createSchoolFloorAndRoomPicker()
- cinfigSegmentdView()
- addSubview(tableView)
-
- NotificationCenter.default.addObserver(self, selector: #selector(notifySelectGateway), name: NSNotification.Name(kNotifactionIHEquipmentlistViewNotifySelectGateway), object: nil)
-
- let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
- let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
- //下拉刷新
- tableView.es.addPullToRefresh(animator: header) {[unowned self] in
- log.debug("下ll拉加载更多")
-
- self.delegate?.tableviewHeaderEsReloadData(floorId: self.currentFloorId, roomId: self.currentRoomId)
- }
-
- //上拉加载更多
- tableView.es.addInfiniteScrolling(animator: footer) {[unowned self] in
- log.debug("上拉加载更多")
- //上拉刷新
- self.delegate?.tableviewBottonEsgetMoreData(floorId: self.currentFloorId, roomId: self.currentRoomId)
- }
- }
-
-
- func endReflesh(){
- tableView.es.stopPullToRefresh()
- tableView.es.stopLoadingMore()
-
- }
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- @objc func notifySelectGateway() {
- self.segmentedView.selectItemAt(index: 5)
- self.segmentedView.listContainer?.didClickSelectedItem(at: 5)//列表滚动
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- if isSchool == true {
- //学校
- schoolBackView?.isHidden = false
- schoolBackView?.frame = CGRect(x: 20, y: 10, width: KSCREENWIDTH - 40, height: 30)
- segmentedView.frame = CGRect(x: 20, y: 50, width: totalItemWidth, height: 30)
- tableView.frame = CGRect(x: 0, y: 80, width: KSCREENWIDTH, height: KSCREENHEIGHT - 80 - KNavBarHeight - KTabbarHeight)
- }else{
- segmentedView.frame = CGRect(x: 20, y: 10, width: totalItemWidth, height: 30)
- tableView.frame = CGRect(x: 0, y: 50, width: KSCREENWIDTH, height: KSCREENHEIGHT - 50 - KNavBarHeight - KTabbarHeight)
- }
-
-
- if self.editingIndexPath != nil {
- configSwipeButtons()
- }
- }
-
- }
- extension IHEquipmentlistView{
- //楼层与教室
- private func createSchoolFloorAndRoomPicker(){
- schoolBackView = UIView.init()
- schoolBackView?.backgroundColor = UIColor.init(hexString: "#F6F8F7")
- let w : CGFloat = KSCREENWIDTH - 40 - 140
- let h : CGFloat = 30
- setFloorAndClassRoom(x: 0, w: 140, h: h, content: "楼层", superView: schoolBackView!,tag : 1)
- setFloorAndClassRoom(x: 140, w: w, h: h, content: "教室", superView: schoolBackView!,tag : 2)
- self.addSubview(schoolBackView!)
- schoolBackView?.isHidden = true
- }
-
- private func setFloorAndClassRoom(x : CGFloat,w : CGFloat,h : CGFloat, content : String,superView : UIView,tag : Int){
- let floorBackView = UIView.init(frame: CGRect.init(x: x, y: 0, width: w, height: h))
- let floorLabel = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: h))
- floorLabel.text = content
- floorLabel.sizeToFit()
- floorLabel.size.height = h
- floorLabel.font = UIFont.systemFont(ofSize: 14.0)
- let floorBtn = UIButton.init(frame: CGRect.init(x: floorLabel.size.width + 4, y: 2, width: w - floorLabel.size.width - 17, height: h - 4))
- floorBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14.0)
- floorBtn.setTitleColor(.black, for: .normal)
- floorBtn.tag = tag
- floorBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14.0)
- floorBtn.setTitle("所有", for: .normal)
- floorBtn.addTarget(self, action: #selector(chooseFloor), for: .touchUpInside)
- floorBtn.backgroundColor = .white
- floorBtn.layer.cornerRadius = 8
- floorBtn.layer.masksToBounds = true
- floorBtn.setImage(UIImage.init(named: "xialaIcon"), for: .normal)
- floorBtn.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 4)
- floorBtn.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 10)
- floorBtn.semanticContentAttribute = .forceRightToLeft
- floorBtn.contentHorizontalAlignment = .center
- floorBackView.addSubview(floorLabel)
- floorBackView.addSubview(floorBtn)
- if tag == 1{
- self.floorBtn = floorBtn
- }else{
- self.roomBtn = floorBtn
- }
-
- superView.addSubview(floorBackView)
- }
-
- @objc private func chooseFloor(btn : UIButton){
- //btn.tag == 1 : 楼层, btn.tag == 2 : 教室
- if btn.tag == 1 {
- isFloor = true
- isRoom = false
- }
- if btn.tag == 2 {
- isRoom = true
- isFloor = false
- }
- let window = UIApplication.shared.keyWindow
- let coverBtn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT))
- coverBtn.addTarget(self, action: #selector(hideChooseFloorCover), for: .touchUpInside)
- coverBtn.backgroundColor = UIColor.init(white: 0.5, alpha: 0.5)
- window?.addSubview(coverBtn)
-
- let p = btn.convert(btn.frame.origin, to: coverBtn)
- let schoolTableView = UITableView.init(frame: CGRect.init(x: 0, y: p.y + 30, width: 170, height: 120))
- if btn.tag == 1{
- schoolTableView.frame.origin.x = 10
- }
- if btn.tag == 2{
- schoolTableView.frame.origin.x = KSCREENWIDTH - 180
- }
- schoolTableView.delegate = self
- schoolTableView.dataSource = self
- // schoolTableView.backgroundColor = .red
- coverBtn.addSubview(schoolTableView)
- self.coverBtn = coverBtn
-
-
- schoolTableView.reloadData()
-
- }
-
- @objc private func hideChooseFloorCover(btn : UIButton){
- btn.removeFromSuperview()
- isFloor = false
- isRoom = false
- }
-
- func cinfigSegmentdView() {
- totalItemWidth = UIScreen.main.bounds.size.width - 20*2
- backgroundColor = .white
-
- // let titles = [ "Lights","Circadian Lights","Sensor","Air Purifiers"]
- let titleDataSource = JXSegmentedTitleDataSource()
- if self.isSchool == true{
- //学校
- titleDataSource.itemContentWidth = totalItemWidth/CGFloat(schoolTitles.count)
- titleDataSource.titles = schoolTitles
- }else{
- titleDataSource.itemContentWidth = totalItemWidth/CGFloat(titles.count)
- titleDataSource.titles = titles
- }
-
- titleDataSource.titleNormalFont = UIFont(name: Alibaba_PuHuiTi_Regular, size: 13)!
- titleDataSource.titleSelectedFont = UIFont(name: Alibaba_PuHuiTi_Bold, size: 13)!
- titleDataSource.isTitleMaskEnabled = true
- titleDataSource.titleNormalColor = UIColor(hexString: "#657085")!
- titleDataSource.titleSelectedColor = UIColor(hexString: "#FFFFFF")!
- titleDataSource.itemSpacing = 0
- titleDataSource.itemContentWidth = 120
- //titleDataSource.isItemSpacingAverageEnabled = false
- segmentedDataSource = titleDataSource
- segmentedView.dataSource = segmentedDataSource
- segmentedView.layer.masksToBounds = true
- segmentedView.layer.cornerRadius = 15
- segmentedView.backgroundColor = UIColor(hexString: "#F6F8F7")
- segmentedView.delegate = self
- addSubview(segmentedView)
- let indicator = JXSegmentedIndicatorBackgroundView()
- indicator.indicatorHeight = 25
- indicator.backgroundWidthIncrement = -10
- indicator.indicatorColor = UIColor(hexString: "#573F95")!
- indicator.layer.shadowColor = UIColor(hexString: "#573F95")!.cgColor
- indicator.layer.shadowRadius = 3
- indicator.layer.shadowOffset = CGSize.zero
- indicator.layer.shadowOpacity = 0.7
- segmentedView.indicators = [indicator]
- }
-
- }
- extension IHEquipmentlistView:JXSegmentedViewDelegate{
- func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
-
- delegate?.equipmentlistViewdidSelectedItemAt(index, floorId: self.currentFloorId, roomId: self.currentRoomId)
-
- self.currentIndex = index
- if let dotDataSource = segmentedDataSource as? JXSegmentedDotDataSource {
- //先更新数据源的数据
- dotDataSource.dotStates[index] = false
- //再调用reloadItem(at: index)
- segmentedView.reloadItem(at: index)
- }
-
- }
- }
- extension IHEquipmentlistView:UITableViewDelegate,UITableViewDataSource{
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if isFloor == true {
- let floorListCount = self.floorList?.count ?? 0
- return floorListCount
- }else if isRoom == true {
- let roomListCount = self.classRoomList?.count ?? 0
- return roomListCount
- }else if currentIndex == 0 {
- let devCount = self.devDataList?.count ?? 0
- let gatewayListCount = self.gatewayList?.count ?? 0
- let totalCount = devCount + gatewayListCount
- return totalCount
- }else if currentIndex == 5{
- let gatewayListCount = self.gatewayList?.count ?? 0
- return gatewayListCount
- }else{
- return self.devDataList?.count ?? 0
- }
-
-
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- //return 135
-
- if isRoom == true || isFloor == true {
- return 40
- }else {
- return 135
- }
- }
- //iOS 11 将进入此方法 actions.performsFirstActionWithFullSwipe = NO 可以控制是否自动删除。
- func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
-
- // if isRoom != true || isFloor != true {
- // return nil
- // }
-
-
- log.debug("左滑")
- #warning("快速移动的时候,如不加此方法,就有可能不执行layoutsubviews")
- self.tableView(self.tableView, willBeginEditingRowAt: indexPath)
-
- let deleteAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
- completionHandler(true)
- log.debug("删除")
-
-
- if self.currentIndex == 0{
- if let devDataList = self.devDataList {
- if indexPath.row < devDataList.count {
- if let delegate = self.delegate{
- let devData = self.devDataList![indexPath.row]
- delegate.equipmentListDeleteDevice(devData.devType!, devId: devData.id!, segmentIndex: self.currentIndex ?? 0)
- }
- }else{
- if let delegate = self.delegate {
- // delegate.gatewayUpdate(segmentIndex: self.currentIndex ?? 5)
- let gateway = self.gatewayList![indexPath.row - devDataList.count ]
- delegate.gatewayDelegate(gateway, segmentIndex: self.currentIndex ?? 0)
- }
- }
- }
- }else if self.currentIndex == 5{
- if let delegate = self.delegate {
- let gateway = self.gatewayList![indexPath.row ]
- delegate.gatewayDelegate(gateway, segmentIndex: self.currentIndex ?? 5)
- }
- }else{
- if let delegate = self.delegate{
- let devData = self.devDataList![indexPath.row]
- delegate.equipmentListDeleteDevice(devData.devType!, devId: devData.id!, segmentIndex: self.currentIndex ?? 0)
- }
- }
-
- //处理事件
- }
- deleteAction.backgroundColor = UIColor(hexString: "#EBEFF2")
-
- let historyAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
- completionHandler(true)
- //处理事件0
- log.debug("历史数据")
- if self.currentIndex == 0{
- if let devDataList = self.devDataList {
- if indexPath.row < devDataList.count {
- if let delegate = self.delegate{
- let data = self.devDataList![indexPath.row]
- delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
- }
- }else{
- if let delegate = self.delegate {
- let data = self.gatewayList![indexPath.row - devDataList.count ]
- delegate.gatewayUpdate(data, segmentIndex: self.currentIndex ?? 0)
- }
- }
- }
- }else if self.currentIndex == 5{
- if let delegate = self.delegate {
- let data = self.gatewayList![indexPath.row]
- delegate.gatewayUpdate(data, segmentIndex: self.currentIndex ?? 5)
- }
- }else{
- if let delegate = self.delegate{
- let data = self.devDataList![indexPath.row]
- delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
- }
- }
-
- }
- //#31D4C1 #0A82CF
- historyAction.backgroundColor = UIColor(hexString: "#31D4C1")
- let settingAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
- completionHandler(true)
- if self.currentIndex == 0{
- if let devDataList = self.devDataList {
- if indexPath.row < devDataList.count {
- if let delegate = self.delegate{
- let data = self.devDataList![indexPath.row]
- delegate.equipmentSetting(data, segmentIndex: self.currentIndex ?? 0)
- }
- }else{
- if let delegate = self.delegate{
- let data = self.gatewayList![indexPath.row - devDataList.count ]
- delegate.gatewaySetting(data, segmentIndex: self.currentIndex ?? 5)
- }
- }
- }
- }else if self.currentIndex == 5{
- if let delegate = self.delegate {
- let data = self.gatewayList![indexPath.row ]
- delegate.gatewaySetting(data, segmentIndex: self.currentIndex ?? 5)
- }
- }else{
- log.debug("设置")
- if let delegate = self.delegate{
- let data = self.devDataList![indexPath.row]
- delegate.equipmentSetting(data, segmentIndex: self.currentIndex ?? 0)
- }
-
- }
- //处理事件
-
- }
- //#05CFAB
- settingAction.backgroundColor = UIColor(hexString: "#573F95")
-
- let actions = UISwipeActionsConfiguration(actions: [settingAction,historyAction,deleteAction])
- actions.performsFirstActionWithFullSwipe = false
- return actions
-
- }
-
-
- func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
- if isRoom == true || isFloor == true {
- return false
- }else{
- return true
- }
- //return true
- }
- func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
- editingIndexPath = indexPath
- log.debug("移动移动")
- setNeedsLayout() // 触发layoutSubviews()
-
- }
- //取消选中
- func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
- editingIndexPath = nil
- // log.debug("didEndEditingRowAt")
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
- if isFloor == true || isRoom == true {
- let schoolCell = "schoolCell"
- var cell = tableView.dequeueReusableCell(withIdentifier: schoolCell)
- if cell == nil{
- cell = UITableViewCell.init(style: .default, reuseIdentifier: schoolCell)
- }
- var lists = [String]()
- if isFloor == true {
- lists = self.floorList!
- }else{
- lists = self.classRoomList!
- }
- cell?.textLabel?.text = lists[indexPath.row]
- cell?.textLabel?.font = UIFont.systemFont(ofSize: 14.0)
- cell?.textLabel?.textAlignment = .center
- return cell!
-
- }else{
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHEquipmentListCell
- cell.selectionStyle = .none
- if currentIndex == 0 {
- if let devDataList = self.devDataList {
- if indexPath.row < devDataList.count {
- cell.devData = devDataList[indexPath.row]
- }else{//0 1 2 3 4 5
- // 3 - 3 = 0
- cell.gateway = self.gatewayList?[ indexPath.row - devDataList.count ]
- }
-
- }
- }else if currentIndex == 5 {
- //网关
- cell.gateway = self.gatewayList?[indexPath.row]
- }else {
- //每个按钮
- cell.devData = devDataList![indexPath.row]
- }
- return cell
- }
-
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-
-
- if isFloor == true || isRoom == true{
- if isFloor == true {
- //加载楼层的所有房间
- let floorData = self.areaFloorList![indexPath.row]
- if floorData.id != currentFloorId{
- roomBtn?.setTitle("所有", for: .normal)
- }
- currentFloorId = floorData.id
- //delegate?.selectFloorRoom(floorId: floorData.id!)
- delegate?.selectFloorRoom(self.currentIndex!,floorId: currentFloorId, roomId: nil)
- currentRoomId = nil
- floorBtn?.setTitle(floorData.name, for: .normal)
- }
- if isRoom == true {
- //加载房间
- let roomData = self.floorRoomList![indexPath.row]
- currentRoomId = roomData.id
- delegate?.selectFloorRoom(self.currentIndex!,floorId: currentFloorId, roomId: currentRoomId)
- roomBtn?.setTitle(roomData.number, for: .normal)
- }
- self.coverBtn?.removeFromSuperview()
- }else if currentIndex == 0 {
- if let devDataList = self.devDataList {
- if indexPath.row < devDataList.count {
- if let delegate = self.delegate {
- let device = self.devDataList![indexPath.row]
- delegate.equipmentListSelected(device)
- }
- }else{
- if let delegate = self.delegate {
- let gateway = self.gatewayList![indexPath.row - devDataList.count]
- delegate.equipmentListSelected(gateway)
- }
- }
- }
- }else if currentIndex == 5 {
- if let delegate = self.delegate {
- let gateway = self.gatewayList![indexPath.row]
- delegate.equipmentListSelected(gateway)
- }
- }else {
- if let delegate = self.delegate {
- let device = self.devDataList![indexPath.row]
- delegate.equipmentListSelected(device)
- }
- }
- }
- func configSwipeButtons() {
- // log.debug("重新绘制 ")
- //iOS 11 层级 UITableView -> UISwipActionPull
- var swipeButtons : [UIView]?
- if #available(iOS 11, *) {
- swipeButtons = self.tableView.getSwipeButtonView()
- }else{
- // iOS 8-10: 画UITableView->UITableViewCell->UITableVIewCellDeleteConfirmationView
- let tabCell = self.tableView.cellForRow(at: self.editingIndexPath!)
- swipeButtons = tabCell?.getSwipeButtonView()
- }
- // log.debug("子控件 -- \(swipeButtons)")
- if swipeButtons?.count == 0 || swipeButtons == nil {
- return
- }
- for i in 0..<(swipeButtons?.count)!{
- let button = swipeButtons![i] as! UIButton
- if i == 0 {
- //ic_delete_bg
- configSwipeButton(button, backgroundImage: UIImage(named: "删除")!)
- }else if i == 1{
- if currentIndex == 0 {
- if let devDataList = self.devDataList {
- if self.editingIndexPath!.row < devDataList.count {
- //ic_hitory_bg
- configSwipeButton(button, backgroundImage: UIImage(named: "历史")!)
- }else{
- configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
- }
- }
- }else if currentIndex == 5{
- configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
- }else {
- //ic_hitory_bg
- configSwipeButton(button, backgroundImage: UIImage(named: "历史")!)
- }
-
- }else{
- //ic_setting_bg
- configSwipeButton(button, backgroundImage: UIImage(named: "设置-紫")!)
- }
- }
- }
-
- func configSwipeButton(_ button: UIButton,backgroundImage:UIImage) {
- button.layer.cornerRadius = 5
- button.layer.masksToBounds = true
- button.setBackgroundImage(backgroundImage, for: .normal)
- button.setBackgroundImage(backgroundImage, for: .selected)
- button.titleLabel?.font = UIFont(name: PingFangSC_Medium, size: 11)
-
- let frame = button.frame
- button.frame = CGRect(x: frame.origin.x + 5 , y: frame.origin.y + 10, width: frame.size.width - 10, height: frame.size.height - 20)
- log.debug("frame\(button.frame)")
- }
- }
|