// // IHServiceDetailView.swift // Inhealth // // Created by weclouds on 2019/12/19. // Copyright © 2019 weclouds. All rights reserved. // import UIKit class IHServiceDetailView: UIView { var alarmDetail : AlarmDetail?{ didSet{ if let detail = self.alarmDetail { if let id = detail.id, let floor = detail.floor, let room = detail.room, let name = detail.name, let deviceId = detail.deviceId, let content = detail.content, let repairName = detail.repairName, let completion = detail.completion, let updatetime = detail.updatetime{ var details = [String]() details.append(floor) details.append(room) details.append(name) details.append(deviceId) details.append(content) details.append(repairName) details.append(updatetime) details.append(completion) self.values = details } } } } let titles = ["楼层","房间号","设备名称","设备 ID","失败原因","维修人","维修申请时间","维修完成时间"] var values :[String]?{ didSet{ self.tableView.reloadData() } } 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: "IHServiceNormalCell", bundle: nil), forCellReuseIdentifier: "normalCell") tableView.register(UINib(nibName: "IHTwoRowCell", bundle: nil), forCellReuseIdentifier: "rowCell") 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) //#05CFAB btn.backgroundColor = UIColor(hexString: "#573F95") btn.layer.cornerRadius = 5 btn.layer.masksToBounds = true return btn }() override init(frame: CGRect) { super.init(frame: frame) addSubview(tableView) // addSubview(preserveBtn) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() tableView.frame = self.bounds 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) } } extension IHServiceDetailView: UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return values?.count ?? 0 } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath.row == 4 { return 70 }else{ return 50 } } 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 == 4 { let cell = tableView.dequeueReusableCell(withIdentifier: "rowCell") as! IHTwoRowCell cell.mTitle = titles[indexPath.row] cell.mValue = values![indexPath.row] cell.selectionStyle = .none return cell }else{ let cell = tableView.dequeueReusableCell(withIdentifier: "normalCell") as! IHServiceNormalCell cell.mTitle = titles[indexPath.row] cell.mValue = values![indexPath.row] cell.selectionStyle = .none return cell } } }