CNLiveVitaeAddCertificateController.swift 6.96 KB
//
//  CNLiveVitaeAddCertificateController.swift
//  metaCode
//
//  Created by zx on 2024/7/26.
//  数字简历-添加证书页面

import Foundation
import SnapKit

class CNLiveVitaeAddCertificateController:CNLiveBaseViewController,UITableViewDataSource, UITableViewDelegate{
    
    var isAddCerPhoto = true//true为增加证书图片 false为增加证书信息
    var seleImage:UIImage?
    var seleImageUrl:String = ""
    lazy var dataArray :NSMutableArray = {
        let dataArray = NSMutableArray()
        return dataArray
    }()
    
    let kCNLiveVitaeCertificateAddPhotoCellIdentifier = "kCNLiveVitaeCertificateAddPhotoCellIdentifier"
    let kCNLiveVitaeCertificateAddInfoCellIdentifier = "kCNLiveVitaeCertificateAddInfoCellIdentifier"
    
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.tableFooterView = UIView.init()
        tableView.register(CNLiveVitaeCertificateAddPhotoCell.self, forCellReuseIdentifier: kCNLiveVitaeCertificateAddPhotoCellIdentifier)
        tableView.register(CNLiveVitaeCertificateAddInfoCell.self, forCellReuseIdentifier: kCNLiveVitaeCertificateAddInfoCellIdentifier)
        tableView.backgroundColor = .clear
        return tableView
    }()
    lazy var bottomZhiNanWhiteView :UIView = {
        let bottomNavView = UIView()
        bottomNavView.backgroundColor = .white
        return bottomNavView
    }()
    lazy var addCertificateBtn: UIButton = {
        let  nextBtn = UIButton(type: .custom)
        nextBtn.setTitle("确认提交", for: .normal)
        nextBtn.setTitleColor(.white, for: .normal)
        nextBtn.backgroundColor = HexColor("#1961FE")
        nextBtn.layer.cornerRadius = 20
        nextBtn.clipsToBounds = true
        nextBtn.addTarget(self, action: #selector(addCertificateBtnAction), for: .touchUpInside)
        return nextBtn
    }()
    lazy var chengNuoTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#B4B4B4")
        titleLabel.textAlignment = .center
        titleLabel.numberOfLines = 2
        titleLabel.text = "我承诺以上所填写资料均完全真实,如被证实有虚假成分,本人愿意承担一切责任"
        titleLabel.font = Font_12
        return titleLabel
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        titleName = "个人证书"
        navigationBarHidden = false
        self.initUI()
    }
    
    deinit {}
    func initUI(){
        self.view.backgroundColor = HexColor("#F9F9F9")
        
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.top.equalTo(KNavigationHeight)
            make.left.right.equalToSuperview()
            make.height.equalToSuperview().offset(-KNavigationHeight-60-63)
        }
        
        self.view.addSubview(self.chengNuoTitleLabel)
        self.chengNuoTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.tableView.snp.bottom).offset(15)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-75)
        }

        self.view.addSubview(self.bottomZhiNanWhiteView)
        self.bottomZhiNanWhiteView.snp.makeConstraints { make in
            make.height.equalTo(60)
            make.bottom.left.right.equalToSuperview()
        }
        self.bottomZhiNanWhiteView.isHidden = true
        
        self.bottomZhiNanWhiteView.addSubview(self.addCertificateBtn)
        self.addCertificateBtn.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(10)
            make.height.equalTo(40)
        }
        
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if self.isAddCerPhoto == true{
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVitaeCertificateAddPhotoCellIdentifier) as? CNLiveVitaeCertificateAddPhotoCell
            else {
                let cell = CNLiveVitaeCertificateAddPhotoCell()
                return cell
            }
            cell.selectImageBlock = { image,key,url in
                self.isAddCerPhoto = false
                self.tableView.reloadData()
                self.seleImage = image
                self.seleImageUrl = url
                self.bottomZhiNanWhiteView.isHidden = false
            }
            return cell
        }else{
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVitaeCertificateAddInfoCellIdentifier) as? CNLiveVitaeCertificateAddInfoCell
            else {
                let cell = CNLiveVitaeCertificateAddInfoCell()
                return cell
            }
            cell.uploadImage = self.seleImage
            cell.tfReturnBlock = {
                self.view.endEditing(true)
            }
            return cell
        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if isAddCerPhoto == true{
            return 351
        }else{
            return 620
        }
    }
    
    //确认提交证书
    @objc func addCertificateBtnAction(){
        let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! CNLiveVitaeCertificateAddInfoCell
        //判断非空
        if self.seleImage == nil{
            showMessage(message: "请上传图片")
            return
        }
        if cell.cerNameTF.text?.count == 0{
            showMessage(message: "请填写证书名称")
            return
        }
        if cell.cerNumberTF.text?.count == 0{
            showMessage(message: "请填写资格证编号")
            return
        }
        if cell.cerJiGouTF.text?.count == 0{
            showMessage(message: "请填写发证机构")
            return
        }
        let vsid = UserInfoManager.shared.userInfo.currentUser?.vsid ?? ""
        //提交证书
        CNLiveVitaeViewModel.saveCertificate(img: self.seleImageUrl, lv: cell.cerLevelTF.text ?? "", number: cell.cerNumberTF.text ?? "", organization: cell.cerJiGouTF.text ?? "", time: cell.cerTimeTF.text ?? "", title: cell.cerNameTF.text ?? "", uploadTime: "", validity: cell.cerYouXiaoTF.text ?? "", vsid: vsid){result, respStatue in
            if respStatue == .success{
                self.navigationController?.viewControllers.forEach({ item in
                    if (item.isKind(of: CNLiveVitaeVocationalCertificateController.self)) {
                        self.navigationController?.popToViewController(item, animated: true)
                    }
                })
            }
            
        }
    }
}