CNLiveDigitalAuthCell.swift 4.15 KB
//
//  CNLiveDigitalAuthCell.swift
//  metaCode
//
//  Created by zx on 2024/6/5.
//  数字认证cell

import Foundation
import Kingfisher
import SnapKit

typealias SelectBlock = (_ currentCell: CNLiveDigitalAuthCell) -> Void
class CNLiveDigitalAuthCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    
    lazy var lineView :UIView = {
        let lineView = UIView(frame: CGRect(x: 0, y: 19, width: 3, height: 15))
        lineView.backgroundColor = HexColor("#1F64E3")
        return lineView
    }()
    
    lazy var twoTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.lineView.right+19, 15, KSreenWidth-30-40, 23))
        titleLabel.textColor = HexColor("#1F64E3")
        titleLabel.textAlignment = .left
        titleLabel.font = Font_16
        return titleLabel
    }()
    //3级身份列表
    lazy var threeArr: [MineAuthenticationsChildIdentitiesModel] = {
        var threeArr = [MineAuthenticationsChildIdentitiesModel]()
        return threeArr
    }()
    let kCNLiveDigitalThreeCollectCellID = "kCNLiveDigitalThreeCollectCellID"
    lazy var threeCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSizeMake(100, 93)
        layout.minimumLineSpacing = 10
        layout.scrollDirection = .horizontal
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .white
        collectionView.register(CNLiveDigitalThreeCollectCell.self, forCellWithReuseIdentifier: kCNLiveDigitalThreeCollectCellID)
        return collectionView
    }()

    
    //childModel
    var _childModel : MineAuthenticationsChildModel?
    var childModel : MineAuthenticationsChildModel? {
        get{
            _childModel
        }
        set{
            _childModel = newValue!
            setupNewUI(model: _childModel!)
        }
    }
    
    var _tblCellIsSelect:Bool = false
    var tblCellIsSelect:Bool{
        get{
            _tblCellIsSelect
        }
        set{
            _tblCellIsSelect = newValue
        }
    }
    var currentSeleIndex = 0
    var selectBlock:SelectBlock?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.addSubview(self.lineView)
        self.contentView.addSubview(self.twoTitleLabel)
        self.contentView.addSubview(self.threeCollectionView)
        self.threeCollectionView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(self.twoTitleLabel.snp.bottom).offset(20)
            make.height.equalTo(93)
        }
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewUI(model:MineAuthenticationsChildModel){
        self.twoTitleLabel.text = model.name
        self.threeArr = model.identities
        self.threeCollectionView.reloadData()
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        self.childModel?.identities.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveDigitalThreeCollectCellID, for: indexPath) as! CNLiveDigitalThreeCollectCell
        if indexPath.row == currentSeleIndex{
            if self.tblCellIsSelect == true{
                cell.cellIsSelected = true
            }else{
                cell.cellIsSelected = false
            }
        }else{
            cell.cellIsSelected = false
        }
        cell.identitiesModel = self.threeArr[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        let identitiesModel = self.threeArr[indexPath.row]
        currentSeleIndex = indexPath.row
        self.threeCollectionView.reloadData()
        self.selectBlock?(self)
    }
    
}