CNLiveVitaeVocationalCertificateController.swift 4.43 KB
//
//  CNLiveVitaeVocationalCertificateController.swift
//  metaCode
//
//  Created by zx on 2024/7/25.
//  职业证书页面

import Foundation
import SnapKit

class CNLiveVitaeVocationalCertificateController:CNLiveBaseViewController,UITableViewDataSource, UITableViewDelegate{
    
    lazy var dataArray :NSMutableArray = {
        let dataArray = NSMutableArray()
        return dataArray
    }()
    
    let kCNLiveVocationalCertificateFirCellIdentifier = "kCNLiveVocationalCertificateFirCellIdentifier"

    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(CNLiveVocationalCertificateFirCell.self, forCellReuseIdentifier: kCNLiveVocationalCertificateFirCellIdentifier)
        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 cerListArr :Array<CNLiveVitaeCertificateModel> = {
        let dataArray = Array<CNLiveVitaeCertificateModel>()
        return dataArray
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.getCetList()
    }
    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)
        }
        
        self.view.addSubview(self.bottomZhiNanWhiteView)
        self.bottomZhiNanWhiteView.snp.makeConstraints { make in
            make.top.equalTo(self.tableView.snp.bottom)
            make.bottom.left.right.equalToSuperview()
        }
        
        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 {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVocationalCertificateFirCellIdentifier) as? CNLiveVocationalCertificateFirCell
        else {
            let cell = CNLiveVocationalCertificateFirCell()
            return cell
        }
        cell.cerListArr = self.cerListArr
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return adapt_length(length: 277)+346
    }
    
    
    @objc func addCertificateBtnAction(){
        self.navigationController?.pushViewController(CNLiveVitaeAddCertificateController(), animated: true)
    }
    
    func getCetList(){
        let vsid = UserInfoManager.shared.userInfo.currentUser?.vsid ?? ""
        CNLiveVitaeViewModel.getCerList(vsid: vsid, page: 1, pageSize: 100){ result, respStatue in
            if respStatue == .success{
                if let res = result as? [CNLiveVitaeCertificateModel]{
                    self.cerListArr = res
                    self.tableView.reloadData()
                }
            }else{
                showMessage(message: "数据异常")
            }
            
        }
    }
}