123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // IHAssociateGatewayView.swift
- // Inhealth
- //
- // Created by weclouds on 2020/8/25.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import PKHUD
- protocol IHAssociateGatewayViewDelete : NSObjectProtocol {
- // func emptyViewSearchDataSegment(_ index:Int)
- // func deviceConnectGateway(_ deviceId:String)
- // func deviceDisconteGateway(_ deviceId:String)
- // func controlightOn(_ isTurnON:Bool,lampId:String)
-
- //添加设备
- func deviceConnectGateway(_ deviceUUId:String)
- //删除设备
- func deviceDisconteGateway(_ deviceAddress:String)
- //搜索相应设备
- func emptyViewSearchDataSegment(_ index:Int)
- //开关灯(有485/cw)
- func controlightOn(_ isTurnON : Bool ,_ device :(address : String ,type : String))
-
- }
- class IHAssociateGatewayView: UIView {
- weak var delegate:IHAssociateGatewayViewDelete?
-
- var currentIndex:Int = 0
-
- // var associatedList:[GatewayLamp]?{
- // didSet{
- // if let associatedList = self.associatedList{
- // if(associatedList.count > 0){
- // tableView.ly_emptyView?.isHidden = true
- // self.tableView.reloadData()
- // }
- // }
- // }
- // }
- //
- // var notAssociatedList:[GatewayLamp]?{
- // didSet{
- // if let notAssociatedList = self.notAssociatedList{
- // if(notAssociatedList.count > 0){
- // tableView.ly_emptyView?.isHidden = true
- // self.tableView.reloadData()
- // }
- // }
- //
- // }
- // }
-
- var associatedDeviceList : [(address : String ,type : String)]?{
- didSet{
- if let associatedDeviceList = associatedDeviceList{
- if(associatedDeviceList.count > 0){
- tableView.ly_emptyView?.isHidden = true
- self.tableView.reloadData()
- }
- }
- }
- }
-
- var notAssociatedDeviceList : [String]?{
- didSet{
- if let notAssociatedDeviceList = notAssociatedDeviceList{
- if(notAssociatedDeviceList.count > 0){
- tableView.ly_emptyView?.isHidden = true
- self.tableView.reloadData()
- }
- }
- }
- }
-
- var emptyView:IHEmptyGatewayView?
- 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: "IHAssociatedGatewayCell", bundle: nil), forCellReuseIdentifier: "associated")
- tableView.register(UINib(nibName: "IHNotAssociatedGatewayCell", bundle: nil), forCellReuseIdentifier: "notassociated")
- return tableView
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- // tableView.frame = self.bounds
- if KNavBarHeight == 64 {
- tableView.frame = CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: self.frame.size.height - 230)
- }else{
- tableView.frame = self.bounds
- }
-
- emptyView?.frame = self.bounds
- }
-
- func createUI() {
- addSubview(tableView)
- emptyView = Bundle.main.loadNibNamed("IHEmptyGatewayView", owner: nil, options: nil)?.last as? IHEmptyGatewayView
- emptyView?.searchCallback = {[unowned self] in
- //搜索事件
- HUD.flash(.progress)
- if let delegate = self.delegate {
- delegate.emptyViewSearchDataSegment(self.currentIndex)
- }
- }
- // 空数据展示界面
- let emptyV :HDEmptyView = HDEmptyView.emptyViewWithCustomView(customView: emptyView!) as! HDEmptyView
- tableView.ly_emptyView = emptyV
- tableView.ly_showEmptyView()
-
- }
- }
- extension IHAssociateGatewayView :JXSegmentedListContainerViewListDelegate{
- func listView() -> UIView {
- return self
- }
-
- }
- extension IHAssociateGatewayView:UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if currentIndex == 0 {
- return self.associatedDeviceList?.count ?? 0
- }else{
- return self.notAssociatedDeviceList?.count ?? 0
- }
-
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 99
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if currentIndex == 0 {
- let cell = tableView.dequeueReusableCell(withIdentifier: "associated") as! IHAssociatedGatewayCell
- let gateDevice = self.associatedDeviceList![indexPath.row]
- cell.gateDevice = gateDevice
- cell.selectionStyle = .none
- cell.disconnectCallback = {[unowned self] in
- HUD.flash(.progress)
- self.delegate?.deviceDisconteGateway(gateDevice.address)
-
- }
- cell.turnonCallback = {[unowned self](isTurnOn) in
- if gateDevice.type != "40" && gateDevice.type != "12" {
- HUD.flash(.progress)
- self.delegate?.controlightOn(isTurnOn,gateDevice)
- }
-
-
- // if let delegate = self.delegate {
- // delegate.controlightOn(isTurnOn, lampId: gateDevice.id!)
- // }
- }
- return cell
- }else{
- let cell = tableView.dequeueReusableCell(withIdentifier: "notassociated") as! IHNotAssociatedGatewayCell
- cell.selectionStyle = .none
- let gateDevice = self.notAssociatedDeviceList![indexPath.row]
- cell.gateDevice = gateDevice
- cell.connectCallback = {[unowned self] in
- HUD.flash(.progress)
- self.delegate?.deviceConnectGateway(gateDevice)
-
- // if let delegate = self.delegate {
- // delegate.deviceConnectGateway(gateDevice.deviceId!)
- // }
- }
- return cell
- }
- }
-
-
-
- }
|