CNLiveHomeLanmuThreeImgCell.swift 4.51 KB
//
//  CNLiveHomeLanmuThreeImgCell.swift
//  metaCode
//
//  Created by zx on 2025/3/11.
//  一行3竖图,title subTitle
import Foundation

class CNLiveHomeLanmuThreeImgCell: UITableViewCell {

    //slideModel
    var _slideModel : [CNLiveAlbumModel]?
    var slideModel : [CNLiveAlbumModel]? {
        get{
            _slideModel
        }
        set{
            _slideModel = newValue!

            setupNewUI(model: _slideModel!)
        }
    }
    

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        contentView.backgroundColor = .white
        contentView.clipsToBounds = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupNewUI(model:[CNLiveAlbumModel]){
        //根据models.contents创建cell 1-3个竖版图
        for (idx,mdl) in model.enumerated(){
            let leftPadding:CGFloat = 15.0
            let imgW:CGFloat = (KSreenWidth-60.0)/3.0
            let imgH:CGFloat = imgW*140.0/105.0
            let x:CGFloat = leftPadding+(imgW+15.0)*CGFloat(idx)
            let y:CGFloat = 10.0
            let imageView = UIImageView(frame: CGRectMake(x, y, imgW, imgH))
            imageView.kf.setImage(with: URL(string:mdl.verticalImg.count > 0 ? mdl.verticalImg : mdl.poster))
            imageView.tag = idx
            imageView.layer.cornerRadius = 9
            imageView.clipsToBounds = true
            imageView.contentMode = .scaleAspectFill
            imageView.isUserInteractionEnabled = true
            imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
            contentView.addSubview(imageView)
            
            let grayBgView = UIView(frame: CGRect(x: imageView.left, y: imageView.bottom, width: imageView.width, height: grayH))
            grayBgView.backgroundColor = HexColor("#FAFAFA")
            grayBgView.addCorner(conrners:[.bottomLeft,.bottomRight], radius: 9)
            grayBgView.clipsToBounds = true
            contentView.addSubview(grayBgView)

            let payIconView = UIImageView()
            payIconView.image = UIImage(named: "home_player_pay")
            payIconView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
            imageView.addSubview(payIconView)
            
            let isPaid = CNLivePlayerTool.isShowPaidIcon(product: mdl.product)
            if isPaid{
                payIconView.isHidden = false
            }else{
                payIconView.isHidden = true
            }
            
//            if mdl.product?.productType == "2" || mdl.product?.productType == "5"{//付费
//                payIconView.isHidden = false
//            }else{
//                if mdl.product?.check == true {
//                    //免费或者付过费了
//                    payIconView.isHidden = true
//                } else {
//                    if mdl.product?.productType == "4" {
//                        //这里表示可以进行试听
//                        payIconView.isHidden = true
//                    } else {
//                        payIconView.isHidden = true
//                    }
//                }
//            }

            
            let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+5, width: imageView.width, height: 20))
            titleLbl.font = BoldFont_14
            titleLbl.textColor = HexColor("#333333")
            titleLbl.text = mdl.title
            contentView.addSubview(titleLbl)

            let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom+3, width: titleLbl.width, height: 17))
            subTitleLbl.font = Font_12
            subTitleLbl.textColor = HexColor("#999999")
            subTitleLbl.text = mdl.subTitle
            contentView.addSubview(subTitleLbl)

        }
        
    }
    
    @objc func detailBtnAction(){
        
    }
    
    @objc func imgTapAction(ges: UITapGestureRecognizer){
        showLoading(message: "")
        let imageView = ges.view as! UIImageView
        let i = imageView.tag
        if let contentMdl = self.slideModel?[i]{
            CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: contentMdl.model , contentId: contentMdl.contentId , pid: contentMdl.pid , shareUrl: contentMdl.shareUrl , thirdUrl: contentMdl.thirdUrl , title: contentMdl.title , s_to: contentMdl.s_to ,trailerId: contentMdl.trailerId , controller: nil, slideModel: nil)
        }
    }
    
}