CNLiveMineAuthFormViewController.swift 13.1 KB
//
//  CNLiveMineAuthFormViewController.swift
//  metaCode
//
//  Created by open on 2024/1/23.
//

import Foundation
import UIKit
import EmptyDataSet_Swift

class CNLiveMineAuthFormViewController: CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource,EmptyDataSetSource, EmptyDataSetDelegate {
    
    let kMIneBodyAuthFormViewCellIdentifier = "kMIneBodyAuthFormViewCellIdentifier"
    lazy var tableView: UITableView = {
        let tableView = UITableView.init(frame: .zero, style: .grouped)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.emptyDataSetSource = self
        tableView.emptyDataSetDelegate = self
        tableView.backgroundColor = .clear
        tableView.separatorStyle = .none
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        tableView.register(MineAuthFormTableViewCell.self, forCellReuseIdentifier: kMIneBodyAuthFormViewCellIdentifier)
        return tableView
    }()
    
    lazy var dataArray: NSMutableArray = {
        let array = NSMutableArray.init()
        if _listModel.userAuth {
            array.add(["back":"mine_form_auth_btn_persion","icon":"mine_form_auth_btn_persion_icon","name":"个人认证","desc":"适合个人创作者、行业专家、自媒体领域"])
        }
        if _listModel.enterpriseAuth && _listModel.agencyAuth {
            let dict01 = ["back":"mine_form_auth_btn_formal_larg","icon":"mine_form_auth_btn_enterprise_icon","name":"企业认证","desc":"适合企业、个体工商户"]
            let dict02 = ["back":"mine_form_auth_btn_formal_larg","icon":"mine_form_auth_btn_agency_icon","name":"机构认证","desc":"适合国家机构、社会组织、高校等"]
            let temp_array = NSMutableArray()
            temp_array.add(dict01)
            temp_array.add(dict02)
            array.add(temp_array as! [Dictionary<String,String>])
        } else {
            if _listModel.enterpriseAuth  {
                array.add(["back":"mine_form_auth_btn_formal","icon":"mine_form_auth_btn_enterprise_icon","name":"企业认证","desc":"适合企业、个体工商户"])
            }else if _listModel.agencyAuth {
                array.add(["back":"mine_form_auth_btn_formal","icon":"mine_form_auth_btn_agency_icon","name":"机构认证","desc":"适合国家机构、社会组织、高校等"])
            }
        }
        return array
    }()
    
    var _listModel: StandListModel!
    
    init(listModel:StandListModel) {
        super.init(nibName:nil, bundle:nil)
        _listModel = listModel
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarHidden = false
        titleName = "元码官方认证"
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.top.equalTo(KNavigationHeight)
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(get_system_tabbar_height() - get_system_tabbar_ui_height())
        }
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return dataArray.count
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kMIneBodyAuthFormViewCellIdentifier) as? MineAuthFormTableViewCell else {
            return MineAuthFormTableViewCell()
        }
        cell.clickBlock = {[weak self] view in
            guard let self = self else { return }
            let titleLabel = view.viewWithTag(1000) as! UILabel
            if titleLabel.text == "个人认证" {
                self.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: _listModel, authType: .person), animated: true)
            }
            if titleLabel.text == "企业认证" {
                self.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: _listModel, authType: .enterprise), animated: true)
            }
            if titleLabel.text == "机构认证" {
                self.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: _listModel, authType: .agency), animated: true)
            }
        }
        let obj = dataArray[indexPath.section]
        if obj is Dictionary<String, String> {
            let dict = obj as! Dictionary<String, String>
            cell.mainView.image = UIImage(named: dict["back"]! as String)
            cell.headerImageView.image = UIImage(named: dict["icon"]! as String)
            cell.titleLabel.text = dict["name"]! as String
            cell.descLabel.text = dict["desc"]! as String
            cell.whiteView01.isHidden = true
        }
        if obj is [Dictionary<String,String>] {
            cell.whiteView01.isHidden = false
            let dict01 = (obj as! Array<Dictionary<String, String>>).first
            cell.mainView.image = UIImage(named: dict01!["back"]! as String)
            cell.headerImageView.image = UIImage(named: dict01!["icon"]! as String)
            cell.titleLabel.text = dict01!["name"]! as String
            cell.descLabel.text = dict01!["desc"]! as String
            let dict02 = (obj as! Array<Dictionary<String, String>>).last
            cell.headerImageView01.image = UIImage(named: dict02!["icon"]! as String)
            cell.titleLabel01.text = dict02!["name"]! as String
            cell.descLabel01.text = dict02!["desc"]! as String
        }
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let obj = dataArray[indexPath.section]
        if obj is Dictionary<String, String> {
            return adapt_length(length: 190)
        }
        if obj is  [Dictionary<String,String>] {
            return adapt_length(length: 280)
        }
        return adapt_length(length: 0.01)
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return adapt_length(length: 10)
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return adapt_length(length: 10)
    }
}

extension CNLiveMineAuthFormViewController {
    func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
        return UIImage(named: "mine_list_source_unusual_empty")
    }
    
    func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        return NSAttributedString(string: "您已添加此身份,请直接使用", attributes: [.font: Font_17,.foregroundColor: HexColor("#666666")!])
    }
}

typealias clickWithClickBlock = (_ view: UIView) -> Void
class MineAuthFormTableViewCell: UITableViewCell {
    
    lazy var mainView: UIImageView = {
        let view = UIImageView.init()
        view.backgroundColor = .white
        view.contentMode = .scaleAspectFill
        view.layer.cornerRadius = adapt_length(length: 10)
        view.layer.masksToBounds = true
        return view
    }()
    
    lazy var whiteView: UIView = {
        let view = UIView.init()
        view.backgroundColor = .white
        view.layer.masksToBounds = true
        view.layer.cornerRadius = adapt_length(length: 10)
        view.isUserInteractionEnabled = true
        view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickWithWhiteAction)))
        return view
    }()
    
    lazy var headerImageView: UIImageView = {
        let headerImageView = UIImageView.init()
        headerImageView.backgroundColor = .white
        headerImageView.contentMode = .scaleAspectFill
        headerImageView.layer.masksToBounds = true
        return headerImageView
    }()
    
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.tag = 1000
        titleLabel.textColor = HexColor("#333333")
        titleLabel.font = semibold_adapt_font(pointSize: 16)
        return titleLabel
    }()
    
    lazy var descLabel: UILabel = {
        let descLabel = UILabel.init()
        descLabel.textColor = HexColor("#999999")
        descLabel.font = regular_adapt_font(pointSize: 14)
        return descLabel
    }()
    
    lazy var whiteView01: UIView = {
        let view = UIView.init()
        view.backgroundColor = .white
        view.isHidden = true
        view.layer.masksToBounds = true
        view.layer.cornerRadius = adapt_length(length: 10)
        view.isUserInteractionEnabled = true
        view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickWithWhite01Action)))
        return view
    }()
    
    lazy var headerImageView01: UIImageView = {
        let headerImageView = UIImageView.init()
        headerImageView.backgroundColor = .white
        headerImageView.contentMode = .scaleAspectFill
        headerImageView.layer.masksToBounds = true
        return headerImageView
    }()
    
    lazy var titleLabel01: UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.tag = 1000
        titleLabel.textColor = HexColor("#333333")
        titleLabel.font = semibold_adapt_font(pointSize: 16)
        return titleLabel
    }()
    
    lazy var descLabel01: UILabel = {
        let descLabel = UILabel.init()
        descLabel.textColor = HexColor("#999999")
        descLabel.font = regular_adapt_font(pointSize: 12)
        return descLabel
    }()
    
    var clickBlock: clickWithClickBlock!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        selectionStyle = .none
        
        contentView.addSubview(mainView)
        mainView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.top.left.equalToSuperview().offset(10)
            make.bottom.right.equalToSuperview().offset(-10)
        }
        
        contentView.addSubview(whiteView)
        whiteView.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-adapt_length(length: 20))
            make.left.equalToSuperview().offset(adapt_length(length: 30))
            make.right.equalToSuperview().offset(-adapt_length(length: 30))
            make.height.equalTo(adapt_length(length: 80))
        }
        
        whiteView.addSubview(headerImageView)
        headerImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(adapt_length(length: 5))
            make.size.equalTo(adapt_length(length: 70))
        }
        whiteView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(headerImageView.snp.top).offset(adapt_length(length: 10))
            make.left.equalTo(headerImageView.snp.right).offset(adapt_length(length: 10))
            make.right.equalToSuperview().offset(-adapt_length(length: 10))
        }
        whiteView.addSubview(descLabel)
        descLabel.snp.makeConstraints { make in
            make.bottom.equalTo(headerImageView.snp.bottom).offset(-adapt_length(length: 10))
            make.left.equalTo(headerImageView.snp.right).offset(adapt_length(length: 10))
            make.right.equalToSuperview().offset(-adapt_length(length: 10))
        }
        
        contentView.addSubview(whiteView01)
        whiteView01.snp.makeConstraints { make in
            make.bottom.equalTo(whiteView.snp.top).offset(-adapt_length(length: 10))
            make.left.equalToSuperview().offset(adapt_length(length: 30))
            make.right.equalToSuperview().offset(-adapt_length(length: 30))
            make.height.equalTo(adapt_length(length: 80))
        }
        
        whiteView01.addSubview(headerImageView01)
        headerImageView01.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(adapt_length(length: 5))
            make.size.equalTo(adapt_length(length: 70))
        }
        whiteView01.addSubview(titleLabel01)
        titleLabel01.snp.makeConstraints { make in
            make.top.equalTo(headerImageView01.snp.top).offset(adapt_length(length: 10))
            make.left.equalTo(headerImageView01.snp.right).offset(adapt_length(length: 10))
            make.right.equalToSuperview().offset(-adapt_length(length: 10))
        }
        whiteView01.addSubview(descLabel01)
        descLabel01.snp.makeConstraints { make in
            make.bottom.equalTo(headerImageView01.snp.bottom).offset(-adapt_length(length: 10))
            make.left.equalTo(headerImageView01.snp.right).offset(adapt_length(length: 10))
            make.right.equalToSuperview().offset(-adapt_length(length: 10))
        }
    }
    
    @objc func clickWithWhiteAction() {
        self.clickBlock(whiteView)
    }
    
    @objc func clickWithWhite01Action() {
        self.clickBlock(whiteView01)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}