CNLiveHomePageDuanJuCell.swift 4.63 KB
//
//  CNLiveHomePageDuanJuCell.swift
//  metaCode
//
//  Created by zx on 2024/1/8.
//  首页-在追短剧cell

import Foundation
import QMUIKit

typealias DuanJUCellSelectedCallBackBlock = (_ cell: CNLiveHomePageDuanJuCell) -> Void

class CNLiveHomePageDuanJuCell:UITableViewCell,UITableViewDelegate,UITableViewDataSource{
    let kCNLiveAlbumCellIdentifier = "kCNLiveAlbumCellIdentifier"
//    let bgBackView = UIView()

    var DuanJUCellSelectedCallBack:DuanJUCellSelectedCallBackBlock?
    lazy var modelArr: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()
    func setModelArr(modelArr:NSMutableArray){
        self.modelArr = NSMutableArray(array: modelArr)
        
        self.tableView.height = CGFloat(self.modelArr.count)*(45+15*2)
        self.totalView.height = CGFloat(self.modelArr.count)*(45+15*2) + 55
        self.tableView.reloadData()
        
//        //定义view的阴影颜色
//        self.totalView.layer.shadowColor = UIColor.black.cgColor
//        //阴影偏移量
//        self.totalView.layer.shadowOffset=CGSize(width:1, height:1)
//        //定义view的阴影宽度,模糊计算的半径
//        self.totalView.layer.shadowRadius = 12
//        //定义view的阴影透明度,注意:如果view没有设置背景色阴影也是不会显示的
//        self.totalView.layer.shadowOpacity = 0.4

    }
    //MARK: - 懒加载
    ///区块标题
    lazy var blockTitleLabl: UILabel = {
        let titleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: DownSlideRecommendLeftGap+5, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 30))
        titleLbl.text = "在追短剧"
        titleLbl.font = BoldFont_21
        titleLbl.textColor = HexColor("#333333")
        return titleLbl
    }()
    lazy var totalView : UIView = {
        let totalView = UIView(frame: CGRect(x: 15, y: 15, width: KSreenWidth-30, height: 100))
        return totalView
    }()

    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: CGRect(x: 0, y: self.blockTitleLabl.bottom+5, width: KSreenWidth-30, height: 50), style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.tableFooterView = UIView.init()
        tableView.backgroundColor = .clear
        tableView.register(CNLiveAlbumCell.self, forCellReuseIdentifier: kCNLiveAlbumCellIdentifier)
        return tableView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none

        self.contentView.addSubview(self.totalView)
        
        self.totalView.addSubview(self.blockTitleLabl)
        self.totalView.addSubview(self.tableView)
        self.tableView.backgroundColor = .white
        self.totalView.layer.cornerRadius = 12
        self.totalView.clipsToBounds = true
        self.totalView.backgroundColor = .white
        
        //定义view的阴影颜色
        self.totalView.layer.shadowColor = UIColor.black.cgColor
        //阴影偏移量
        self.totalView.layer.shadowOffset=CGSize(width:1, height:1)
        //定义view的阴影宽度,模糊计算的半径
        self.totalView.layer.shadowRadius = 12
        //定义view的阴影透明度,注意:如果view没有设置背景色阴影也是不会显示的
        self.totalView.layer.shadowOpacity = 0.4
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        contentView.backgroundColor =  HexColor(kCNDownSlideBackgroundColorHex)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        self.modelArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let model = self.modelArr[indexPath.row] as! CNLiveAlbumMsgModel
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveAlbumCellIdentifier) as? CNLiveAlbumCell
        else {
            let cell = CNLiveAlbumCell()
            return cell
        }
        cell.albumMsgModel = model

        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.DuanJUCellSelectedCallBack!(self)
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 45+15*2
    }
    //MARK: - 事件
    @objc func playBtnAction(){
        showLoading(message: "")
//        self.getAlbumList()
    }
}