123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- //
- // IHServiceRepairView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/19.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- protocol IHServiceRepairViewDelegate : NSObjectProtocol {
- //维修保存
- func saveRepair(alarmId : String,repairId : String)
- }
- class IHServiceRepairView: UIView {
- var alarmInfo : AlarmData?{
- didSet{
- if let alarm = self.alarmInfo{
- 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{
- var tempDatas = [String]()
- tempDatas.append(floor)
- tempDatas.append(room)
- tempDatas.append(deviceName)
- tempDatas.append(deviceId)
- tempDatas.append(content)
- tempDatas.append("")
- self.dataSource = tempDatas
- self.tableView.reloadData()
- }
- }
- }
- }
- //保存选择的信息
- var repairMan :RepairMan?{
- didSet{
- if let man = self.repairMan {
- if let number = man.number,let name = man.name {
- //self.dataSource![5] = "\(number)-\(name)"
- //self.tableView.reloadRows(at: [IndexPath(row: 5, section: 0)], with: .fade)
- self.dataSource![5] = "\(name)"
- self.tableView.reloadRows(at: [IndexPath.init(row: 5, section: 0)], with: .automatic)
- }
- }
-
- }
- }
- //第一个维修人员
- var repairmanList:[RepairMan]?{
- didSet{
- let firstMan = self.repairmanList?.first
- self.repairMan = firstMan
- }
- }
- var dataSource:[String]?{
- didSet{
-
- }
- }
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: .grouped)
- tableView.delegate = self
- tableView.dataSource = self
- tableView.backgroundColor = .white
- tableView.separatorStyle = .none
- tableView.register(UINib(nibName: "IHTwoRowCell", bundle: nil), forCellReuseIdentifier:"rowcell")
- tableView.register(UINib(nibName: "IHSelectedCell", bundle: nil), forCellReuseIdentifier: "selectedCell")
- return tableView
- }()
- lazy var preserveBtn: UIButton = {
- let btn = UIButton(type: .custom)
- btn.setTitle("保存", for: .normal)
- btn.setTitleColor(UIColor(hexString: "#FFFFFF"), for: .normal)
- btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 14)
- btn.backgroundColor = UIColor(hexString: "#573F95")
- btn.layer.cornerRadius = 5
- btn.layer.masksToBounds = true
- return btn
- }()
-
- weak var delegate : IHServiceRepairViewDelegate?
- override init(frame: CGRect) {
- super.init(frame: frame)
- addSubview(tableView)
- addSubview(preserveBtn)
- preserveBtn.addTarget(self, action: #selector(saveRepairBtn), for: .touchUpInside)
- }
-
- 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: self.bounds.size.height - 64)
- preserveBtn.frame = CGRect(x: 20, y: self.bounds.size.height - 64, width: self.bounds.size.width - 40, height: 40)
-
- }
-
- //维修保存
- @objc private func saveRepairBtn(){
-
- let repairmanName = self.dataSource![5]
- // if repairmanName
- var repairmanId : String?
- for item in repairmanList! {
- if item.name == repairmanName {
- repairmanId = item.id
- }
- }
- log.debug("维修保存")
- delegate?.saveRepair(alarmId : (alarmInfo?.id)!,repairId : repairmanId!)
- }
- }
- extension IHServiceRepairView: UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.dataSource?.count ?? 0
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 70
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 150
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.1
- }
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let headerView = IHServiceHeaderView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: 150))
- return headerView
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if indexPath.row == 5 {
- let cell = tableView.dequeueReusableCell(withIdentifier: "selectedCell") as! IHSelectedCell
- cell.mTitle = "维修人"
- cell.isEdit = false
- cell.mValue = self.dataSource![indexPath.row]
- cell.selectionStyle = .none
- return cell
- }else{
- let cell = tableView.dequeueReusableCell(withIdentifier: "rowcell") as! IHTwoRowCell
- if indexPath.row == 0 {
- cell.mTitle = "楼层"
- // cell.mValue = "8393742"
- }else if indexPath.row == 1 {
- cell.mTitle = "房间"
- // cell.mValue = "8393742"
- } else if indexPath.row == 2 {
- cell.mTitle = "设备名称"
- // cell.mValue = "8393742"
- }else if indexPath.row == 3{
- cell.mTitle = "ID"
- // cell.mValue = "8393742"
- }else if indexPath.row == 4{
- cell.mTitle = "失败原因"
- // cell.mValue = "2 light buib is damaged"
- }
- cell.mValue = self.dataSource![indexPath.row]
- cell.isChangeColor = false
- cell.selectionStyle = .none
- return cell
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row == 5{
- // g_showHUD("该功能在开发中...")
-
- if repairmanList == nil {
- g_showHUD("无数据")
- return
-
- }
- var titleArr = [String]()
- for repairman in self.repairmanList! {
- if let number = repairman.number,let name = repairman.name {
- //let title = "\(number)-\(name)"
- let title = "\(name)"
- titleArr.append(title)
- }
- }
- let pick = THScrollChooseView(question: titleArr, withDefaultDesc: titleArr.first)
- pick?.confirmBlock = {(selectedIndex) in
- log.debug(" title = \(titleArr[selectedIndex] )")
- self.repairMan = self.repairmanList![selectedIndex]
- }
- pick?.show()
- }
- }
- }
|