CNLiveDigitalAssetsController.swift 4.92 KB
//
//  CNLiveDigitalAssetsController.swift
//  metaCode
//
//  Created by zx on 2024/6/17.
//  我的数字资产页面

import Foundation

class CNLiveDigitalAssetsController:CNLiveBaseViewController, UITableViewDataSource, UITableViewDelegate{
    
    lazy var nextBtn: UIButton = {
        let  nextBtn = UIButton(type: .custom)
        nextBtn.setTitle("培训就业指南", for: .normal)
        nextBtn.setTitleColor(.white, for: .normal)
        nextBtn.titleLabel?.font = Font_17
        nextBtn.backgroundColor = HexColor("#1961FE")
        nextBtn.layer.cornerRadius = 22
        nextBtn.clipsToBounds = true
        nextBtn.addTarget(self, action: #selector(nextBtnAction), for: .touchUpInside)
        return nextBtn
    }()
    
    let kCNLiveDigitalFirstCellIdentifier = "kCNLiveDigitalFirstCellIdentifier"
    let kCNLiveDigitalSecCellIdentifier = "kCNLiveDigitalSecCellIdentifier"
    
    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(CNLiveDigitalFirstCell.self, forCellReuseIdentifier: kCNLiveDigitalFirstCellIdentifier)
        tableView.register(CNLiveDigitalSecCell.self, forCellReuseIdentifier: kCNLiveDigitalSecCellIdentifier)
        
        return tableView
    }()
    lazy var dataArray: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarHidden = false
        titleName = "元码数字认证"
        
        self.initUI()
        self.loadData()
    }
    
    func initUI(){
        //背景图
        let layerView = UIView()
        layerView.frame = CGRect(x: 0, y: KNavigationHeight, width:KSreenWidth, height: adapt_length(length: 234))
        // fillCode
        let bgLayer1 = CAGradientLayer()
        bgLayer1.colors = [UIColor(red: 0.16, green: 0.45, blue: 0.99, alpha: 1).cgColor, UIColor(red: 0.96, green: 0.96, blue: 0.98, alpha: 1).cgColor]
        bgLayer1.locations = [0, 1]
        bgLayer1.frame = layerView.bounds
        bgLayer1.startPoint = CGPoint(x: 0.5, y: 0)
        bgLayer1.endPoint = CGPoint(x: 1, y: 1)
        layerView.layer.addSublayer(bgLayer1)
        view.addSubview(layerView)
        
        view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(KNavigationHeight)
            make.bottom.equalToSuperview().offset(adapt_length(length: -59))
        }
        self.tableView.backgroundColor = .clear
        
        self.view.addSubview(self.nextBtn)
        self.nextBtn.snp.makeConstraints { make in
            make.top.equalTo(self.tableView.snp.bottom).offset(adapt_length(length: 10))
            make.height.equalTo(adapt_length(length: 44))
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
        }
    }
    
    func loadData(){
        CNLiveMineViewModel.requestsGETAuthInfoList(page: 1) { [weak self] result, respStatue in
            if respStatue == .success {
                let listBaseModel = result as! MineAuthListBaseModel
                if self != nil{
                    self!.dataArray.addObjects(from: listBaseModel.list)
                    self!.dataArray.add(MineAuthListModel())
                    self!.tableView.reloadData()
                }
            }else {

            }
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0{
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDigitalFirstCellIdentifier) as? CNLiveDigitalFirstCell
            else {
                let cell = CNLiveDigitalFirstCell()
                return cell
            }
            return cell
        }else{
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDigitalSecCellIdentifier) as? CNLiveDigitalSecCell
            else {
                let cell = CNLiveDigitalSecCell()
                cell.digitalListModels = self.dataArray as? [MineAuthListModel]
                return cell
            }
            cell.digitalListModels = self.dataArray as? [MineAuthListModel]
            return cell
        }
        
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 0{
            return adapt_length(length: 121+20)
        }else{
            return adapt_length(length: 838+15)
        }
        
    }
    deinit {
        
    }
    
    @objc func nextBtnAction(){
        showMessage(message: "此功能对您暂未开放")
    }
}