IHServiceRepairView.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // IHServiceRepairView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/19.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. protocol IHServiceRepairViewDelegate : NSObjectProtocol {
  10. //维修保存
  11. func saveRepair(alarmId : String,repairId : String)
  12. }
  13. class IHServiceRepairView: UIView {
  14. var alarmInfo : AlarmData?{
  15. didSet{
  16. if let alarm = self.alarmInfo{
  17. if let alarmid = alarm.id ,let floor = alarm.floor, let room = alarm.roomNumber,let deviceName = alarm.name,let deviceId = alarm.deviceId,let content = alarm.content{
  18. var tempDatas = [String]()
  19. tempDatas.append(floor)
  20. tempDatas.append(room)
  21. tempDatas.append(deviceName)
  22. tempDatas.append(deviceId)
  23. tempDatas.append(content)
  24. tempDatas.append("")
  25. self.dataSource = tempDatas
  26. self.tableView.reloadData()
  27. }
  28. }
  29. }
  30. }
  31. //保存选择的信息
  32. var repairMan :RepairMan?{
  33. didSet{
  34. if let man = self.repairMan {
  35. if let number = man.number,let name = man.name {
  36. //self.dataSource![5] = "\(number)-\(name)"
  37. //self.tableView.reloadRows(at: [IndexPath(row: 5, section: 0)], with: .fade)
  38. self.dataSource![5] = "\(name)"
  39. self.tableView.reloadRows(at: [IndexPath.init(row: 5, section: 0)], with: .automatic)
  40. }
  41. }
  42. }
  43. }
  44. //第一个维修人员
  45. var repairmanList:[RepairMan]?{
  46. didSet{
  47. let firstMan = self.repairmanList?.first
  48. self.repairMan = firstMan
  49. }
  50. }
  51. var dataSource:[String]?{
  52. didSet{
  53. }
  54. }
  55. lazy var tableView: UITableView = {
  56. let tableView = UITableView(frame: CGRect.zero, style: .grouped)
  57. tableView.delegate = self
  58. tableView.dataSource = self
  59. tableView.backgroundColor = .white
  60. tableView.separatorStyle = .none
  61. tableView.register(UINib(nibName: "IHTwoRowCell", bundle: nil), forCellReuseIdentifier:"rowcell")
  62. tableView.register(UINib(nibName: "IHSelectedCell", bundle: nil), forCellReuseIdentifier: "selectedCell")
  63. return tableView
  64. }()
  65. lazy var preserveBtn: UIButton = {
  66. let btn = UIButton(type: .custom)
  67. btn.setTitle("保存", for: .normal)
  68. btn.setTitleColor(UIColor(hexString: "#FFFFFF"), for: .normal)
  69. btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 14)
  70. btn.backgroundColor = UIColor(hexString: "#573F95")
  71. btn.layer.cornerRadius = 5
  72. btn.layer.masksToBounds = true
  73. return btn
  74. }()
  75. weak var delegate : IHServiceRepairViewDelegate?
  76. override init(frame: CGRect) {
  77. super.init(frame: frame)
  78. addSubview(tableView)
  79. addSubview(preserveBtn)
  80. preserveBtn.addTarget(self, action: #selector(saveRepairBtn), for: .touchUpInside)
  81. }
  82. required init?(coder: NSCoder) {
  83. fatalError("init(coder:) has not been implemented")
  84. }
  85. override func layoutSubviews() {
  86. super.layoutSubviews()
  87. tableView.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height - 64)
  88. preserveBtn.frame = CGRect(x: 20, y: self.bounds.size.height - 64, width: self.bounds.size.width - 40, height: 40)
  89. }
  90. //维修保存
  91. @objc private func saveRepairBtn(){
  92. let repairmanName = self.dataSource![5]
  93. // if repairmanName
  94. var repairmanId : String?
  95. for item in repairmanList! {
  96. if item.name == repairmanName {
  97. repairmanId = item.id
  98. }
  99. }
  100. log.debug("维修保存")
  101. delegate?.saveRepair(alarmId : (alarmInfo?.id)!,repairId : repairmanId!)
  102. }
  103. }
  104. extension IHServiceRepairView: UITableViewDelegate,UITableViewDataSource{
  105. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  106. return self.dataSource?.count ?? 0
  107. }
  108. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  109. return 70
  110. }
  111. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  112. return 150
  113. }
  114. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  115. return 0.1
  116. }
  117. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  118. let headerView = IHServiceHeaderView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: 150))
  119. return headerView
  120. }
  121. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  122. if indexPath.row == 5 {
  123. let cell = tableView.dequeueReusableCell(withIdentifier: "selectedCell") as! IHSelectedCell
  124. cell.mTitle = "维修人"
  125. cell.isEdit = false
  126. cell.mValue = self.dataSource![indexPath.row]
  127. cell.selectionStyle = .none
  128. return cell
  129. }else{
  130. let cell = tableView.dequeueReusableCell(withIdentifier: "rowcell") as! IHTwoRowCell
  131. if indexPath.row == 0 {
  132. cell.mTitle = "楼层"
  133. // cell.mValue = "8393742"
  134. }else if indexPath.row == 1 {
  135. cell.mTitle = "房间"
  136. // cell.mValue = "8393742"
  137. } else if indexPath.row == 2 {
  138. cell.mTitle = "设备名称"
  139. // cell.mValue = "8393742"
  140. }else if indexPath.row == 3{
  141. cell.mTitle = "ID"
  142. // cell.mValue = "8393742"
  143. }else if indexPath.row == 4{
  144. cell.mTitle = "失败原因"
  145. // cell.mValue = "2 light buib is damaged"
  146. }
  147. cell.mValue = self.dataSource![indexPath.row]
  148. cell.isChangeColor = false
  149. cell.selectionStyle = .none
  150. return cell
  151. }
  152. }
  153. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  154. if indexPath.row == 5{
  155. // g_showHUD("该功能在开发中...")
  156. if repairmanList == nil {
  157. g_showHUD("无数据")
  158. return
  159. }
  160. var titleArr = [String]()
  161. for repairman in self.repairmanList! {
  162. if let number = repairman.number,let name = repairman.name {
  163. //let title = "\(number)-\(name)"
  164. let title = "\(name)"
  165. titleArr.append(title)
  166. }
  167. }
  168. let pick = THScrollChooseView(question: titleArr, withDefaultDesc: titleArr.first)
  169. pick?.confirmBlock = {(selectedIndex) in
  170. log.debug(" title = \(titleArr[selectedIndex] )")
  171. self.repairMan = self.repairmanList![selectedIndex]
  172. }
  173. pick?.show()
  174. }
  175. }
  176. }