CNLiveVocationalCertificateFirCell.swift 14.5 KB
//
//  CNLiveVocationalCertificateFirCell.swift
//  metaCode
//
//  Created by zx on 2024/7/25.
//  简历-职业证书顶部cell

import Foundation
import Kingfisher
import SnapKit


class CNLiveVocationalCertificateFirCell: UITableViewCell, UICollectionViewDataSource ,UICollectionViewDelegate{
    
    var currSeleIndex = 0
    var pageNum: NSInteger! = 1

    //cerListArr
    var _cerListArr : Array<CNLiveVitaeCertificatesModel>?
    var cerListArr : Array<CNLiveVitaeCertificatesModel>? {
        get{
            _cerListArr
        }
        set{
            _cerListArr = newValue!
            setupNewUI(cerListArr :_cerListArr!)
        }
    }
    
    lazy var bgImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "mine_jianli_zhengshu-bg")
        return iconImgView
    }()
    lazy var yuanmaLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.text = "职业证书"
        titleLabel.font = BoldFont_24
        titleLabel.adjustsFontSizeToFitWidth=true
        return titleLabel
    }()

    lazy var yuanmaDescLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.text = "共 1 条"
        titleLabel.font = Font_16
        return titleLabel
    }()
    
    let kCNLiveVocationalCertificateFirCollectCellIdentifier = "kCNLiveVocationalCertificateFirCollectCellIdentifier"

    let collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()//CNLiveVocationalCertifiteCollectionViewLayout()
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSizeMake(76, 90)
        layout.sectionInset = .init(top: 0, left: 15, bottom: 0, right: 15)
        layout.minimumLineSpacing = 30
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.backgroundColor = .clear
        collectionView.showsHorizontalScrollIndicator = false
        return collectionView
    }()

    lazy var whiteBgView :UIView = {
        let whiteBgView = UIView()
        whiteBgView.backgroundColor = .white
        whiteBgView.layer.cornerRadius = 12
        whiteBgView.clipsToBounds = true
        return whiteBgView
    }()
    lazy var cerDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "证书详情"
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    lazy var cerNameTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "证书名称"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var cerNameDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "无"
        titleLabel.font = BoldFont_14
        return titleLabel
    }()
    lazy var cerLevelTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "证书等级/分数"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var cerLevelDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "无"
        titleLabel.font = BoldFont_14
        return titleLabel
    }()
    lazy var authIconImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "mine_jianli_yiyanzheng")
        iconImgView.isHidden = true
        return iconImgView
    }()
    lazy var cerNumberTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "证书编号"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var cerNumberDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "无"
        titleLabel.font = BoldFont_14
        return titleLabel
    }()
    lazy var cerJiGouTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "发证机构"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var cerJiGouDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "无"
        titleLabel.font = BoldFont_14
        return titleLabel
    }()
    lazy var cerStatusTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "验证状态"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var cerStatusDetailTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "未验证"
        titleLabel.font = BoldFont_14
        return titleLabel
    }()
    lazy var authGuanfangIconImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "mine_jianli_guanfnagAuth")
        return iconImgView
    }()
        
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear
        self.contentView.addSubview(self.bgImgView)
        self.bgImgView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(KSreenWidth*457/375)
        }
            
        self.contentView.addSubview(self.yuanmaLabel)
        self.yuanmaLabel.snp.makeConstraints { make in
            make.top.equalTo(adapt_length(length: 55))
            make.left.equalTo(adapt_length(length: 30))
        }
        
        self.contentView.addSubview(self.yuanmaDescLabel)
        self.yuanmaDescLabel.snp.makeConstraints { make in
            make.top.equalTo(self.yuanmaLabel.snp.bottom).offset(adapt_length(length: 5))
            make.left.equalTo(adapt_length(length: 30))
        }
        
        self.contentView.addSubview(self.collectionView)
        self.collectionView.dataSource = self
        self.collectionView.delegate = self
        self.collectionView.register(CNLiveCertificateCollectionCell.self, forCellWithReuseIdentifier: kCNLiveVocationalCertificateFirCollectCellIdentifier)
        self.collectionView.snp.makeConstraints { make in
            make.top.equalTo(self.yuanmaDescLabel.snp.bottom).offset(adapt_length(length: 41))
            make.height.equalTo(adapt_length(length: 114))
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
        
        self.contentView.addSubview(self.whiteBgView)
        self.whiteBgView.snp.makeConstraints { make in
            make.top.equalTo(adapt_length(length: 277))
            make.bottom.equalToSuperview()
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
        self.whiteBgView.addSubview(self.cerDetailTitleLabel)
        self.cerDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.cerNameTitleLabel)
        self.cerNameTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerDetailTitleLabel.snp.bottom).offset(30)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.cerNameDetailTitleLabel)
        self.cerNameDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerNameTitleLabel.snp.bottom).offset(3)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-5)
        }
        self.whiteBgView.addSubview(self.cerLevelTitleLabel)
        self.cerLevelTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerNameDetailTitleLabel.snp.bottom).offset(15)
            make.left.equalTo(15)
            make.width.equalTo(100)
            make.height.equalTo(17)
        }
        self.whiteBgView.addSubview(self.cerLevelDetailTitleLabel)
        self.cerLevelDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerLevelTitleLabel.snp.bottom).offset(3)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.authIconImgView)
        self.authIconImgView.snp.makeConstraints { make in
            make.top.equalTo(self.cerNameDetailTitleLabel.snp.bottom).offset(5)
            make.right.equalToSuperview()
        }
        self.whiteBgView.addSubview(self.cerNumberTitleLabel)
        self.cerNumberTitleLabel.snp.makeConstraints { make in
        
            make.top.equalTo(self.cerLevelTitleLabel.snp.top)
            make.right.equalToSuperview().offset(adapt_length(length: -117))
            make.left.greaterThanOrEqualTo(self.cerLevelTitleLabel.snp.right).offset(5)
        }
        self.whiteBgView.addSubview(self.cerNumberDetailTitleLabel)
        self.cerNumberDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerNumberTitleLabel.snp.bottom).offset(3)
            make.left.equalTo(self.cerNumberTitleLabel.snp.left)
            make.right.equalToSuperview().offset(-5)
        }
        self.whiteBgView.addSubview(self.cerJiGouTitleLabel)
        self.cerJiGouTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerLevelDetailTitleLabel.snp.bottom).offset(15)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.cerJiGouDetailTitleLabel)
        self.cerJiGouDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerJiGouTitleLabel.snp.bottom).offset(3)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-5)
        }
        self.whiteBgView.addSubview(self.cerStatusTitleLabel)
        self.cerStatusTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerJiGouDetailTitleLabel.snp.bottom).offset(15)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.cerStatusDetailTitleLabel)
        self.cerStatusDetailTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.cerStatusTitleLabel.snp.bottom).offset(3)
            make.left.equalTo(15)
        }
        self.whiteBgView.addSubview(self.authGuanfangIconImgView)
        self.authGuanfangIconImgView.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-20)
            make.left.equalTo(15)
            make.width.equalTo(83)
            make.height.equalTo(16)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewUI(cerListArr : Array<CNLiveVitaeCertificatesModel>){
        self.yuanmaDescLabel.text = "共 \(cerListArr.count) 条"
        self.collectionView.reloadData()
        self.collectionView.scrollToItem(at: IndexPath(item: self.currSeleIndex, section: 0), at: .centeredHorizontally, animated: true)
    }
    func setupCerDetailNewUI(cerModel : CNLiveVitaeCertificatesModel){
        self.cerNameDetailTitleLabel.text = (cerModel.title.count > 0) ? cerModel.title : "无"
        self.cerLevelDetailTitleLabel.text =  (cerModel.lv.count > 0) ? cerModel.lv : "无"
        self.cerNumberDetailTitleLabel.text = (cerModel.number.count > 0) ? cerModel.number : "无"
        self.cerJiGouDetailTitleLabel.text =  (cerModel.organization.count > 0) ? cerModel.organization : "无"
        var isAuthed = false
        if cerModel.status == 0 || cerModel.status == -1{
            isAuthed = false
        }
        if cerModel.status == 1{
            isAuthed = true
        }
        self.cerStatusDetailTitleLabel.text =  isAuthed ? "已验证" : "未验证"
        self.authIconImgView.isHidden =  isAuthed ? false : true
        self.authGuanfangIconImgView.image = isAuthed ? UIImage(named: "mine_jianli_guanfnagAuth") : UIImage(named: "mine_jianli_zhenshi")
        if isAuthed{
            self.authGuanfangIconImgView.snp.remakeConstraints { make in
                make.bottom.equalToSuperview().offset(-20)
                make.left.equalTo(15)
                make.width.equalTo(68)
                make.height.equalTo(19)
            }
        }else{
            self.authGuanfangIconImgView.snp.remakeConstraints { make in
                make.bottom.equalToSuperview().offset(-20)
                make.left.equalTo(15)
                make.width.equalTo(83)
                make.height.equalTo(16)
            }
        }
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.cerListArr?.count ?? 0 // 图片的数量
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveVocationalCertificateFirCollectCellIdentifier, for: indexPath) as! CNLiveCertificateCollectionCell
        if indexPath.row == self.currSeleIndex{
            cell.cellIsSelected = true
            if self.cerListArr?.count ?? 0 > 0{
                let model = self.cerListArr![indexPath.row]
                self.setupCerDetailNewUI(cerModel: model)
            }
            
        }else{
            cell.cellIsSelected = false
        }
        if self.cerListArr?.count ?? 0 > 0{
            let model = self.cerListArr?[indexPath.row]
            cell.cerModel = model
        }
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.currSeleIndex = indexPath.row
        self.collectionView.reloadData()
        if self.cerListArr?.count ?? 0 > 0{
            let model = self.cerListArr![indexPath.row]
            self.setupCerDetailNewUI(cerModel: model)
        }
    }
    
    
}