123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // IHEquipmentView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/11.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import JXPagingView
- let KNotifictionIHEquipmentViewGetHomeData = "KNotifictionIHEquipmentViewGetHomeData"
- struct EquipmentViewCellModel {
- var title:String?
- var icon:String?
- var value:String?
- var isAlert:Bool?
- }
- class IHEquipmentView: UIView ,UIScrollViewDelegate{
- var gateWayCallback:(()->Void)?//网关回调,进入网关列表
- fileprivate var tempDataSouce : [EquipmentViewCellModel]? = [EquipmentViewCellModel]()
- fileprivate var constants : [EquipmentViewCellModel]? = [EquipmentViewCellModel]()
- var dataSource:[String]?{
- didSet{
- relaodData()
- }
- }
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame:self.bounds, style: .plain)
- tableView.dataSource = self
- tableView.delegate = self
- return tableView
- }()
- var listViewDidScrollCallback: ((UIScrollView) -> ())?
- override init(frame: CGRect) {
- super.init(frame: frame)
- addSubview(tableView)
- self.backgroundColor = UIColor.white
- self.tableView.backgroundColor = UIColor.white
- tableView.separatorStyle = .none
- tableView.register(UINib(nibName: "IHEquipmentCell", bundle: nil), forCellReuseIdentifier: "cell")
- initConstantsData()
-
- NotificationCenter.default.addObserver(self, selector: #selector(notifyHomeData), name: NSNotification.Name(KNotifictionIHEquipmentViewGetHomeData), object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- @objc func notifyHomeData(_ notify:Notification) {
- let data = notify.object as! HomeData
- self.dataSource = [data.deviceCount!,data.netCount!,data.classroomLightCount!,data.blackboardLightCount!,data.panelDeviceCount!,data.curtainDeviceCount!,data.lightCount!,data.cicLightCount!,data.sensorCount!,data.airPurCount!,data.alarmCount!]
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
- override func layoutSubviews() {
- super.layoutSubviews()
- // tableView.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width, height: 60 * 11)
-
- tableView.frame = self.bounds
- self.tableView.reloadData()
- }
- //初始化常量
- func initConstantsData() {
- let model1 = EquipmentViewCellModel(title: "设备总数", icon: "所有设备", value: "", isAlert: false)
- let model2 = EquipmentViewCellModel(title: "故障数", icon: "告警", value: "", isAlert: true)
- let model3 = EquipmentViewCellModel(title: "普通灯数", icon: "Ordinary light", value: "", isAlert: false)
- let model4 = EquipmentViewCellModel(title: "HCL灯控数", icon: "Circadian light", value: "", isAlert: false)
- let model5 = EquipmentViewCellModel(title: "感应器数", icon: "Sensor", value: "", isAlert: false)
- let model6 = EquipmentViewCellModel(title: "空气净化器数", icon: "空气净化器-设备默认图", value: "", isAlert: false)
- let model7 = EquipmentViewCellModel(title: "网关数", icon: "网关", value: "1", isAlert: false)
-
- let model8 = EquipmentViewCellModel(title: "窗帘", icon: "窗帘", value: "", isAlert: false)
- let model9 = EquipmentViewCellModel(title: "面板", icon: "面板", value: "", isAlert: false)
- let model10 = EquipmentViewCellModel(title: "黑板灯", icon: "黑板灯", value: "", isAlert: false)
- let model11 = EquipmentViewCellModel(title: "教室灯", icon: "灯控", value: "", isAlert: false)
-
- constants?.append(model1)
- constants?.append(model7)
- constants?.append(model11)
- constants?.append(model10)
- constants?.append(model9)
- constants?.append(model8)
- // constants?.append(model7)
- constants?.append(model3)
- constants?.append(model4)
- constants?.append(model5)
- constants?.append(model6)
- constants?.append(model2)
-
- // constants?.append(model1)
- // constants?.append(model7)
- // constants?.append(model3)
- // constants?.append(model4)
- // constants?.append(model5)
- // constants?.append(model6)
- //
- // //FIX: 2020.2.17 yalerts移动到air purifiers 下面
- // constants?.append(model2)
-
- }
-
- func relaodData() {
- tempDataSouce?.removeAll()
- for i in 0..<(constants?.count)! {
- let constant = constants![i]
- let value = dataSource![i]
- let model = EquipmentViewCellModel(title: constant.title, icon: constant.icon, value: value, isAlert: constant.isAlert)
- tempDataSouce?.append(model)
- }
- self.tableView.reloadData()
- }
- }
- extension IHEquipmentView : UITableViewDataSource,UITableViewDelegate{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return tempDataSouce!.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHEquipmentCell
- cell.model = tempDataSouce![indexPath.row]
- cell.selectionStyle = .none
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 60
- }
- //防跳动
- func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
- return 60
- }
-
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- self.listViewDidScrollCallback?(scrollView)
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row == 1 {
- log.debug("didSelectRowAt")
- if let block = self.gateWayCallback {
- block()
- }
- }
- }
- }
- extension IHEquipmentView : JXPagingViewListViewDelegate{
- func listView() -> UIView {
- return self
- }
-
- func listScrollView() -> UIScrollView {
- self.tableView
- }
-
- func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
- self.listViewDidScrollCallback = callback
- }
-
- }
|