IHServiceDetailView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // IHServiceDetailView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/19.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class IHServiceDetailView: UIView {
  10. var alarmDetail : AlarmDetail?{
  11. didSet{
  12. if let detail = self.alarmDetail {
  13. if let id = detail.id,
  14. let floor = detail.floor,
  15. let room = detail.room,
  16. let name = detail.name,
  17. let deviceId = detail.deviceId,
  18. let content = detail.content,
  19. let repairName = detail.repairName,
  20. let completion = detail.completion,
  21. let updatetime = detail.updatetime{
  22. var details = [String]()
  23. details.append(floor)
  24. details.append(room)
  25. details.append(name)
  26. details.append(deviceId)
  27. details.append(content)
  28. details.append(repairName)
  29. details.append(updatetime)
  30. details.append(completion)
  31. self.values = details
  32. }
  33. }
  34. }
  35. }
  36. let titles = ["楼层","房间号","设备名称","设备 ID","失败原因","维修人","维修申请时间","维修完成时间"]
  37. var values :[String]?{
  38. didSet{
  39. self.tableView.reloadData()
  40. }
  41. }
  42. lazy var tableView: UITableView = {
  43. let tableView = UITableView(frame: CGRect.zero, style: .grouped)
  44. tableView.delegate = self
  45. tableView.dataSource = self
  46. tableView.backgroundColor = .white
  47. tableView.separatorStyle = .none
  48. tableView.register(UINib(nibName: "IHServiceNormalCell", bundle: nil), forCellReuseIdentifier: "normalCell")
  49. tableView.register(UINib(nibName: "IHTwoRowCell", bundle: nil), forCellReuseIdentifier: "rowCell")
  50. return tableView
  51. }()
  52. lazy var preserveBtn: UIButton = {
  53. let btn = UIButton(type: .custom)
  54. btn.setTitle("保存", for: .normal)
  55. btn.setTitleColor(UIColor(hexString: "#FFFFFF"), for: .normal)
  56. btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 14)
  57. //#05CFAB
  58. btn.backgroundColor = UIColor(hexString: "#573F95")
  59. btn.layer.cornerRadius = 5
  60. btn.layer.masksToBounds = true
  61. return btn
  62. }()
  63. override init(frame: CGRect) {
  64. super.init(frame: frame)
  65. addSubview(tableView)
  66. // addSubview(preserveBtn)
  67. }
  68. required init?(coder: NSCoder) {
  69. fatalError("init(coder:) has not been implemented")
  70. }
  71. override func layoutSubviews() {
  72. super.layoutSubviews()
  73. tableView.frame = self.bounds
  74. tableView.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height - 64)
  75. preserveBtn.frame = CGRect(x: 20, y: self.bounds.size.height - 64, width: self.bounds.size.width - 40, height: 40)
  76. }
  77. }
  78. extension IHServiceDetailView: UITableViewDelegate,UITableViewDataSource{
  79. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  80. return values?.count ?? 0
  81. }
  82. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  83. if indexPath.row == 4 {
  84. return 70
  85. }else{
  86. return 50
  87. }
  88. }
  89. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  90. return 150
  91. }
  92. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  93. return 0.1
  94. }
  95. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  96. let headerView = IHServiceHeaderView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: 150))
  97. return headerView
  98. }
  99. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  100. if indexPath.row == 4 {
  101. let cell = tableView.dequeueReusableCell(withIdentifier: "rowCell") as! IHTwoRowCell
  102. cell.mTitle = titles[indexPath.row]
  103. cell.mValue = values![indexPath.row]
  104. cell.selectionStyle = .none
  105. return cell
  106. }else{
  107. let cell = tableView.dequeueReusableCell(withIdentifier: "normalCell") as! IHServiceNormalCell
  108. cell.mTitle = titles[indexPath.row]
  109. cell.mValue = values![indexPath.row]
  110. cell.selectionStyle = .none
  111. return cell
  112. }
  113. }
  114. }