CNLiveVodPayView.swift 5.9 KB
//
//  CNLiveVodPayView.swift
//  metaCode
//
//  Created by zx on 2025/4/1.
//  支付页面

import Foundation
import CNLiveBusinessTools

typealias CNLiveVodPayViewPayBlock = ()->Void

class CNLiveVodPayView:UIView,UIGestureRecognizerDelegate{
    
    var payBlock:CNLiveVodPayViewPayBlock?
    //MARK: - 懒加载
    lazy var titleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = Font_12
        titleLbl.textColor = HexColor("#FFFFFF")
        titleLbl.text = "应版权方要求,本内容所有用户均需付费"
        return titleLbl
    }()
    lazy var payBtn: UIButton = {
        let  closeBtn = UIButton(type: .custom)
        closeBtn.backgroundColor = HexColor("#F5A623", alpha: 0.14)
        closeBtn.layer.borderColor = HexColor("#F5A623")?.cgColor
        closeBtn.layer.borderWidth = 0.5
        closeBtn.clipsToBounds = true
        closeBtn.layer.cornerRadius = 6
        closeBtn.setTitleColor(HexColor("#F5A623"), for: .normal)
        closeBtn.setTitle("元购买本专辑", for: .normal)
        closeBtn.titleLabel?.font = Font_12
        closeBtn.addTarget(self, action: #selector(payBtnAction), for: .touchUpInside)
        return closeBtn
    }()

    lazy var landscapeBackBtn: UIButton = {
        let backBtn = UIButton.backItem(imageName: ("mine_header_icon_white_back"), target: self, action: #selector(landscapeBackBtnAction))
        backBtn.frame = CGRect(x: 15, y: KStatusBarHeight, width: 60, height: 30)
        return backBtn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = HexColor("#000000", alpha: 0.7)
        self.isUserInteractionEnabled = true
        self.initUI()
        
        self.initGesture()
    }
      
    func initGesture(){
        self.isMultipleTouchEnabled = true

        // 双击手势
        var doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapAction))
        doubleTapGesture.numberOfTapsRequired = 2 // 双击触发
        doubleTapGesture.delaysTouchesBegan = true
        doubleTapGesture.delaysTouchesEnded = true
        doubleTapGesture.numberOfTouchesRequired = 1

        var panGesture = UIPanGestureRecognizer(target: self, action: #selector(panAction))
        panGesture.delaysTouchesBegan = true
        panGesture.delaysTouchesEnded = true
        panGesture.maximumNumberOfTouches = 1
        panGesture.cancelsTouchesInView = true

        var tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        tapGesture.delaysTouchesBegan = true
        tapGesture.delaysTouchesEnded = true
        tapGesture.numberOfTouchesRequired = 1
        tapGesture.numberOfTapsRequired = 1
        tapGesture.require(toFail: doubleTapGesture)
        tapGesture.require(toFail: panGesture)
        self.addGestureRecognizer(tapGesture)
        self.addGestureRecognizer(doubleTapGesture)
        self.addGestureRecognizer(panGesture)

        var pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction))
        pinchGesture.delaysTouchesBegan = true
        self.addGestureRecognizer(pinchGesture)

        // 长按手势
        var longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction))
        longGesture.minimumPressDuration = 0.5// 长按触发时间(秒)
        self.addGestureRecognizer(longGesture)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        
//        self.addSubview(self.landscapeBackBtn)

        self.addSubview(self.titleLabel)
        
        self.addSubview(self.payBtn)
        payBtn.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(117)
            make.height.equalTo(30)
        }
        titleLabel.snp.makeConstraints { make in
            make.bottom.equalTo(self.payBtn.snp.top).offset(-15)
            make.centerX.equalToSuperview()
        }
    }
    
    @objc func payBtnAction(){
        //拉起支付
        if metaAppDelegate.isLogin{
            self.payBlock?()
        }else{
            //游客模式未登录 提示登录
            AlertTool.showSystemAlert(title: "是否登录?", message: "登录后能通过其他设备访问已付费内容", actionTitles: ["确定","取消"], style: .alert) { index in
                if index == 1 {
                    //确定 //是->跳登录
                    metaAppDelegate.pushLoginVC()
                }else if index == 2 {
                    //取消
                    //否->uuid内购购买
                    showLoading(message: "")
                    let uuid = CNLiveBusinessTools.uuid()
                    print("uuid:\(uuid)")
                    CNLiveLoginViewModel.requestUUIDLoginInDevice(uuid: uuid, frmld: "") { result, status in
                        if status == .success{
                            let uid = UserInfoManager.shared.userInfo.uid
                            self.payBlock?()
                        }
                    }
                }
            }
            
            
            
            
            
        }
    }

    @objc func tapAction(){
//        self.isHidden = true
        print("tapAction")
    }
    @objc func pinchAction(){
//        self.isHidden = true
        print("pinchAction")
    }
    @objc func longPressAction(){
//        self.isHidden = true
        print("longPressAction")
    }
    @objc func doubleTapAction(){
//        self.isHidden = true
        print("doubleTapAction")
    }
    
    @objc func panAction(){
//        self.isHidden = true
        print("panAction")
    }

    @objc func landscapeBackBtnAction(){
        let viewControllers = navigationViewController().viewControllers
        if viewControllers.count > 1 {
            if viewControllers.last == self {
                navigationViewController().popViewController(animated: true)
            }
        }
    }
}