// // MeTraineeDetails01Controller.swift // JiaPeiManage // // Created by Ning.ge on 2023/6/20. // import UIKit import RxSwift import RxCocoa final class MeTraineeDetails01Controller: BaseTableViewController { let cellIdentifier:String = "_MeTraineeDetails01Cell" // MARK: 服务属性 private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking()) // MARK: UI属性 var groupList:[String : [String:String]] = [:] var groupColorList:[String:String] = [:] let keys = ["个人信息","培训信息"] let keyArray = [["证件类型","证件号码","推荐人","国籍","地区","县区","联系地址","培训车型","是否激活","备案时间","所属机构"], ["阶段一学时","阶段二学时", "阶段三学时", "阶段四学时", "科一已打/所需学时", "科二已打/所需学时", "科三已打/所需学时","科四已打/所需学时", "科二总里程", "科三总里程", "总里程",]] // MARK: 数据 var traineeInfoModel:TraineeInfoModel? // init(info:TraineeInfoModel) { // super.init() // self.traineeInfoModel = info // } required convenience init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() //绑定 biandView() } // MARK: 私有方法 func setInfo(info:TraineeInfoModel){ self.traineeInfoModel = info groupList["个人信息"] = ["证件类型":"身份证", "证件号码":info.idcard, "推荐人":info.source ?? "", "国籍":info.nationality, "地区":info.dqmc, "县区":info.qxmc, "联系地址":info.address, "培训车型":info.trainType, "是否激活":(info.active=="1" ? "是":"否"), "备案时间":info.recordDate, "所属机构":info.schoolName,] let onetime:String = info.trainOneExamStatus=="1" ? "运管已签章"+info.trainOneExamTime.prefix(10):"无" let twotime:String = info.trainTwoExamStatus=="1" ? "运管已签章"+info.trainTwoExamTime.prefix(10):"无" let threetime:String = info.trainThreeExamStatus=="1" ? "运管已签章"+info.trainThreeExamTime.prefix(10):"无" let fourtime:String = info.trainFourExamStatus=="1" ? "运管已签章"+info.trainFourExamTime.prefix(10):"无" if (info.trainOneExamStatus=="1"){ groupColorList["阶段一学时"] = "#35BF5E" groupColorList["科一已打/所需学时"] = "#35BF5E" } if(info.trainTwoExamStatus=="1"){ groupColorList["阶段二学时"] = "#35BF5E" groupColorList["科二已打/所需学时"] = "#35BF5E" } if(info.trainThreeExamStatus=="1"){ groupColorList["阶段三学时"] = "#35BF5E" groupColorList["科三已打/所需学时"] = "#35BF5E" } if(info.trainFourExamStatus=="1"){ groupColorList["阶段四学时"] = "#35BF5E" groupColorList["科四已打/所需学时"] = "#35BF5E" } groupList["培训信息"] = ["阶段一学时":onetime, "阶段二学时":twotime, "阶段三学时":threetime, "阶段四学时":fourtime, "科一已打/所需学时":info.k1+"/"+info.totalKm1, "科二已打/所需学时":info.k2+"/"+info.totalKm2, "科三已打/所需学时":info.k3+"/"+info.totalKm3, "科四已打/所需学时":info.k4+"/"+info.totalKm4, "科二总里程":info.k2Mileage, "科三总里程":info.k3Mileage, "总里程":info.mileage,] tableView.reloadData() } func biandView(){ tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none //去除分割线 tableView.register(UINib(nibName: "MeTraineeDetails01Cell", bundle: nil), forCellReuseIdentifier: cellIdentifier) tableView.rowHeight = 40.f self.isEmptyDisplay = false self.hideLoadAnimation() } } //数据源 extension MeTraineeDetails01Controller:UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { if(groupList.count>0){ return keys.count ?? 0 } return 0 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let count = groupList[keys[section]]!.count return count } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header_view = MeTraineeDetails01HeaderView.loadFromNib() header_view.title_label.text = keys[section] return header_view } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 50.f } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var groupDict = groupList[keys[indexPath.section]]! let _keys = keyArray[indexPath.section] let type = _keys[indexPath.row] let value = groupDict[type] let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MeTraineeDetails01Cell cell.contentView.backgroundColor = ((indexPath.row%2) != 0) ? UIColor("#113357") : UIColor("#0B2B4D") cell.backgroundColor = ((indexPath.row%2) != 0) ? UIColor("#113357") : UIColor("#0B2B4D") cell.type_label.text = type cell.value_label.text = value if let color = groupColorList[type] { // key 存在,执行相应的逻辑 cell.value_label.textColor = UIColor(color) }else { // key 不存在,执行相应的逻辑 cell.value_label.textColor = .db_fontSelColor } return cell } } //事件 extension MeTraineeDetails01Controller:UITableViewDelegate { // func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { // tableView.deselectRow(at: indexPath, animated: false) // let rowInfo = self.traineeDataModel?.rows![indexPath.row] // if rowInfo != nil { // let context: Int = rowInfo?.id ?? 0 // NYSwRouter.push(NYSwPushType.trainee_info,context: context) // } // } }