CNLiveIdentityResTableCell.swift 4.64 KB
//
//  CNLiveIdentityResTableCell.swift
//  metaCode
//
//  Created by zx on 2024/6/24.
//  身份大库tableViewCell

import Foundation
import Kingfisher
import SnapKit

typealias IdentityResSelectBlock = (_ currentCell: CNLiveIdentityResTableCell ,_ identitiesId:String) -> Void
class CNLiveIdentityResTableCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
        
    lazy var twoTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(15, 15, KSreenWidth-30-40, 24))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.font = BoldFont_17
        return titleLabel
    }()
    //3级身份列表
    lazy var threeArr: [MineAuthenticationsChildIdentitiesModel] = {
        var threeArr = [MineAuthenticationsChildIdentitiesModel]()
        return threeArr
    }()
    let kCNLiveIdentityResThreeCollectCellID = "kCNLiveIdentityResThreeCollectCellID"
    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(CNLiveIdentityResThreeCollectCell.self, forCellWithReuseIdentifier: kCNLiveIdentityResThreeCollectCellID)
        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 = -1
    var selectBlock:IdentityResSelectBlock?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear
        self.selectionStyle = .none
        self.contentView.addSubview(self.twoTitleLabel)
        self.contentView.addSubview(self.threeCollectionView)
        self.threeCollectionView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(self.twoTitleLabel.snp.bottom).offset(10)
            make.height.equalTo(112)
        }
    }
    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: kCNLiveIdentityResThreeCollectCellID, for: indexPath) as! CNLiveIdentityResThreeCollectCell
        if indexPath.row == self.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) {
        self.currentSeleIndex = indexPath.row
        let identitiesModel = self.threeArr[indexPath.row]
        if identitiesModel.userAuth == 0{
            //正在审核
            showMessage(message: "您已认证过该身份,不能重复认证")
            return
        }else if identitiesModel.userAuth == 1{
            //审核成功
            showMessage(message: "您已认证过该身份,不能重复认证")
            return
        }else if identitiesModel.userAuth == -1{
            //审核失败
            
        }else{
            
        }
        self.selectBlock?(self,identitiesModel.id)
        self.threeCollectionView.reloadData()
    }
    
}