CNLiveVitaeCertificateAddPhotoCell.swift 7.92 KB
//
//  CNLiveVitaeCertificateAddPhotoCell.swift
//  metaCode
//
//  Created by zx on 2024/7/26.
//

import Foundation
import HXPHPicker

typealias SelectUploadImageBlock = (_ uploadImage: UIImage,_ key: String,_ url: String) -> Void

class CNLiveVitaeCertificateAddPhotoCell: UITableViewCell, PhotoPickerControllerDelegate{
    var selectImageBlock:SelectUploadImageBlock?
    lazy var whiteBgView :UIView = {
        let whiteBgView = UIView()
        whiteBgView.backgroundColor = .white
        whiteBgView.layer.cornerRadius = 12
        whiteBgView.clipsToBounds = true
        return whiteBgView
    }()
    lazy var uploadTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "请上传个人证书图片"
        titleLabel.font = BoldFont_15
        return titleLabel
    }()
    
    lazy var uploadRealBgView :UIView = {
        let bottomNavView = UIView()
        bottomNavView.backgroundColor = HexColor("#F7F8FA")
        return bottomNavView
    }()

    lazy var uploadRealTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.numberOfLines = 2
        titleLabel.text = "·请上传真实信息,否则可能会影响你的信用\n·图片只自己查询和做认证,对外不展示图片"
        titleLabel.font = Font_11
        return titleLabel
    }()
    lazy var uploadPhotoBgImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "mine_jianli_cerPhotoBg")
        iconImgView.isUserInteractionEnabled = true
        iconImgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(uploadPhotoBgImgViewAction)))
        return iconImgView
    }()
    lazy var uploadPhotoImgView :UIImageView = {
        let iconImgView = UIImageView()
        iconImgView.image = UIImage(named: "mine_jianli_cerPhoto")
        return iconImgView
    }()
    lazy var uploadPhotoTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.text = "上传图片"
        titleLabel.font = BoldFont_16
        return titleLabel
    }()
    lazy var chakanTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#666666")
        titleLabel.textAlignment = .right
        titleLabel.text = "点击查看"
        titleLabel.font = Font_14
        return titleLabel
    }()
    lazy var realTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#1961FE")
        titleLabel.textAlignment = .left
        titleLabel.text = "正确示意"
        titleLabel.font = Font_14
        titleLabel.isUserInteractionEnabled = true
        titleLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(uploadShiYiAction)))
        return titleLabel
    }()
    lazy var realBgView :UIView = {
        let bottomNavView = UIView()
        bottomNavView.backgroundColor = .clear
        bottomNavView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(uploadShiYiAction)))
        return bottomNavView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear

        self.contentView.addSubview(self.whiteBgView)
        self.whiteBgView.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.height.equalTo(351)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
        
        self.whiteBgView.addSubview(self.uploadTitleLabel)
        self.uploadTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.left.equalTo(15)
        }
        
        self.whiteBgView.addSubview(self.uploadRealBgView)
        self.uploadRealBgView.snp.makeConstraints { make in
            make.top.equalTo(self.uploadTitleLabel.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.height.equalTo(50)
            make.right.equalToSuperview().offset(-15)
        }
        
        self.uploadRealBgView.addSubview(self.uploadRealTitleLabel)
        self.uploadRealTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.centerY.equalToSuperview()
        }
        
        self.whiteBgView.addSubview(self.uploadPhotoBgImgView)
        self.uploadPhotoBgImgView.snp.makeConstraints { make in
            make.top.equalTo(self.uploadRealBgView.snp.bottom).offset(15)
            make.left.equalTo(15)
            make.height.equalTo(180)
            make.right.equalToSuperview().offset(-15)
        }
        self.uploadPhotoBgImgView.addSubview(self.uploadPhotoImgView)
        self.uploadPhotoImgView.snp.makeConstraints { make in
            make.top.equalTo(50)
            make.width.height.equalTo(50)
            make.centerX.equalToSuperview()
        }
        self.uploadPhotoBgImgView.addSubview(self.uploadPhotoTitleLabel)
        self.uploadPhotoTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.uploadPhotoImgView.snp.bottom).offset(10)
            make.centerX.equalToSuperview()
        }
        
        self.whiteBgView.addSubview(self.chakanTitleLabel)
        self.chakanTitleLabel.snp.makeConstraints { make in
            make.right.equalTo(self.uploadPhotoBgImgView.snp.centerX).offset(-5)
            make.top.equalTo(self.uploadPhotoBgImgView.snp.bottom).offset(15)
        }
            
        self.whiteBgView.addSubview(self.realTitleLabel)
        self.realTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(self.uploadPhotoBgImgView.snp.centerX).offset(5)
            make.top.equalTo(self.uploadPhotoBgImgView.snp.bottom).offset(15)
        }
        
        self.whiteBgView.addSubview(self.realBgView)
        self.realBgView.snp.makeConstraints { make in
            make.left.equalTo(self.uploadPhotoBgImgView.snp.centerX)
            make.top.equalTo(self.uploadPhotoBgImgView.snp.bottom).offset(5)
            make.width.equalTo(100)
            make.bottom.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func uploadPhotoBgImgViewAction(){
        //上传图片
        let config = PhotoTools.getWXPickerConfig()
        config.selectMode = .single
        config.selectOptions = .photo
        config.maximumSelectedPhotoCount = 3
        let pickerController = PhotoPickerController(picker: config)
        pickerController.pickerDelegate = self
        pickerController.isOriginal = false
        currentViewController()!.present(pickerController, animated: true, completion: nil)

    }
    @objc func uploadShiYiAction(){
        //跳转上传示意图页面
        navigationViewController().pushViewController(CNLiveVitaeCerAddPhotoController(), animated: true)
    }
}

extension CNLiveVitaeCertificateAddPhotoCell {
    
    func pickerController(_ pickerController: PhotoPickerController,
                            didFinishSelection result: PickerResult) {
        result.getImage { [weak self] (image, photoAsset, index) in
            if let image = image {
                let uploadKey = UploadManager.uploadViateImage(imageData: image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
                    print("获取进度==>\(progress)")
                }, successBlock: { [weak self] key,url in
                    self?.selectImageBlock?(image,key,url)
                })
                
            }else {
                print("failed")
            }
        } completionHandler: { (images) in

        }
    }
}