CNLiveVodIntroductionCell.swift 11.1 KB
//
//  CNLiveVodIntroductionCell.swift
//  metaCode
//
//  Created by zx on 2025/3/3.
//  简介,点赞等

import Foundation
import CNLiveShareToolKit

// type 1详情按钮 2点赞按钮 3收藏按钮 4分享按钮
typealias CNLiveVodIntroductionCellUpdateBlock = (_ isExpandDetail:Bool,_ isFavorite:Bool ,_ favoriteNum:Int,_ isCollection:Bool,_ type:String,_ model:CNLiveVodPlayBlockListListModel)->Void
class CNLiveVodIntroductionCell:UITableViewCell{
    
    var updateCellBlock:CNLiveVodIntroductionCellUpdateBlock?
    
    var _vodPlayBlockListModel : CNLiveVodPlayBlockListModel?
    var vodPlayBlockListModel : CNLiveVodPlayBlockListModel? {
        get{
            _vodPlayBlockListModel
        }
        set{
            _vodPlayBlockListModel = newValue!
            self.setupNewUI(model: vodPlayBlockListModel!)
        }
    }
    
    //MARK: - 懒加载
    lazy var titleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = BoldFont_15
        titleLbl.textColor = HexColor("#000102")
        titleLbl.text = "标题"
        return titleLbl
    }()
    //详情
    lazy var detailBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: 60, height: 40)
        expandBtn.setTitle("详情", for: .normal)
        expandBtn.setTitle("详情", for: .selected)
        expandBtn.setTitleColor(HexColor("#999999"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_expand"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_unexpand"), for: .selected)
        expandBtn.titleLabel?.font = Font_10
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
        expandBtn.addTarget(self, action: #selector(detailBtnAction), for: .touchUpInside)
        return expandBtn
    }()


    //点赞
    lazy var likeBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
        expandBtn.setTitle("0", for: .normal)
        expandBtn.setTitle("0", for: .selected)
        expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_like"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_liked"), for: .selected)
        expandBtn.titleLabel?.font = Font_10
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
        expandBtn.addTarget(self, action: #selector(likeBtnAction), for: .touchUpInside)
        expandBtn.backgroundColor = HexColor("#F5F5F5")
        expandBtn.clipsToBounds = true
        expandBtn.layer.cornerRadius = 20
        return expandBtn
    }()
    //评论
    lazy var collectionBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
        expandBtn.setTitle("收藏", for: .normal)
        expandBtn.setTitle("已收藏", for: .selected)
        expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_uncollection"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_collection"), for: .selected)
        expandBtn.titleLabel?.font = Font_10
        expandBtn.backgroundColor = HexColor("#F5F5F5")
        expandBtn.clipsToBounds = true
        expandBtn.layer.cornerRadius = 20
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
        expandBtn.addTarget(self, action: #selector(collectionBtnAction), for: .touchUpInside)
        return expandBtn
    }()
    //分享
    lazy var shareBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
        expandBtn.setTitle("分享", for: .normal)
        expandBtn.setTitle("分享", for: .selected)
        expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_share"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_player_share"), for: .selected)
        expandBtn.titleLabel?.font = Font_10
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
        expandBtn.backgroundColor = HexColor("#F5F5F5")
        expandBtn.clipsToBounds = true
        expandBtn.layer.cornerRadius = 20
        expandBtn.addTarget(self, action: #selector(shareBtnAction), for: .touchUpInside)
        return expandBtn
    }()
    //share gift
    lazy var shareGiftBtn: UIButton = {
        let expandBtn = UIButton.init(type: .custom)
        expandBtn.backgroundColor = .clear
        expandBtn.frame = CGRect(x: 0, y: 0, width: 64, height: 21)
        expandBtn.setTitle("送礼", for: .normal)
        expandBtn.setTitle("送礼", for: .selected)
        expandBtn.setTitleColor(HexColor("#000102"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_shareGift"), for: .normal)
        expandBtn.setImage(UIImage(named: "home_shareGift"), for: .selected)
        expandBtn.titleLabel?.font = Font_12
        expandBtn.setupButtonImageAndTitlePossitionWith(padding: 6, style: .left)
        expandBtn.addTarget(self, action: #selector(shareGiftBtnAction), for: .touchUpInside)
        expandBtn.backgroundColor = HexColor("#FFEFE9")
        expandBtn.clipsToBounds = true
        expandBtn.layer.cornerRadius = 10
        return expandBtn
    }()

    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
        
    private func setupUI() {
        contentView.backgroundColor = .white
        self.contentView.addSubview(self.titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(15)
            make.width.lessThanOrEqualTo(KSreenWidth-10-80)
        }
        
        self.contentView.addSubview(self.detailBtn)
        detailBtn.snp.makeConstraints { make in
            make.left.equalTo(self.titleLabel.snp.right).offset(10)
            make.centerY.equalTo(self.titleLabel.snp.centerY)
            make.width.equalTo(60)
            make.height.equalTo(30)
        }
        self.contentView.addSubview(self.likeBtn)
        likeBtn.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.top.equalTo(self.titleLabel.snp.bottom).offset(19)
            make.width.equalTo((KSreenWidth-40)/3.0)
            make.height.equalTo(40)
        }

//        if  metaAppDelegate.isGift{
//            self.contentView.addSubview(shareGiftBtn)
//            shareGiftBtn.snp.makeConstraints { make in
//                make.right.equalToSuperview().offset(-10)
//                make.width.equalTo(64)
//                make.height.equalTo(21)
//                make.centerY.equalTo(self.titleLabel.snp.centerY)
//            }
//        }
        
        self.contentView.addSubview(self.collectionBtn)
        collectionBtn.snp.makeConstraints { make in
            make.left.equalTo(self.likeBtn.snp.right).offset(10)
            make.centerY.equalTo(self.likeBtn.snp.centerY)
            make.width.equalTo((KSreenWidth-40)/3.0)
            make.height.equalTo(40)
        }
        self.contentView.addSubview(self.shareBtn)
        shareBtn.snp.makeConstraints { make in
            make.left.equalTo(self.collectionBtn.snp.right).offset(10)
            make.centerY.equalTo(self.likeBtn.snp.centerY)
            make.width.equalTo((KSreenWidth-40)/3.0)
            make.height.equalTo(40)
        }

        self.contentView.clipsToBounds = true
    }
    
    func setupNewUI(model:CNLiveVodPlayBlockListModel){
        if model.list.count > 0{
            if let vodMdl = model.list.first{
                titleLabel.text = vodMdl.title
                //处理转换成万
                likeBtn.setTitle("\(vodMdl.likesNum)", for: .normal)
                likeBtn.setTitle("\(vodMdl.likesNum)", for: .selected)
                likeBtn.isSelected = vodMdl.liked

                if metaAppDelegate.isLogin{
                    collectionBtn.isSelected = vodMdl.collectioned
                }else{
                    collectionBtn.isSelected = false
                }
            }
        }
    }

    @objc func detailBtnAction(){
        self.updateCellBlock?(true, false,0, false, "1",self.vodPlayBlockListModel!.list.first!)
    }

    @objc func likeBtnAction(){
        let vodMdl = self.vodPlayBlockListModel!.list.first!
        let isLike = !vodMdl.liked
        
//        let num = likeBtn.isSelected ? 1 : -1
//        var likeNum = 0//((vodMdl.likesNum+num) == -1) ? 0 : vodMdl.likesNum+num
//        if metaAppDelegate.isLogin{
//            likeNum = ((vodMdl.likesNum+num) == -1) ? 0 : vodMdl.likesNum+num
//            likeBtn.isSelected = likeBtn.isSelected ? false : true
//        }else{
//            likeNum = vodMdl.likesNum
//            likeBtn.isSelected = false
//        }
//        print("1111111likeNum\(likeNum)")
//        likeBtn.setTitle("\(likeNum)", for: .normal)
//        likeBtn.setTitle("\(likeNum)", for: .selected)

//        self.updateCellBlock?(false, likeBtn.isSelected,likeNum, false, "2",self.vodPlayBlockListModel!.list.first!)
        self.updateCellBlock?(false, isLike,0, false, "2",self.vodPlayBlockListModel!.list.first!)

    }
    @objc func collectionBtnAction(){
        let vodMdl = self.vodPlayBlockListModel!.list.first!
        let isCollectioned = !vodMdl.collectioned
//        if metaAppDelegate.isLogin{
//            collectionBtn.isSelected = collectionBtn.isSelected ? false : true
//        }else{
//            collectionBtn.isSelected = false
//        }
        self.updateCellBlock?(false, false,0, isCollectioned, "3",self.vodPlayBlockListModel!.list.first!)
    }
    @objc func shareBtnAction(){
        self.updateCellBlock?(false, false,0, false, "4",self.vodPlayBlockListModel!.list.first!)
    }
    
    @objc func shareGiftBtnAction(){
        let shareTitle = metaAppDelegate.giftModel?.data?.share_app_banner?.share_title
        let shareDesc = metaAppDelegate.giftModel?.data?.share_app_banner?.share_content
        let shareImage = metaAppDelegate.giftModel?.data?.share_app_banner?.share_icon
        let shareUrl = metaAppDelegate.giftModel?.data?.share_app_banner?.jumpUrl

        CNLiveShareManager.showShareViewWithParam(forShareTitle: shareTitle, shareUrl: shareUrl, shareDesc: shareDesc, shareImage: shareImage, screenFull: false, hiddenWjj: true, hiddenQQ: true, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: currentViewController(), topImage: [], topTitles: [], platformType: .all) { title in
            
        } completerBlock: { resultType, platformType, typeString in
            if resultType == .succ{
                print("succ")
            }
        }

    }

    
}