116 lines
3.6 KiB
Swift
116 lines
3.6 KiB
Swift
//
|
|
// SPMemberRechargeView.swift
|
|
// MoviaBox
|
|
//
|
|
// Created by 佳尔 on 2025/4/28.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPMemberRechargeView: UIView {
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
let count = CGFloat(dataArr?.count ?? 0)
|
|
|
|
let height = 32 + count * collectionViewLayout.itemSize.height + (count - 1) * collectionViewLayout.minimumInteritemSpacing
|
|
return CGSize(width: kSPScreenWidth, height: height)
|
|
}
|
|
|
|
///会员购买成功
|
|
var buyFinishHandle: (() -> Void)?
|
|
|
|
var dataArr: [SPPayTemplateItem]? {
|
|
didSet {
|
|
self.invalidateIntrinsicContentSize()
|
|
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
var shortPlayId: String?
|
|
var videoId: String?
|
|
|
|
//MARK: UI属性
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 14)
|
|
label.textColor = .colorFFFFFF(alpha: 0.7)
|
|
label.text = "Membership".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
|
layout.itemSize = CGSize(width: kSPScreenWidth - 32, height: 152)
|
|
layout.minimumInteritemSpacing = 10
|
|
layout.minimumLineSpacing = 10
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.isScrollEnabled = false
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
SPMemberRechargeCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SPMemberRechargeView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(titleLabel)
|
|
addSubview(collectionView)
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.height.equalTo(20)
|
|
make.top.equalToSuperview()
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(32)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPMemberRechargeView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPMemberRechargeCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.model = dataArr?[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr?.count ?? 0
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
guard let model = dataArr?[indexPath.row] else { return }
|
|
|
|
SPIAPManager.manager.startRecharge(model: model, shortPlayId: shortPlayId, videoId: videoId) { [weak self] finish in
|
|
if finish {
|
|
SPToast.show(text: "success".localized)
|
|
self?.buyFinishHandle?()
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|