CNLiveDigitalResumePreViewSecCell.swift 7.13 KB
//
//  CNLiveDigitalResumePreViewSecCell.swift
//  metaCode
//
//  Created by zx on 2024/8/7.
//  数字简历-sec 官方验证cell

import Foundation
import Kingfisher
import SnapKit

var DefaultPreViewCellHeight:CGFloat = 193
var HaveDataPreViewCellHeight:CGFloat = 218

class CNLiveDigitalResumePreViewSecCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    
    lazy var whiteView :UIView = {
        let whiteView = UIView(frame: CGRect(x: 15, y:15, width: KSreenWidth-30, height: DefaultPreViewCellHeight))
        whiteView.backgroundColor = .white
        whiteView.layer.cornerRadius = 12
        whiteView.clipsToBounds = true
        return whiteView
    }()
    lazy var myIdentityTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .center
        titleLabel.text = "官方认证"
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    
    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_preview_guanfangNoData")
        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
    }()
    
    let kCNLiveDigitalResumePreViewSecCollectCellID = "kCNLiveDigitalResumePreViewSecCollectCellID"
    lazy var threeCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSizeMake(60, 60+3+17+14)
        layout.minimumLineSpacing = 22
        layout.scrollDirection = .horizontal
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .white
        collectionView.register(CNLiveDigitalResumePreViewSecCollectionCell.self, forCellWithReuseIdentifier: kCNLiveDigitalResumePreViewSecCollectCellID)
        return collectionView
    }()
    var _digitalListModels : [CNLiveVitaeIdentitiesModel]?
    var digitalListModels : [CNLiveVitaeIdentitiesModel]? {
        get{
            _digitalListModels
        }
        set{
            _digitalListModels = newValue!
            setupNewUI(models: _digitalListModels!)
        }
    }
    
    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.myIdentityTitleLabel)
        self.myIdentityTitleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(adapt_length(length: 15))
            make.left.equalTo(adapt_length(length: 15))
        }
        
        self.whiteView.addSubview(self.threeCollectionView)
        self.threeCollectionView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().offset(18)
            make.top.equalTo(53)
            make.height.equalTo(60+7+17+14)
            make.width.equalToSuperview().offset(-36)
        }
        
        self.whiteView.addSubview(self.zhengshuBtn)
        self.zhengshuBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            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.zhengshuNoDescTitleLabel.isHidden = true
        self.zhengshuNoIconImgView.isHidden = true
 
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewUI(models:[CNLiveVitaeIdentitiesModel]){
        if models.count > 0{
            //有已审核身份
            self.whiteView.height = HaveDataPreViewCellHeight
            self.threeCollectionView.reloadData()
            self.threeCollectionView.isHidden = false
            self.zhengshuNoIconImgView.isHidden = true
            self.zhengshuNoDescTitleLabel.isHidden = true
            self.zhengshuNoIconImgView.isHidden = true
        }else{
            //没有 已审核身份
            self.whiteView.height = DefaultPreViewCellHeight
            self.threeCollectionView.isHidden = true
            self.zhengshuNoIconImgView.isHidden = false
            self.zhengshuNoDescTitleLabel.isHidden = false
        }
    }
   
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        self.digitalListModels?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveDigitalResumePreViewSecCollectCellID, for: indexPath) as! CNLiveDigitalResumePreViewSecCollectionCell
        cell.authListModel = self.digitalListModels?[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.threeCollectionView.reloadData()
    }
    
    @objc func zhengshuBtnAction(){
        //跳转 选择官方认证身份页面
        let vc = CNLiveDigitalResumePreViewSelectRenzhengCerController()
        vc.renzhengCerType = .renzheng
        vc.digitalListModels = self.digitalListModels
        navigationViewController().pushViewController(vc, animated: true)
    }

}