CNLivePlayletHomePageCell.swift 4.62 KB
//
//  CNLivePlayletHomePageCell.swift
//  metaCode
//
//  Created by zx on 2024/1/4.
//

import Foundation
import QMUIKit
import Kingfisher
class CNLivePlayletHomePageCell:UITableViewCell{
    
    var _albumListModel : CNLiveAlbumListModel?
    var albumListModel : CNLiveAlbumListModel? {
        get{
            _albumListModel
        }
        set{
            _albumListModel = newValue!
            
            self.setupNewUI(model: _albumListModel!)
        }
    }
    //MARK: - 懒加载
    lazy var iconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 15, y: 12, width: 57, height: 75))
        iconImgView.layer.cornerRadius = 5
        iconImgView.contentMode = .scaleAspectFill
        iconImgView.clipsToBounds = true
        return iconImgView
    }()
    lazy var payIconImgView :UIImageView = {
        let payIconImgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 14))
        payIconImgView.image = UIImage(named: "homePage_payed")
        return payIconImgView
    }()
    
    ///标题
    lazy var titleLabl: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.iconImgView.top, KSreenWidth-(self.iconImgView.right+15)-10, 21))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.font = Font_13
        titleLabel.numberOfLines = 2
        titleLabel.text = "视频标题"
        let height = titleLabel.qmui_lineHeight
        titleLabel.height = height*2
        return titleLabel
    }()
    ///时长
    lazy var timeLabel: UILabel = {
        let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+15, self.iconImgView.bottom-21, 150, 21))
        titleLabel.textColor = HexColor("#333333")
        titleLabel.textAlignment = .left
        titleLabel.font = Font_12
        titleLabel.text = "04:31"
        let height = titleLabel.qmui_lineHeight
        titleLabel.height = height
        return titleLabel
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.addSubview(self.iconImgView)
        self.iconImgView.addSubview(self.payIconImgView)
        self.addSubview(self.titleLabl)
        self.addSubview(self.timeLabel)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupNewUI(model:CNLiveAlbumListModel){
        self.titleLabl.text = model.title
        self.timeLabel.text = model.duration
        self.iconImgView.kf.setImage(with: URL(string: model.poster))
        
        let isPaid = CNLivePlayerTool.isShowPaidIcon(product: model.product)
        if isPaid{
            self.payIconImgView.isHidden = false
            self.payIconImgView.image = UIImage(named: "homePage_payed")
        }else{
            //免费
            self.payIconImgView.isHidden = true
        }
        
//        if model.product?.check == true{
//            //付过费 或 免费
//            self.payIconImgView.isHidden = true
//            //显示已购买 或者 不显示
//            if model.product?.productType == "0" || model.product?.productType == "4"{
//                //免费
//                self.payIconImgView.isHidden = true
//            }else if model.product?.productType == "1"{
//                //积分
//                self.payIconImgView.isHidden = false
//                self.payIconImgView.image = UIImage(named: "homePage_payed")
//            }else if model.product?.productType == "2"{
//                //付费
//                self.payIconImgView.isHidden = false
//                self.payIconImgView.image = UIImage(named: "homePage_payed")
//            }else{
//                
//            }
//        }else{
//            //需要付费
//            if model.product?.productType == "0" || model.product?.productType == "4"{
//                //免费
//                self.payIconImgView.isHidden = true
//            }else if model.product?.productType == "1"{
//                //积分
//                self.payIconImgView.isHidden = false
//                self.payIconImgView.image = UIImage(named: "homePage_payment")
//            }else if model.product?.productType == "2"{
//                //付费
//                self.payIconImgView.isHidden = false
//                self.payIconImgView.image = UIImage(named: "homePage_payment")
//            }else{
//                self.payIconImgView.isHidden = false
//                self.payIconImgView.image = UIImage(named: "homePage_payment")
//            }
//        }
    }
}