123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // IHServiceView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/19.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import ESPullToRefresh
- protocol IHServiceViewDelegate: NSObjectProtocol{
- func serviceViewSeeDetails(for indexPath: IndexPath)
-
- func serviceViewDeleteEquipment(for alarmId: String)
-
- func serviceViewRepairEquipment(for indexPath: IndexPath)
-
- func tableViewEsAddPullToRefresh()
- func tableViewEsAddInfiniteScrolling()
- }
- class IHServiceView: UIView {
- var alarmList :[AlarmData]? {
- didSet{
-
- self.tableView.reloadData()
- }
- }
- weak var delegate : IHServiceViewDelegate?
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: .plain)
- tableView.delegate = self
- tableView.dataSource = self
- tableView.backgroundColor = .white
- tableView.separatorStyle = .none
- tableView.register(UINib(nibName: "IHSeviceListCell", bundle: nil), forCellReuseIdentifier: "serviceCell")
- tableView.register(UINib(nibName: "IHMaintenaceCell", bundle: nil), forCellReuseIdentifier: "maintentceCell")
- tableView.register(UINib(nibName: "IHRepairedCell", bundle: nil), forCellReuseIdentifier: "repaireCell")
- return tableView
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- addSubview(tableView)
-
- //设置下滑刷新,上拉加载更多
- let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
- let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
-
- //下拉刷新
- tableView.es.addPullToRefresh(animator: header) {
- self.delegate?.tableViewEsAddPullToRefresh()
- }
-
- //上拉加载更多
- tableView.es.addInfiniteScrolling(animator: footer) {
- self.delegate?.tableViewEsAddInfiniteScrolling()
- }
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func endRefresh(){
- tableView.es.stopPullToRefresh()
- tableView.es.stopLoadingMore()
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- tableView.frame = self.bounds
- }
- }
- extension IHServiceView:UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return alarmList?.count ?? 0
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 150
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
- let alarm = alarmList?[indexPath.row]
-
- if alarm?.status == "0" {
-
- let cell = tableView.dequeueReusableCell(withIdentifier: "serviceCell") as! IHSeviceListCell
- cell.selectionStyle = .none
- cell.tableView = tableView
- cell.delegate = self
- cell.alarm = alarm
- return cell
- }else if alarm?.status == "1"{
- let cell = tableView.dequeueReusableCell(withIdentifier: "maintentceCell") as! IHMaintenaceCell
- cell.selectionStyle = .none
- cell.tableView = tableView
- cell.delegate = self
- cell.alarm = alarm
- return cell
- }else if alarm?.status == "2"{
- let cell = tableView.dequeueReusableCell(withIdentifier: "repaireCell") as! IHRepairedCell
- cell.selectionStyle = .none
- cell.tableView = tableView
- cell.delegate = self
- cell.alarm = alarm
- return cell
- }
-
- return UITableViewCell()
-
- }
-
-
- }
- extension IHServiceView : IHServiceCellDelegate{
- func seeDetails(for indexPath: IndexPath) {
- log.debug("seeDetails -\(indexPath.row)")
- if let delegate = self.delegate {
- delegate.serviceViewSeeDetails(for: indexPath)
- }
- }
-
- func deleteEquipment(for indexPath: IndexPath) {
- log.debug("deleteEquipment -\(indexPath.row)")
- let alarm = self.alarmList![indexPath.row]
- if let delegate = self.delegate {
- delegate.serviceViewDeleteEquipment(for: alarm.id!)
- }
- }
-
-
- func repairEquipment(for indexPath: IndexPath) {
- log.debug("deleteEquipment -\(indexPath.row)")
- if let delegate = self.delegate {
- delegate.serviceViewRepairEquipment(for: indexPath)
- }
- }
-
- }
|