CNLiveAlbumCell.swift 6.87 KB
//
//  CNLiveAlbumCell.swift
//  metaCode
//
//  Created by zx on 2024/1/8.
//

import Foundation
import QMUIKit

typealias CNLiveAlbumCellEnterBlock = (_ albumModel:CNLiveAlbumModel)->Void;

class CNLiveAlbumCell:UITableViewCell{
    
    var enterBlock:CNLiveAlbumCellEnterBlock?
    var albumModelArr:Array<CNLiveAlbumListModel>?
    
    var isDetail:Bool = false
    var cellType:CNLiveHomePageCellType = .course
    
    var _albumMsgModel : CNLiveAlbumMsgModel?
    var albumMsgModel : CNLiveAlbumMsgModel? {
        get{
            _albumMsgModel
        }
        set{
            _albumMsgModel = newValue!
            
            self.setupNewUIMsgModel(model: _albumMsgModel!, isDetail: self.isDetail)
        }
    }

    //AlbumModel
    var _albumModel : CNLiveAlbumModel?
    var albumModel : CNLiveAlbumModel? {
        get{
            _albumModel
        }
        set{
            _albumModel = newValue!
            
            self.setupNewUI(model: _albumModel!)
        }
    }
    //MARK: - 懒加载
    lazy var iconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 15, y: 15, width: 45, height: 45))
        iconImgView.layer.cornerRadius = 5
        iconImgView.clipsToBounds = true
        iconImgView.contentMode = .scaleAspectFill
        return iconImgView
    }()
    ///标题
    lazy var titleLabl: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, 15, KSreenWidth-(self.iconImgView.right+15)-80, 21))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.font = Font_15
        titleLabel.text = "标题"
        return titleLabel
    }()
    ///副标题
    lazy var subTitleLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.titleLabl.bottom+5, self.titleLabl.width, 17))
        titleLabel.textColor = HexColor("#999999")
        titleLabel.textAlignment = .left
        titleLabel.font = Font_12
        titleLabel.text = "共68集"
        return titleLabel
    }()
    let playBtnSubLayer = "playBtnSubLayer"
    lazy var playBtn: QMUIButton = {
        let playBtn = QMUIButton.init(type: .custom)
        playBtn.frame = CGRect(x: KSreenWidth-80, y: 0, width: 65, height: 26)
        playBtn.centerY = self.iconImgView.centerY
        playBtn.layer.cornerRadius = 13
        playBtn.clipsToBounds = true
        playBtn.setTitle("播放", for: .normal)
        playBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
        playBtn.titleLabel?.font = Font_13
        playBtn.addTarget(self, action: #selector(playBtnAction), for: .touchUpInside)
        
        let gradient = CAGradientLayer()
        gradient.frame = playBtn.bounds
        gradient.colors = [HexColor("#67C5FF")!.cgColor, HexColor("#609AFF")!.cgColor]
        gradient.locations = [0, 1]
        gradient.startPoint = CGPoint(x: 0, y: 0.5)
        gradient.endPoint = CGPoint(x: 0.5, y: 0.5)
        gradient.name = playBtnSubLayer
        playBtn.layer.insertSublayer(gradient, at: 0)
        return playBtn
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.contentView.addSubview(self.iconImgView)
        self.contentView.addSubview(self.titleLabl)
        self.contentView.addSubview(self.subTitleLabel)
        self.contentView.addSubview(self.playBtn)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupNewUI(model:CNLiveAlbumModel){
        if model.model == kCNDownSlideContentsModelModel1 || model.model == kCNDownSlideContentsModelModel2 || model.model == kCNDownSlideContentsModelModel3 || model.model == kCNDownSlideContentsModelModel4{
            //课程-跳转h5网页
            self.cellType = .course
            self.playBtn.setTitle("进入", for: .normal)
        }else if model.model == kCNDownSlideContentsModelModelAlbum_ugc{
            //短剧-跳转短剧播放页
            self.cellType = .playlet
            self.playBtn.setTitle("播放", for: .normal)
        }else if model.model == kCNDownSlideContentsModelModelServing{
            self.cellType = .course
            self.playBtn.setTitle("进入", for: .normal)
        }else if model.model == kCNDownSlideContentsModelModelAlbum_video{
            self.cellType = .courseToMyCurriculum
            self.playBtn.setTitle("进入", for: .normal)
        }else{
            
        }
        self.titleLabl.text = model.title
        self.subTitleLabel.text = model.subTitle
        self.iconImgView.kf.setImage(with: URL(string: model.poster))
        self.titleLabl.width = KSreenWidth-(self.iconImgView.right+15)-80
        self.subTitleLabel.width = self.titleLabl.width
        self.playBtn.left = KSreenWidth-80
    }
    func setupNewUIMsgModel(model:CNLiveAlbumMsgModel,isDetail:Bool){
        
        //在追短剧model
        self.titleLabl.text = model.albumName
        self.subTitleLabel.text = model.desc
        self.iconImgView.kf.setImage(with: URL(string: model.albumImg))
        self.titleLabl.width = KSreenWidth-(self.iconImgView.right+15)-80-30
        self.subTitleLabel.width = self.titleLabl.width
        if self.isDetail{
            self.playBtn.left = KSreenWidth-80
        }else{
            self.playBtn.left = KSreenWidth-80-30
        }
    }
  
    @objc func playBtnAction(){
        
        var aid = ""
        if self.albumModel != nil{
            aid = self.albumModel!.contentId
        }else if self.albumMsgModel != nil{
            aid = self.albumMsgModel!.albumId
        }else{
            aid = ""
        }
        if (self.albumModel != nil){
            if (self.albumModel?.model == kCNDownSlideContentsModelModel1 || self.albumModel?.model == kCNDownSlideContentsModelModel2 || self.albumModel?.model == kCNDownSlideContentsModelModel3 || self.albumModel?.model == kCNDownSlideContentsModelModel4){
                //课程-跳转h5网页
                self.enterBlock!(self.albumModel!)
            }else if self.albumModel?.model == kCNDownSlideContentsModelModelAlbum_ugc{
                //短剧-跳转短剧播放页
                CNLiveDownSlideTool.pushShortVideoController(contentId: aid, navigationVC: navigationViewController().visibleViewController?.navigationController, slideModel: nil)
            }else if self.albumModel?.model == kCNDownSlideContentsModelModelAlbum_video{
                //课程-跳转h5视频专辑页
                self.enterBlock!(self.albumModel!)
            }else{
                
            }
        }else if (self.albumMsgModel != nil){
            //短剧-跳转短剧播放页
            CNLiveDownSlideTool.pushShortVideoController(contentId: aid, navigationVC: navigationViewController().visibleViewController?.navigationController, slideModel: nil)

        }
        
    }
}