CNLiveRealNameCell.swift 4.87 KB
//
//  CNLiveRealNameCell.swift
//  metaCode
//
//  Created by zx on 2024/6/7.
//  实名认证cell

import Foundation
import Kingfisher
import SnapKit
import QMUIKit

typealias TFReturnBlock = () -> Void//

typealias TFTextUpdateBlock = (_ currentCell: CNLiveRealNameCell ,_ type:Int ,_ textStr:String) -> Void//type: 10姓名 11证件号码
class CNLiveRealNameCell: UITableViewCell, QMUITextFieldDelegate {
            
    var tfTextUpdateBlock:TFTextUpdateBlock?
    var tfReturnBlock:TFReturnBlock?
    
    lazy var nameLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.text = "本人姓名"
        titleLabel.font = BoldFont_16
        titleLabel.adjustsFontSizeToFitWidth = true
        return titleLabel
    }()
    lazy var nameTF :QMUITextField = {
        let searchTF = QMUITextField()
        searchTF.backgroundColor = HexColor("#F7F7F7")
        searchTF.qmui_borderWidth = 0.5
        searchTF.qmui_borderColor = HexColor("#DCDCDC")
        searchTF.textInsets = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
        searchTF.clearButtonMode = .always
        searchTF.textColor = HexColor("#999999")
        searchTF.font = Font_16
        searchTF.delegate = self
        searchTF.returnKeyType = .done
        return searchTF
    }()
    lazy var nameDescLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.text = "按本人有效身份证件填写"
        titleLabel.font = Font_12
        return titleLabel
    }()
    
    var _type:Int = 0//100姓名 101类型 102号码
    var type:Int{
        get{
            _type
        }
        set{
            _type = newValue
            
            if _type == 100{//100姓名
                self.nameLabel.text = "本人姓名"
                let attributedPlaceholder = NSAttributedString(string: "请输入本人姓名", attributes: [.foregroundColor: HexColor("#999999")!, .font: self.nameTF.font!])
                self.nameTF.attributedPlaceholder = attributedPlaceholder
                self.nameTF.isUserInteractionEnabled = true
                self.nameDescLabel.text = "按本人有效身份证件填写"
                
            }else if _type == 101{//101类型
                self.nameLabel.text = "证件类型"
                let attributedPlaceholder = NSAttributedString(string: "居民身份证", attributes: [.foregroundColor: HexColor("#999999")!, .font: self.nameTF.font!])
                self.nameTF.attributedPlaceholder = attributedPlaceholder
                self.nameTF.isUserInteractionEnabled = false
                self.nameDescLabel.text = "中国大陆地区用户推荐设置居民身份证"
            }else if _type == 102{//102号码
                self.nameLabel.text = "证件号码"
                let attributedPlaceholder = NSAttributedString(string: "请输入证件号码", attributes: [.foregroundColor: HexColor("#999999")!, .font: self.nameTF.font!])
                self.nameTF.attributedPlaceholder = attributedPlaceholder
                self.nameTF.isUserInteractionEnabled = true
                self.nameDescLabel.text = "请认真核对您的证件号码,证件号码一经提交"
            }else{
                
            }
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.contentView.addSubview(self.nameLabel)
        self.contentView.addSubview(self.nameTF)
        self.contentView.addSubview(self.nameDescLabel)
        self.nameLabel.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(20)
            make.height.equalTo(23)
        }
        self.nameTF.snp.makeConstraints { make in
            make.top.equalTo(self.nameLabel.snp.bottom).offset(5)
            make.left.equalTo(20)
            make.right.equalToSuperview().offset(-20)
            make.height.equalTo(53)
        }
        self.nameDescLabel.snp.makeConstraints { make in
            make.top.equalTo(self.nameTF.snp.bottom).offset(5)
            make.left.equalTo(20)
            make.right.equalToSuperview().offset(-20)
            make.height.equalTo(17)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UITextFieldDelegate
    func textFieldDidEndEditing(_ textField: UITextField) {
        if self.nameLabel.text == "本人姓名"{
            self.tfTextUpdateBlock?(self, 10, self.nameTF.text ?? "")
        }else if self.nameLabel.text == "证件号码"{
            self.tfTextUpdateBlock?(self, 11, self.nameTF.text ?? "")
        }else{
            
        }
    }
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        self.tfReturnBlock?()
        return true
    }

    
}