CNLiveIdentityRepositoryController.swift 15.5 KB
//
//  CNLiveIdentityRepositoryController.swift
//  metaCode
//
//  Created by zx on 2024/6/24.
//  身份大库 页面

import Foundation
import SnapKit

class CNLiveIdentityRepositoryController:CNLiveBaseViewController,UITableViewDataSource,UITableViewDelegate{
    
    var currentSeleIndex = -1
    var currentSeleCollectionIndex = -1
    var channelId:String = "0"
    var currCollectMdl:MineAuthenticationsChildIdentitiesModel?
    
    //2级行业数组
    lazy var dataArray :NSMutableArray = {
        let dataArray = NSMutableArray()
        return dataArray
    }()
    
    //所有数据 ,1级行业数组
    var totalFirstChildsArr = Array<MineAuthenticationsChildModel>()
    
    let kCNLiveIdentityRespositoryCellIdentifier = "kCNLiveIdentityRespositoryCellIdentifier"
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.tableFooterView = UIView.init()
        tableView.register(CNLiveIdentityResTableCell.self, forCellReuseIdentifier: kCNLiveIdentityRespositoryCellIdentifier)
        tableView.backgroundColor = .clear
        return tableView
    }()
    
    lazy var zhinanBtn: UIButton = {
        let  nextBtn = UIButton(type: .custom)
        nextBtn.setTitle("就业指南", for: .normal)
        nextBtn.setTitleColor(.white, for: .normal)
        nextBtn.backgroundColor = HexColor("#1961FE")
        nextBtn.layer.cornerRadius = 39.0/2
        nextBtn.clipsToBounds = true
        nextBtn.addTarget(self, action: #selector(zhinanBtnAction), for: .touchUpInside)
        return nextBtn
    }()

    lazy var bottomTotalView :UIView = {
        let bottomNavView = UIView(frame: CGRect(x: 0, y: KSreenHeight-189, width: KSreenWidth, height: 189))
        bottomNavView.backgroundColor = .white
        bottomNavView.layer.cornerRadius = 16
        bottomNavView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
        // shadowCode
        bottomNavView.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
        bottomNavView.layer.shadowOffset = CGSize(width: 0, height: 0)
        bottomNavView.layer.shadowOpacity = 1
        bottomNavView.layer.shadowRadius = 10
        
        bottomNavView.addSubview(self.iconImgView)
        self.iconImgView.addSubview(self.rightIconImgView)
        bottomNavView.addSubview(self.seleTitleLabel)
        bottomNavView.addSubview(self.tishiTitleLabel)
        bottomNavView.addSubview(self.buXuanZeBtn)
        bottomNavView.addSubview(self.xuanZeBtn)
        
        return bottomNavView
    }()
    lazy var iconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 20, y: 20, width: 50, height: 50))
        iconImgView.contentMode = .scaleAspectFill
        iconImgView.clipsToBounds = true
        return iconImgView
    }()
    lazy var rightIconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: self.iconImgView.width-15, y: self.iconImgView.height-15, width: 15, height: 15))
        iconImgView.image = UIImage(named: "auth_selected")
        return iconImgView
    }()
    lazy var seleTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(0, self.iconImgView.bottom+1, 90, 17))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .center
        titleLabel.font = BoldFont_12
        return titleLabel
    }()
    lazy var tishiTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(0, 107, 300, 21))
        titleLabel.centerX = KSreenWidth / 2
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .center
        titleLabel.text = "身份选择后不可修改"
        titleLabel.font = BoldFont_12
        return titleLabel
    }()
    lazy var buXuanZeBtn: UIButton = {
        let  closeBtn = UIButton(type: .custom)
        closeBtn.frame = CGRect(x: 15, y: 135, width: (KSreenWidth-30)/2, height: 39)
        closeBtn.layer.cornerRadius = 21
        closeBtn.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner]
        closeBtn.layer.borderColor = HexColor("#1961FE")?.cgColor
        closeBtn.layer.borderWidth = 0.45
        closeBtn.backgroundColor = .white
        closeBtn.setTitle("暂不选择", for: .normal)
        closeBtn.setTitleColor(HexColor("#1961FE"), for: .normal)
        closeBtn.titleLabel?.font = Font_17
        closeBtn.addTarget(self, action: #selector(buXuanZeBtnAction), for: .touchUpInside)
        return closeBtn
    }()
    lazy var xuanZeBtn: UIButton = {
        let  closeBtn = UIButton(type: .custom)
        closeBtn.frame = CGRect(x: 15+(KSreenWidth-30)/2, y: 135, width: (KSreenWidth-30)/2, height: 39)
        closeBtn.layer.cornerRadius = 21
        closeBtn.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]
//        closeBtn.layer.borderColor = HexColor("#1961FE")?.cgColor
//        closeBtn.layer.borderWidth = 0.45
        closeBtn.backgroundColor = HexColor("#1961FE")
        closeBtn.setTitle("选好了", for: .normal)
        closeBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
        closeBtn.titleLabel?.font = Font_17
        closeBtn.addTarget(self, action: #selector(xuanZeBtnAction), for: .touchUpInside)
        return closeBtn
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.currentSeleIndex = -1
        self.currentSeleCollectionIndex = -1
        self.tableView.reloadData()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
        navigationBarHidden = false
        titleName = "教育培训"
        let vsid = UserInfoManager.shared.userInfo.currentUser?.vsid ?? ""
        let sid = UserInfoManager.shared.userInfo.uid
        self.getAuthenticationsApi(vsid: vsid, sid: sid)
        
        self.initUI()
        let deleteNavBtn = UIButton(type: .custom)
        deleteNavBtn.frame = CGRect(x: 0, y: KStatusBarHeight, width: 80, height: KNavigationHeight-KStatusBarHeight)
        deleteNavBtn.backgroundColor = .clear
        deleteNavBtn.setTitle("切换行业", for: .normal)
        deleteNavBtn.setTitleColor(HexColor("#1961FE"), for: .normal)
        deleteNavBtn.titleLabel?.font = Font_13
//        deleteNavBtn.setImage(UIImage(named: "auth_shuaxin"), for: .normal)
//        deleteNavBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
        deleteNavBtn.addTarget(self, action: #selector(changeNavBtnClick), for: .touchUpInside)
        self.rightNavBtns = [deleteNavBtn]
    }
    
    func initUI(){
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.top.equalTo(KNavigationHeight)
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-59)
        }
        
        self.view.addSubview(self.zhinanBtn)
        self.zhinanBtn.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-10)
            make.height.equalTo(39)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
        
        self.view.addSubview(self.bottomTotalView)
        self.bottomTotalView.isHidden = true
    }
    
    deinit {
        
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveIdentityRespositoryCellIdentifier) as? CNLiveIdentityResTableCell
        else {
            let cell = CNLiveIdentityResTableCell()
            return cell
        }

        if self.currentSeleIndex == indexPath.row{
            cell.tblCellIsSelect = true
        }else{
            cell.tblCellIsSelect = false
        }
        cell.currentSeleIndex = self.currentSeleCollectionIndex
        let model = self.dataArray[indexPath.row] as! MineAuthenticationsChildModel
        cell.childModel = model
        cell.selectBlock = {[weak self] currCell,identitiesId in
            if let idxPath = self?.tableView.indexPath(for: currCell){
                self!.currentSeleIndex = idxPath.row
                self!.currentSeleCollectionIndex = currCell.currentSeleIndex
                self!.channelId = identitiesId
                self!.tableView.reloadData()
                let idMdl = currCell.threeArr[currCell.currentSeleIndex]
                self!.currCollectMdl = idMdl
                self!.iconImgView.kf.setImage(with: URL(string: idMdl.icon),placeholder: UIImage(named: "auth_shenfen"))
                self!.seleTitleLabel.text = idMdl.name
                self!.bottomTotalView.isHidden = false
                self!.tishiTitleLabel.text = idMdl.name+"身份选择后不可修改"
            }
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 161
    }
    
    @objc func changeNavBtnClick(){
        var infoArr = Array<String>()
        self.totalFirstChildsArr.forEach { childModel in
            let childMdl = childModel
            infoArr.append(childMdl.name)
        }
        
        
        MineStandListAlertView.showStandListView(infos: infoArr as NSArray,name: "行业切换", show_type: .string, isAddPerson: false) {text in
            let seleText = text as? String
            let tempArr = self.totalFirstChildsArr 
            tempArr.forEach({ userMdl in
                if userMdl.name == seleText{
                    //找到1级行业
                    self.dataArray = NSMutableArray(array: userMdl.child)
                    self.tableView.reloadData()
                    self.titleName = userMdl.name
                }
            })
        }
    }
    
    @objc func zhinanBtnAction(){
        //弹窗
        self.show17Alert()
    }
    
    let delegate = UIApplication.shared.delegate as! AppDelegate
    /// 未认证-inputType17时弹窗背景图
    lazy var alertBgImgView:UIImageView = {
        let alertBgImgView:UIImageView = UIImageView()
        alertBgImgView.tag = 20001
        alertBgImgView.isUserInteractionEnabled = true
        let ges = UITapGestureRecognizer(target: self, action: #selector(alertBgImgViewClickAction))
        alertBgImgView.addGestureRecognizer(ges)

        return alertBgImgView
    }()
    lazy var alertBgView:UIView = {
        let alertBgView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: KSreenHeight))
        alertBgView.backgroundColor = HexColor("#000000")
        alertBgView.alpha = 0.6
        alertBgView.isUserInteractionEnabled = true
        alertBgView.tag = 20000
        
        let ges = UITapGestureRecognizer(target: self, action: #selector(alertBgViewClickAction))
        alertBgView.addGestureRecognizer(ges)

        return alertBgView
    }()
    // MARK: - 点击弹窗,按类型跳转
    @objc func alertBgImgViewClickAction() {
        self.hiden17Alert()
    }
    @objc func alertBgViewClickAction() {
        //点击蒙版隐藏view
        self.hiden17Alert()
    }

    //弹出弹窗
    func show17Alert(){
        
        delegate.window?.addSubview(self.alertBgView)
        delegate.window?.addSubview(self.alertBgImgView)
        alertBgImgView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
            make.width.equalTo(KSreenWidth-80)
            make.height.equalTo((KSreenWidth-80)*170.5/295)
        }
        
        self.alertBgImgView.image = UIImage(named: "auth_alert_unOpen")
    }
    func hiden17Alert(){
        delegate.window?.subviews.forEach({ view in
            if view.tag >= 20000{
                view.removeFromSuperview()
            }
        })
    }
    
    // MARK: - 暂不选择 按钮
    @objc func buXuanZeBtnAction(){
        self.bottomTotalView.isHidden = true
        self.currentSeleIndex = -1
        self.currentSeleCollectionIndex = -1
        self.tableView.reloadData()
    }
    // MARK: - 选好了 按钮
    @objc func xuanZeBtnAction(){
        if self.currCollectMdl?.userAuth == 0{//正在审核
            showMessage(message: "您已认证过该身份,不能重复认证")
            return
        }else if self.currCollectMdl?.userAuth == 1{//审核成功
            //进入身份认证页面
            self.bottomTotalView.isHidden = true
            
        }else if self.currCollectMdl?.userAuth == -1{//审核失败
//                showMessage(message: "审核失败")
            self.bottomTotalView.isHidden = true
        }else{
            self.bottomTotalView.isHidden = true
        }
        if self.currCollectMdl?.auth == true{
            //身份需要实名认证
            if UserInfoManager.shared.userInfo.userMsgUsers?.verifyUsers.count ?? 0 > 0{
                //实名认证过->身份管理页面
                let listModel = StandListModel()
                listModel.id = Int(self.currCollectMdl?.id ?? "0")!
                listModel.name = ""
                let vc = CNLiveDigitalRealManageController()
                vc.listModel = listModel
                self.navigationController?.pushViewController(vc, animated: true)
            }else{
                //未实名认证->实名认证
                let vc = CNLiveRealNameAuthController()
                vc.channelId = self.currCollectMdl?.id ?? ""
                self.navigationController?.pushViewController(vc, animated: true)
            }
        }else{
            //身份不需要实名
            //跳转到身份认证页面
            let listModel = StandListModel()
            listModel.id = Int(self.currCollectMdl?.id ?? "0") ?? 0
            self.navigationController?.pushViewController(CNLiveMineInputViewController.init(listModel: listModel, authType: .person), animated: pushAnimated)
        }
    }
    
    //行业认证列表
    func getAuthenticationsApi(vsid:String,sid:String)
    {
        showLoading(message: "")
        CNLiveMineViewModel.requestsIndustryInfo(channelId: "", type: "1", sid: sid, vsid: vsid) { result, respStatue in
            if respStatue == .success{
                if let res = result as? [MineAuthenticationsChildModel]{
                    //添加每个MineAuthenticationsBaseModel到self.dataArray对应的 频道列表model里
                    
                    if res.count > 0{
                        //所有二级行业
                        var totalTwoChildsArr = Array<MineAuthenticationsChildModel>()
                        let twoChildModels = res.first
                        twoChildModels?.child.forEach { twoChildModel in
                            totalTwoChildsArr.append(twoChildModel)
                        }

                        self.totalFirstChildsArr = Array(res) as! [MineAuthenticationsChildModel]
                        self.dataArray = NSMutableArray(array: totalTwoChildsArr)
                        self.tableView.reloadData()
                        
                        self.titleName = twoChildModels?.name ?? ""
                    }else{
                        //没有行业列表 ,提示暂无内容
//                        self.show17Alert()
                    }
                }
            }else{
                
            }
        }
    }

}