CNLiveVodCellBottomView.swift 5.35 KB
//
//  CNLiveVodCellBottomView.swift
//  metaCode
//
//  Created by zx on 2025/3/20.
//  看点展开View

import Foundation

typealias CNLiveVodTrailersExpandCellHidenBlock = ()->Void
typealias CNLiveVodTrailersExpandCellUpdateBlock = (_ selectIdx:Int,_ model:CNLiveVodPlayBlockListListModel,_ kanDianListArr:NSMutableArray)->Void


class CNLiveVodCellBottomView:UIView, UITableViewDataSource, UITableViewDelegate{
    var expandHideBlock:CNLiveVodTrailersExpandCellHidenBlock?//收起
    var updateBlock:CNLiveVodTrailersExpandCellUpdateBlock?//更新
    var selectIdx:Int = -1

    var _vodPlayBlockListModel : CNLiveVodPlayBlockListModel?
    var vodPlayBlockListModel : CNLiveVodPlayBlockListModel? {
        get{
            _vodPlayBlockListModel
        }
        set{
            _vodPlayBlockListModel = newValue!
            self.setupNewUI(model: vodPlayBlockListModel!)
        }
    }
    
    lazy var titleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = BoldFont_18
        titleLbl.textColor = HexColor("#000102")
        titleLbl.text = "看点"
        return titleLbl
    }()
    //more
    lazy var detailBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: 50, height: 24)
        expandBtn.setImage(UIImage(named: "home_player_expand"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_expand"), for: .highlighted)
        expandBtn.addTarget(self, action: #selector(detailBtnAction), for: .touchUpInside)
        return expandBtn
    }()
    let kCNLiveVodTrailerExpandCellIdentifier = "kCNLiveVodTrailerExpandCellIdentifier"

    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.register(CNLiveVodTrailerExpandCell.self, forCellReuseIdentifier: kCNLiveVodTrailerExpandCellIdentifier)
        tableView.backgroundColor = .white
        return tableView
    }()
    ///数据源
    lazy var dataArray: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()

    // MARK: - init
    init() {
        super.init(frame: CGRectZero)
        self.initializeThings()
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initializeThings()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initializeThings(){
        self.addSubview(self.titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(15)
            make.width.lessThanOrEqualToSuperview().offset(-80)
        }
        
        self.addSubview(self.detailBtn)
        detailBtn.snp.makeConstraints { make in
            make.top.equalTo(self.titleLabel.snp.top)
            make.width.equalTo(50)
            make.right.equalToSuperview()
            make.height.equalTo(24)
        }
        
        self.addSubview(tableView)
        tableView.frame = CGRect(x: 0, y: 55, width: KSreenWidth, height: self.height-55)
        tableView.backgroundColor = .white
    }
    
    func setupNewUI(model:CNLiveVodPlayBlockListModel){
        self.titleLabel.text = model.name
        self.dataArray = NSMutableArray(array: model.list)
        self.tableView.reloadData()
    }

    // MARK: - UITableViewDelegate
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count
    }
    // MARK: - UITableViewDelegate
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let historyModel = self.dataArray[indexPath.row] as? CNLiveVodPlayBlockListListModel{
            //看点
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodTrailerExpandCellIdentifier) as? CNLiveVodTrailerExpandCell
            else {
                let cell = CNLiveVodTrailerExpandCell()
                return cell
            }
            if self.selectIdx >= 0{
                if self.selectIdx == indexPath.row{
                    //当前cell选中
                    cell.isJiShuSelected = true
                }else{
                    //不选中
                    cell.isJiShuSelected = false
                }
            }else{
                //不选中
                cell.isJiShuSelected = false
            }

            cell.vodPlayBlockListListModel = historyModel
            return cell
        }
        return UITableViewCell()
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //刷新点播页面 ,选中当前cell
        self.selectIdx = indexPath.row

        if let historyModel = self.dataArray[indexPath.row] as? CNLiveVodPlayBlockListListModel{
            self.tableView.reloadData()
            self.updateBlock?(self.selectIdx,historyModel, self.dataArray)
        }
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 90
    }

    // MARK: - 收起看点
    @objc func detailBtnAction(){
        self.expandHideBlock?()
    }
}