CNLiveAuthTool.swift 6.79 KB
//
//  CNLiveAuthTool.swift
//  metaCode
//
//  Created by zx on 2024/6/12.
//

import Foundation
import QMUIKit
import SnapKit

typealias AuthToolHiddenBlock = () -> Void

class CNLiveAuthTool:NSObject{
    static let shared = CNLiveAuthTool()
    
    var authToolHiddenBlock:AuthToolHiddenBlock?
    let delegate = UIApplication.shared.delegate as! AppDelegate

    lazy var bgBtnView: UIButton = {
        let bgBtnView = UIButton(frame: self.delegate.window!.bounds)
        bgBtnView.backgroundColor = HexColor("#000000")
        bgBtnView.alpha = 0.6
//        bgBtnView.addTarget(self, action: #selector(bgBtnViewAction), for: .touchUpInside)
        return bgBtnView
    }()

    lazy var bottomBgView :UIView = {
        let bottomBgView = UIView(frame: CGRect(x: (KSreenWidth-adapt_length(length: 273))/2, y: (KSreenHeight-adapt_length(length: 597))/2, width: adapt_length(length: 273), height: adapt_length(length: 597)))
        bottomBgView.backgroundColor = HexColor("#FFFFFF")
        bottomBgView.layer.cornerRadius = 13
        bottomBgView.clipsToBounds = true
        bottomBgView.tag = integralAlertToolTag
        return bottomBgView
    }()
    
    lazy var failTitleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .center
        titleLabel.font = BoldFont_16
        titleLabel.text = "实名认证失败"
        return titleLabel
    }()
    
    lazy var jianchaView :UIView = {
        let jianchaView = UIView(frame: CGRect(x: adapt_length(length: 14), y: adapt_length(length: 58), width: KSreenWidth-2*adapt_length(length: 14), height: adapt_length(length: 77)))
        jianchaView.backgroundColor = HexColor("#F7F7F7")
        jianchaView.layer.cornerRadius = 9.5
        jianchaView.clipsToBounds = true
        jianchaView.layer.borderWidth = 0.5
        jianchaView.layer.borderColor = HexColor("#E1E1E1")?.cgColor
        return jianchaView
    }()

    //请检查
    lazy var jianchaTitleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .center
        titleLabel.font = Font_12
        titleLabel.text = "请检查"
        return titleLabel
    }()
    
    lazy var firstImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: adapt_length(length: 13), y: adapt_length(length: 35), width: adapt_length(length: 11), height: adapt_length(length: 11)))
        iconImgView.image = UIImage(named: "auth_1")
        return iconImgView
    }()
    lazy var firstTitleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.font = Font_10
        titleLabel.text = "请确保人脸与身份信息证件照相符"
        return titleLabel
    }()

//    lazy var secImgView :UIImageView = {
//        let iconImgView = UIImageView(frame: CGRect(x: adapt_length(length: 13), y: adapt_length(length: 54), width: adapt_length(length: 11), height: adapt_length(length: 11)))
//        iconImgView.image = UIImage(named: "auth_2")
//        return iconImgView
//    }()
//    lazy var secTitleLabel: UILabel = {
//        let titleLabel = UILabel.init()
//        titleLabel.textColor = HexColor("#333333")
//        titleLabel.font = Font_10
//        titleLabel.text = "请确保人脸与身份信息证件照相符"
//        return titleLabel
//    }()
    
    lazy var detailImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "auth_fail")
        return iconImgView
    }()
    
    lazy var xiugaiBtn: UIButton = {
        let  payBtn = UIButton(type: .custom)
        payBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
        payBtn.setTitle("去修改", for: .normal)
        payBtn.titleLabel?.font = Font_18
        payBtn.backgroundColor = HexColor("#1961FE")
        payBtn.layer.cornerRadius = 21
        payBtn.clipsToBounds = true
        payBtn.addTarget(self, action: #selector(xiugaiBtnAction), for: .touchUpInside)
        return payBtn
    }()
    
    // MARK: - show
    ///弹出实名失败弹窗
    func showAuthFailAlert(){
        delegate.window?.addSubview(self.bgBtnView)
        delegate.window?.addSubview(self.bottomBgView)
        self.bottomBgView.addSubview(self.xiugaiBtn)
        self.xiugaiBtn.snp.makeConstraints { make in
            make.height.equalTo(adapt_length(length: 39))
            make.width.equalTo(adapt_length(length: 160))
            make.bottom.equalToSuperview().offset(adapt_length(length: -15))
            make.centerX.equalToSuperview()
        }
        
        self.bottomBgView.addSubview(self.failTitleLabel)
        self.failTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(adapt_length(length: 20))
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(adapt_length(length: 23))
        }

        self.bottomBgView.addSubview(self.jianchaView)
        
        self.jianchaView.addSubview(self.jianchaTitleLabel)
        self.jianchaTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(adapt_length(length: 13))
            make.top.equalTo(adapt_length(length: 10))
        }
        
        self.jianchaView.addSubview(self.firstImgView)
        self.firstImgView.snp.makeConstraints { make in
            make.left.equalTo(adapt_length(length: 13))
            make.top.equalTo(adapt_length(length: 35))
            make.width.equalTo(adapt_length(length: 11))
            make.height.equalTo(adapt_length(length: 11))
        }
        
        self.jianchaView.addSubview(self.firstTitleLabel)
        self.firstTitleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self.firstImgView.snp.centerY)
            make.left.equalTo(self.firstImgView.snp.right).offset(adapt_length(length: 1.5))
        }

        self.bottomBgView.addSubview(self.detailImgView)
        self.detailImgView.snp.makeConstraints { make in
            make.left.equalTo(adapt_length(length: 15))
            make.top.equalTo(self.jianchaView.snp.bottom).offset(adapt_length(length: 10))
            make.width.equalTo(adapt_length(length: 243))
            make.height.equalTo(adapt_length(length: 384))
        }
    }
    
    //隐藏弹窗
    func hiddenIntegralAlert(){
        self.authToolHiddenBlock?()
        delegate.window?.subviews.forEach({ view in
            if view.tag == integralAlertToolTag{
                UIView.animate(withDuration: 0.25) {
                    view.removeFromSuperview()
                    self.bgBtnView.removeFromSuperview()
                    self.bottomBgView.removeFromSuperview()
                }
            }
        })
    }
    
    // MARK: - BtnAction
    @objc func xiugaiBtnAction(){
        self.hiddenIntegralAlert()
    }
    
}