IHServiceView.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // IHServiceView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/19.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import ESPullToRefresh
  10. protocol IHServiceViewDelegate: NSObjectProtocol{
  11. func serviceViewSeeDetails(for indexPath: IndexPath)
  12. func serviceViewDeleteEquipment(for alarmId: String)
  13. func serviceViewRepairEquipment(for indexPath: IndexPath)
  14. func tableViewEsAddPullToRefresh()
  15. func tableViewEsAddInfiniteScrolling()
  16. }
  17. class IHServiceView: UIView {
  18. var alarmList :[AlarmData]? {
  19. didSet{
  20. self.tableView.reloadData()
  21. }
  22. }
  23. weak var delegate : IHServiceViewDelegate?
  24. lazy var tableView: UITableView = {
  25. let tableView = UITableView(frame: CGRect.zero, style: .plain)
  26. tableView.delegate = self
  27. tableView.dataSource = self
  28. tableView.backgroundColor = .white
  29. tableView.separatorStyle = .none
  30. tableView.register(UINib(nibName: "IHSeviceListCell", bundle: nil), forCellReuseIdentifier: "serviceCell")
  31. tableView.register(UINib(nibName: "IHMaintenaceCell", bundle: nil), forCellReuseIdentifier: "maintentceCell")
  32. tableView.register(UINib(nibName: "IHRepairedCell", bundle: nil), forCellReuseIdentifier: "repaireCell")
  33. return tableView
  34. }()
  35. override init(frame: CGRect) {
  36. super.init(frame: frame)
  37. addSubview(tableView)
  38. //设置下滑刷新,上拉加载更多
  39. let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
  40. let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
  41. //下拉刷新
  42. tableView.es.addPullToRefresh(animator: header) {
  43. self.delegate?.tableViewEsAddPullToRefresh()
  44. }
  45. //上拉加载更多
  46. tableView.es.addInfiniteScrolling(animator: footer) {
  47. self.delegate?.tableViewEsAddInfiniteScrolling()
  48. }
  49. }
  50. required init?(coder: NSCoder) {
  51. fatalError("init(coder:) has not been implemented")
  52. }
  53. func endRefresh(){
  54. tableView.es.stopPullToRefresh()
  55. tableView.es.stopLoadingMore()
  56. }
  57. override func layoutSubviews() {
  58. super.layoutSubviews()
  59. tableView.frame = self.bounds
  60. }
  61. }
  62. extension IHServiceView:UITableViewDelegate,UITableViewDataSource{
  63. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  64. return alarmList?.count ?? 0
  65. }
  66. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  67. return 150
  68. }
  69. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  70. let alarm = alarmList?[indexPath.row]
  71. if alarm?.status == "0" {
  72. let cell = tableView.dequeueReusableCell(withIdentifier: "serviceCell") as! IHSeviceListCell
  73. cell.selectionStyle = .none
  74. cell.tableView = tableView
  75. cell.delegate = self
  76. cell.alarm = alarm
  77. return cell
  78. }else if alarm?.status == "1"{
  79. let cell = tableView.dequeueReusableCell(withIdentifier: "maintentceCell") as! IHMaintenaceCell
  80. cell.selectionStyle = .none
  81. cell.tableView = tableView
  82. cell.delegate = self
  83. cell.alarm = alarm
  84. return cell
  85. }else if alarm?.status == "2"{
  86. let cell = tableView.dequeueReusableCell(withIdentifier: "repaireCell") as! IHRepairedCell
  87. cell.selectionStyle = .none
  88. cell.tableView = tableView
  89. cell.delegate = self
  90. cell.alarm = alarm
  91. return cell
  92. }
  93. return UITableViewCell()
  94. }
  95. }
  96. extension IHServiceView : IHServiceCellDelegate{
  97. func seeDetails(for indexPath: IndexPath) {
  98. log.debug("seeDetails -\(indexPath.row)")
  99. if let delegate = self.delegate {
  100. delegate.serviceViewSeeDetails(for: indexPath)
  101. }
  102. }
  103. func deleteEquipment(for indexPath: IndexPath) {
  104. log.debug("deleteEquipment -\(indexPath.row)")
  105. let alarm = self.alarmList![indexPath.row]
  106. if let delegate = self.delegate {
  107. delegate.serviceViewDeleteEquipment(for: alarm.id!)
  108. }
  109. }
  110. func repairEquipment(for indexPath: IndexPath) {
  111. log.debug("deleteEquipment -\(indexPath.row)")
  112. if let delegate = self.delegate {
  113. delegate.serviceViewRepairEquipment(for: indexPath)
  114. }
  115. }
  116. }