CNLiveDigitalSecCell.swift 5.26 KB
//
//  CNLiveDigitalSecCell.swift
//  metaCode
//
//  Created by zx on 2024/6/17.
//  数字资产-身份cell

import Foundation
import Kingfisher
import SnapKit

class CNLiveDigitalSecCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
        
    lazy var whiteView :UIView = {
        let whiteView = UIView(frame: CGRect(x: 15, y:adapt_length(length: 15), width: KSreenWidth-30, height: adapt_length(length: 152)))
        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
    }()
    
    let kCNLiveDigitalSecCollectCellID = "kCNLiveDigitalSecCollectCellID"
    lazy var threeCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSizeMake(adapt_length(length: 60), adapt_length(length: 60+3+17))
        layout.minimumLineSpacing = 22
        layout.scrollDirection = .horizontal
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .white
        collectionView.register(CNLiveDigitalSecCollectionCell.self, forCellWithReuseIdentifier: kCNLiveDigitalSecCollectCellID)
        return collectionView
    }()
    var currSeleIndex = 0

    var _digitalListModels : [MineAuthListModel]?
    var digitalListModels : [MineAuthListModel]? {
        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.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(adapt_length(length: 18))
            make.top.equalTo(adapt_length(length: 53))
            make.height.equalTo(adapt_length(length: 60+7+17))
            make.width.equalToSuperview().offset(adapt_length(length: -36))
        }
 
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    @objc func zhengshuBtnAction(){
//        self.show17Alert()
//    }
//    @objc func gongzuoBtnAction(){
//        self.show17Alert()
//    }
//    @objc func shetuanBtnAction(){
//        self.show17Alert()
//    }
//    @objc func huojiangBtnAction(){
//        self.show17Alert()
//    }
    
//    // MARK: - 点击弹窗,按类型跳转
//    @objc func alertBgImgViewClickAction() {
//        self.hiden17Alert()
//    }
//    @objc func alertBgViewClickAction() {
//        //点击蒙版隐藏view
//        self.hiden17Alert()
//    }
//    
//    //弹出弹窗
//    func show17Alert(){
//        
//        delegate.window?.addSubview(self.alertBgView)
//        delegate.window?.addSubview(self.alertBgImgView)
//        alertBgImgView.snp.makeConstraints { make in
//            make.centerX.equalToSuperview()
//            make.centerY.equalToSuperview()
//            make.width.equalTo(KSreenWidth-80)
//            make.height.equalTo((KSreenWidth-80)*170.5/295)
//        }
//        
//        self.alertBgImgView.image = UIImage(named: "auth_alert_unOpen")
//    }
//    func hiden17Alert(){
//        delegate.window?.subviews.forEach({ view in
//            if view.tag >= 20000{
//                view.removeFromSuperview()
//            }
//        })
//    }
//    
    
    func setupNewUI(models:[MineAuthListModel]){

        self.threeCollectionView.reloadData()
    }
   
    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: kCNLiveDigitalSecCollectCellID, for: indexPath) as! CNLiveDigitalSecCollectionCell
        cell.authListModel = self.digitalListModels?[indexPath.row]
        if indexPath.row == currSeleIndex
        {//
            cell.cellIsSelected = true
        }else{
        //
            cell.cellIsSelected = false
        }
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.currSeleIndex = indexPath.row
        self.threeCollectionView.reloadData()
    }
}