CNLiveMineViewController.swift 6.11 KB
//
//  CNLiveMineViewController.swift
//  metaCode
//
//  Created by open on 2023/6/6.
//

import Foundation


class CNLiveMineViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource{
    
    let kCNLiveMineOneViewCellIdentifier = "kCNLiveMineOneViewCellIdentifier"
    let kCNLiveMineTwoViewCellIdentifier = "kCNLiveMineTwoViewCellIdentifier"
    let kMineBodyThreeViewCellIdentifier = "kMineBodyThreeViewCellIdentifier"
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .grouped)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.backgroundColor = .clear
        tableView.tableFooterView = UIView.init()
        tableView.separatorStyle = .none
        tableView.register(MineBodyOneListViewCell.self, forCellReuseIdentifier: kCNLiveMineOneViewCellIdentifier)
        tableView.register(MineBodyTwoListViewCell.self, forCellReuseIdentifier: kCNLiveMineTwoViewCellIdentifier)
        tableView.register(MineBodyThreeViewCell.self, forCellReuseIdentifier: kMineBodyThreeViewCellIdentifier)
        return tableView
    }()
    
    lazy var mainView: UIImageView = {
        let mainView = UIImageView.init()
        mainView.backgroundColor = .clear
        mainView.image = UIImage(named: "mine_header_icon_back")
        mainView.contentMode = .scaleAspectFill
        return mainView
    }()
    
    lazy var dataArray: NSMutableArray = {
        let dataArray = NSMutableArray()
        dataArray.add([""])
        let array01 : [Dictionary] = [["name":"我的身份","icon":"mine_header_icon_identity"]]
        dataArray.add(array01)
        let array02 : [Dictionary] = [["name":"添加身份","icon":"mine_list_icon_add_identity"]]
        dataArray.add(array02)
        let array03 : [Dictionary] = [["name":"帮助与反馈","icon":"mine_list_icon_help_feedback"],
                                     ["name":"更多设置","icon":"mine_list_icon_set_more"]]
        dataArray.add(array03)
        return dataArray
    }()
    
    lazy var headerView: MineHeaderView = {
        let headerView = MineHeaderView.init(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 80))
        return headerView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = HexColor("#f9f9f9")
        setNeedsStatusBarAppearanceUpdate()
        
        view.addSubview(mainView)
        mainView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(KSreenHeight * 0.4)
        }
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        headerView.updateHeaderView()
        tableView.reloadData()
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
      return .lightContent
    }
    
    deinit {
        
    }
}

extension CNLiveMineViewController {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return dataArray.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (dataArray[section] as AnyObject).count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 {
            let cell = tableView.dequeueReusableCell(withIdentifier: kMineBodyThreeViewCellIdentifier) as! MineBodyThreeViewCell
            
            return cell
        }
        if indexPath.section == 1 {
            let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineOneViewCellIdentifier) as! MineBodyOneListViewCell
            cell.reloadWithData()
            return cell
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineTwoViewCellIdentifier) as! MineBodyTwoListViewCell
        let array = dataArray[indexPath.section]
        let sub_dict = (array as! Array<Any>)[indexPath.row]
        cell.setupWithDataSource(show_type: .feedback,dict: sub_dict as! Dictionary<String, Any>)
        return cell

    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 {
            return 100
        }
        if indexPath.section == 1 {
            return 120
        }
        return 60
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 0 {
            self.navigationController?.pushViewController(CNLiveMineQuestViewController.init(), animated: true)
        }
        if indexPath.section == 1 {
            self.navigationController?.pushViewController(CNLiveMineAddInfoViewController.init(show_type: .info), animated: true)
        }
        if indexPath.section == 2 {
            self.navigationController?.pushViewController(CNLiveMineAddInfoViewController.init(show_type: .add), animated: true)
        }
        if indexPath.section == 3 && indexPath.row == 0 {
            self.navigationController?.pushViewController(CNLiveHelpFeedBackViewController.init(), animated: true)
        }
        if indexPath.section == 3 && indexPath.row == 1 {
            self.navigationController?.pushViewController(CNLiveTypeFeedBackViewController.init(show_type: .setting), animated: true)
        }
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 150
        }
        return 0.001

    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if section == 0 {
            return headerView
        }
        return UIView.init()

    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let offsetY = scrollView.contentOffset.y
        mainView.snp.updateConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(offsetY < 0 ? (KSreenHeight * 0.4) + abs(offsetY) : KSreenHeight * 0.4)
        }
    }
}