CNLiveDigitalThreeCell.swift 14.3 KB
//
//  CNLiveDigitalThreeCell.swift
//  metaCode
//
//  Created by zx on 2024/8/7.
//  数字资产-其他证书cell

import Foundation
import Kingfisher
import SnapKit

class CNLiveDigitalThreeCell: UITableViewCell{//, UICollectionViewDelegate, UICollectionViewDataSource {
    
    var _certificatesArr : [CNLiveVitaeCertificatesModel]?
    var certificatesArr : [CNLiveVitaeCertificatesModel]? {
        get{
            _certificatesArr
        }
        set{
            _certificatesArr = newValue!
            setupNewUI(modelsArr: newValue!)
        }
    }
    
    lazy var whiteView :UIView = {
        let whiteView = UIView(frame: CGRect(x: 15, y:adapt_length(length: 20), width: KSreenWidth-30, height: 317))
        whiteView.backgroundColor = .white
        whiteView.layer.cornerRadius = 12
        whiteView.clipsToBounds = true
        return whiteView
    }()
    
    lazy var authNameTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "其他证书"
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    //关联证书
    lazy var zhengshuView :UIView = {
        let bottomNavView = UIView(frame: CGRect(x: 15, y: 0, width: 100, height: 231))
        bottomNavView.backgroundColor = HexColor("#F9F9F9")
        bottomNavView.layer.cornerRadius = 9
        bottomNavView.clipsToBounds = true
        return bottomNavView
    }()
    lazy var zhengshuTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .center
        titleLabel.text = "关联证书"
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    lazy var zhengshuDescTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "关联技能证书或身份证书,见证你的实力"
        titleLabel.font = Font_12
        return titleLabel
    }()
    
//    let kCNLiveDigitalThreeCerCollectCellID = "kCNLiveDigitalThreeCerCollectCellID"
//    lazy var threeCollectionView: UICollectionView = {
//        let layout = UICollectionViewFlowLayout()
//        layout.itemSize = CGSizeMake(85, 101)
//        layout.minimumLineSpacing = 20
//        layout.scrollDirection = .horizontal
//        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
//        collectionView.delegate = self
//        collectionView.dataSource = self
//        collectionView.backgroundColor = .clear
//        collectionView.register(CNLiveDigitalThreeCerCollectCell.self, forCellWithReuseIdentifier: kCNLiveDigitalThreeCerCollectCellID)
//        return collectionView
//    }()
    
    lazy var zhengshuNoDescTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.text = "还没有添加其他职业证书"
        titleLabel.font = Font_12
        return titleLabel
    }()
    lazy var zhengshuNoIconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 18, y: 0, width: 60, height: 45))
        iconImgView.contentMode = .scaleAspectFit
        iconImgView.image = UIImage(named: "mine_jianli_nocer")
        return iconImgView
    }()
    
    lazy var zhengshuBtn: UIButton = {
        let  closeBtn = UIButton(type: .custom)
        closeBtn.setTitle("管理证书", for: .normal)
        closeBtn.setTitleColor(HexColor("#1961FE"), for: .normal)
        closeBtn.titleLabel?.font = BoldFont_14
        closeBtn.layer.borderColor = HexColor("#1961FE")?.cgColor
        closeBtn.layer.borderWidth = 0.5
        closeBtn.layer.cornerRadius = 6
        closeBtn.clipsToBounds = true
        closeBtn.addTarget(self, action: #selector(zhengshuBtnAction), for: .touchUpInside)
        return closeBtn
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        self.selectionStyle = .none
        
        self.contentView.addSubview(self.whiteView)
        self.whiteView.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.bottom.equalToSuperview()
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
        self.whiteView.addSubview(self.authNameTitleLabel)
        self.authNameTitleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(adapt_length(length: 15))
            make.left.equalTo(adapt_length(length: 15))
        }
        self.whiteView.addSubview(self.zhengshuView)
        self.zhengshuView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(adapt_length(length: 15))
            make.right.equalToSuperview().offset(adapt_length(length: -15))
            make.top.equalTo(self.authNameTitleLabel.snp.bottom).offset(adapt_length(length: 15))
            make.bottom.equalToSuperview().offset(-15)
        }
        self.zhengshuView.addSubview(self.zhengshuTitleLabel)
        self.zhengshuTitleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(adapt_length(length: 15))
            make.top.equalToSuperview().offset(adapt_length(length: 15))
        }
        self.zhengshuView.addSubview(self.zhengshuDescTitleLabel)
        self.zhengshuDescTitleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(adapt_length(length: 15))
            make.top.equalTo(self.zhengshuTitleLabel.snp.bottom).offset(adapt_length(length: 3))
        }

        self.whiteView.addSubview(self.zhengshuBtn)
        self.zhengshuBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20-15)
            make.width.equalTo(86)
            make.height.equalTo(34)
        }
        
        self.whiteView.addSubview(self.zhengshuNoDescTitleLabel)
        self.zhengshuNoDescTitleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(self.zhengshuBtn.snp.top).offset(-10)
        }
        self.whiteView.addSubview(self.zhengshuNoIconImgView)
        self.zhengshuNoIconImgView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(self.zhengshuNoDescTitleLabel.snp.top).offset(-10)
            make.width.equalTo(60)
            make.height.equalTo(45)
        }
//        self.contentView.backgroundColor = .clear
//        self.backgroundColor = .clear
//        self.selectionStyle = .none
//        
//        self.contentView.addSubview(self.whiteView)
//        self.whiteView.addSubview(self.authNameTitleLabel)
//        self.authNameTitleLabel.snp.makeConstraints { make in
//            make.left.equalTo(adapt_length(length: 15))
//            make.top.equalTo(adapt_length(length: 15))
//        }
//        
//        self.whiteView.addSubview(self.zhengshuView)
//        self.zhengshuView.snp.makeConstraints { make in
//            make.left.equalToSuperview().offset(adapt_length(length: 15))
//            make.right.equalToSuperview().offset(adapt_length(length: -15))
//            make.top.equalTo(self.authNameTitleLabel.snp.bottom).offset(adapt_length(length: 15))
//            make.height.equalTo(249)
//        }
//        self.zhengshuView.addSubview(self.zhengshuTitleLabel)
//        self.zhengshuTitleLabel.snp.makeConstraints { make in
//            make.left.equalToSuperview().offset(adapt_length(length: 15))
//            make.top.equalToSuperview().offset(adapt_length(length: 15))
//        }
//        self.zhengshuView.addSubview(self.zhengshuDescTitleLabel)
//        self.zhengshuDescTitleLabel.snp.makeConstraints { make in
//            make.left.equalToSuperview().offset(adapt_length(length: 15))
//            make.top.equalTo(self.zhengshuTitleLabel.snp.bottom).offset(adapt_length(length: 3))
//        }
//        self.zhengshuView.addSubview(self.threeCollectionView)
//        self.threeCollectionView.snp.makeConstraints { make in
//            make.left.right.equalToSuperview()
//            make.top.equalTo(self.zhengshuDescTitleLabel.snp.bottom).offset(15)
//            make.height.equalTo(101)
//            make.width.equalToSuperview().offset(-20)
//        }
//        self.zhengshuView.addSubview(self.zhengshuBtn)
//        self.zhengshuBtn.snp.makeConstraints { make in
//            make.centerX.equalToSuperview()
//            make.bottom.equalToSuperview().offset(adapt_length(length: -20))
//            make.width.equalTo(adapt_length(length: 86))
//            make.height.equalTo(34)
//        }
//        
//        self.zhengshuView.addSubview(self.zhengshuNoDescTitleLabel)
//        self.zhengshuNoDescTitleLabel.snp.makeConstraints { make in
//            make.centerX.equalToSuperview()
//            make.bottom.equalTo(self.zhengshuBtn.snp.top).offset(-10)
//        }
//        self.zhengshuView.addSubview(self.zhengshuNoIconImgView)
//        self.zhengshuNoIconImgView.snp.makeConstraints { make in
//            make.centerX.equalToSuperview()
//            make.bottom.equalTo(self.zhengshuNoDescTitleLabel.snp.top).offset(-10)
//            make.width.equalTo(60)
//            make.height.equalTo(45)
//        }

        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        self.certificatesArr?.count ?? 0
//    }
//    
//    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveDigitalThreeCerCollectCellID, for: indexPath) as! CNLiveDigitalThreeCerCollectCell
//        cell.cerModel = self.certificatesArr?[indexPath.row]
//        return cell
//    }
//    
//    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        navigationViewController().pushViewController(CNLiveVitaeVocationalCertificateController(), animated: true)
//    }
    
    @objc func cerTapAction(ges:UITapGestureRecognizer){
        if let getView = ges.view{
            let tag = getView.tag-1000
            let vc = CNLiveVitaeVocationalCertificateController()
            if let cerModel = self.certificatesArr?[tag]{
                vc.currSeleCerId = cerModel.id
            }
            //跳转 证书列表页面
            navigationViewController().pushViewController(vc, animated: true)

        }
    }

    @objc func zhengshuBtnAction(){
        //跳转 证书列表页面
        navigationViewController().pushViewController(CNLiveVitaeVocationalCertificateController(), animated: true)
    }
    
//    func setupNewUI(models:[CNLiveVitaeCertificateModel]){
//        if models.count > 0{
//            self.threeCollectionView.reloadData()
//            self.threeCollectionView.isHidden = false
//            self.zhengshuNoDescTitleLabel.isHidden = true
//            self.zhengshuNoIconImgView.isHidden = true
//
//        }else{
//            self.threeCollectionView.isHidden = true
//            self.zhengshuNoDescTitleLabel.isHidden = false
//            self.zhengshuNoIconImgView.isHidden = false
//        }
//    }
    func setupNewUI(modelsArr:[CNLiveVitaeCertificatesModel]){
        self.whiteView.subviews.forEach { view in
            if view.tag >= 1000{
                view.removeFromSuperview()
            }
        }
        if modelsArr.count > 0{
            //有 证书
            //计算几行 ,1行3个
            let totalHang:Int = modelsArr.count / 3
            if totalHang == 0{
                self.whiteView.height = CerHaveDataPreViewCellHeight
            }else{
                self.whiteView.height = CerHaveDataPreViewCellHeight+72+15+CGFloat(totalHang*115)
            }
            self.zhengshuNoIconImgView.isHidden = true
            self.zhengshuNoDescTitleLabel.isHidden = true
            
            for i in 0..<modelsArr.count {
                let imgW:Float = Float((KSreenWidth-80-30)/3.0)
                let imgH:Float = 101*imgW/85.0
                let imgGap:Float = 20
                let imgLeftGap:Float = 20
                let lie = i%3
                let hang = i/3
                let imgView = UIImageView(frame: CGRect(x: CGFloat(imgLeftGap+(imgGap+imgW)*Float(lie)), y: CGFloat((imgH+10)*Float(hang))+125, width: CGFloat(imgW), height: CGFloat(imgH)))
                imgView.contentMode = .scaleAspectFit
                imgView.tag = 1000+i
                imgView.isUserInteractionEnabled = true
                imgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cerTapAction)))
                let cerModel = modelsArr[i]//CNLiveVitaeCertificateModel
//                let imgUrl = cerModel.img
//                imgView.kf.setImage(with: URL(string: imgUrl))
                if cerModel.status == 1{
                    imgView.image = UIImage(named: "mine_jianli_cerBg_authed")
                }else{
                    imgView.image = UIImage(named: "mine_jianli_cerBg_unauthed")
                }
                imgView.clipsToBounds = true
                imgView.layer.cornerRadius = 5
                self.whiteView.addSubview(imgView)
                
                let titleX:Float = 15*imgW/85
                let titleY:Float = 19*imgW/85
                let titleW:Float = 55*imgW/85
                let titleH:Float = 30
                let titleLbl = UILabel()
                titleLbl.frame = CGRect(x: CGFloat(titleX), y: CGFloat(titleY), width: CGFloat(titleW), height: CGFloat(titleH))
                titleLbl.numberOfLines = 2
                titleLbl.font = BoldFont_11
                titleLbl.textColor = HexColor("#333333")
                titleLbl.textAlignment = .center
                imgView.addSubview(titleLbl)
                titleLbl.text = cerModel.title
            }
             
        }else{
            //没有 证书
            self.whiteView.height = DefaultPreViewCellHeight
            self.zhengshuNoIconImgView.isHidden = false
            self.zhengshuNoDescTitleLabel.isHidden = false
        }
    }
}