CNLiveMineBindingManagerController.swift 2.85 KB
//
//  CNLiveMineBindingManagerController.swift
//  metaCode
//
//  Created by zx on 2024/4/26.
//

import Foundation
import SnapKit

class CNLiveMineBindingManagerController:CNLiveBaseViewController, UITableViewDataSource, UITableViewDelegate{
    
    let kCNBindingManageCellIdentifier = "kCNBindingManageCellIdentifier"

    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.register(CNBindingManageCell.self, forCellReuseIdentifier: kCNBindingManageCellIdentifier)
        tableView.backgroundColor = HexColor("#f4f4f4")
        return tableView
    }()
    
    ///数据源
    lazy var unBindingData: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
        navigationBarHidden = false
        titleName = "绑定管理"
        
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.bottom.left.right.equalToSuperview()
            make.top.equalTo(KNavigationHeight)
        }
        self.loadData()
    }
    
    deinit {
        
    }
    
    func loadData(){
        CNLiveMineViewModel.requestModels {[weak self] unBindingArr in
            let unbingArr = unBindingArr as! NSMutableArray
            self!.unBindingData = NSMutableArray(array: unbingArr)
            self!.tableView.reloadData()
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.unBindingData.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNBindingManageCellIdentifier) as? CNBindingManageCell
        else {
            return CNBindingManageCell()
        }
        let bindModel = self.unBindingData[indexPath.row] as! CNBindingManageModel
        cell.bindModel = bindModel
        cell.finishBlock = { status in
            if status == .success{
                self.loadData()
            }else{
                
            }
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        85
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0{
            //跳转绑定手机号页面
            self.navigationController?.pushViewController(CNLiveMineChangePhoneController(), animated: true)
        }
    }
}