CNLiveVodPlayShopCollectionCell.swift 4.7 KB
//
//  CNLiveVodPlayShopCollectionCell.swift
//  metaCode
//
//  Created by zx on 2025/3/5.
//  点播-电商商品 列表cell

import Foundation
import Kingfisher

class CNLiveVodPlayShopCollectionCell: UICollectionViewCell {
    
    //contentsModel
    var _vodPlayShopModel : CNLiveVodPlayShopModel?
    var vodPlayShopModel : CNLiveVodPlayShopModel? {
        get{
            _vodPlayShopModel
        }
        set{
            _vodPlayShopModel = newValue!
            setupNewUI(model: _vodPlayShopModel!)
        }
    }
    //默认商品列表
    var _albumModel : CNLiveAlbumModel?
    var albumModel : CNLiveAlbumModel? {
        get{
            _albumModel
        }
        set{
            _albumModel = newValue!
            self.setupNewUI(goodsModel: _albumModel!)
        }
    }


    lazy var iconImgView :UIImageView = {
        let iconImgView = UIImageView(frame: CGRect(x: 9, y: 9, width: 72, height: 72))
        iconImgView.contentMode = .scaleAspectFill
        iconImgView.clipsToBounds = true
        iconImgView.layer.cornerRadius = 9
        return iconImgView
    }()
    lazy var titleBgView :UIView = {
        let iconImgView = UIView(frame: CGRect(x: 0, y: 0, width: 235, height: 90))
        iconImgView.clipsToBounds = true
        iconImgView.layer.cornerRadius = 9
        iconImgView.backgroundColor = HexColor("#FAFAFA")
        return iconImgView
    }()
    lazy var titleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = BoldFont_14
        titleLbl.textColor = HexColor("#333333")
        titleLbl.numberOfLines = 2
        return titleLbl
    }()
    lazy var subTitleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = BoldFont_14
        titleLbl.textColor = HexColor("#E24F63")
        titleLbl.numberOfLines = 1
        return titleLbl
    }()
    //购买
    lazy var payBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = HexColor("#478BFF")
        expandBtn.clipsToBounds = true
        expandBtn.layer.cornerRadius = 9
        expandBtn.frame = CGRect(x: 0, y: 0, width: 64, height: 21)
        expandBtn.setTitle("购买", for: .normal)
        expandBtn.setTitle("购买", for: .highlighted)
        expandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_shoppingCart"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_shoppingCart"), for: .selected)
        expandBtn.titleLabel?.font = Font_12
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 6, style: .left)
        expandBtn.isUserInteractionEnabled = false
//        expandBtn.addTarget(self, action: #selector(payBtnAction), for: .touchUpInside)
        return expandBtn
    }()

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.addSubview(self.titleBgView)
        self.titleBgView.addSubview(self.iconImgView)
        self.titleBgView.addSubview(self.titleLabel)
        self.titleBgView.addSubview(self.subTitleLabel)
        self.titleBgView.addSubview(self.payBtn)

        titleBgView.snp.makeConstraints { make in
            make.left.top.width.height.equalToSuperview()
        }
        iconImgView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(9)
            make.top.equalToSuperview().offset(9)
            make.width.equalTo(72)
            make.height.equalTo(72)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(self.iconImgView.snp.right).offset(10)
            make.top.equalToSuperview().offset(6)
            make.right.equalToSuperview().offset(-20)
            make.height.equalTo(40)
        }
        subTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(self.titleLabel.snp.left)
            make.bottom.equalTo(self.iconImgView.snp.bottom)
        }
        payBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-8)
            make.bottom.equalTo(self.iconImgView.snp.bottom)
            make.width.equalTo(64)
            make.height.equalTo(21)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewUI(model:CNLiveVodPlayShopModel){
        self.iconImgView.kf.setImage(with: URL(string: model.img))
        self.titleLabel.text = model.title
        self.subTitleLabel.text = model.price
    }
    func setupNewUI(goodsModel:CNLiveAlbumModel){
        self.iconImgView.kf.setImage(with: URL(string: goodsModel.poster))
        self.titleLabel.text = goodsModel.title
        self.subTitleLabel.text = goodsModel.numberModel?.price
    }
    
    //购买
    @objc func payBtnAction(){

    }
}