163 lines
5.2 KiB
Swift
163 lines
5.2 KiB
Swift
//
|
|
// SPMemberRechargeView.swift
|
|
// MoviaBox
|
|
//
|
|
// Created by 佳尔 on 2025/4/28.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPMemberRechargeView: UIView {
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
let height = 30 + self.collectionView.contentSize.height
|
|
return CGSize(width: kSPScreenWidth, height: height + 1)
|
|
}
|
|
|
|
///会员购买成功
|
|
var buyFinishHandle: (() -> Void)?
|
|
|
|
private var dataArr: [SPPayTemplateItem]?
|
|
|
|
var shortPlayId: String?
|
|
var videoId: String?
|
|
|
|
//MARK: UI属性
|
|
private lazy var titleBgView: UIView = {
|
|
let view = UIView()
|
|
view.backgroundColor = .colorFFFFFF(alpha: 0.1)
|
|
view.layer.cornerRadius = 11.5
|
|
view.layer.masksToBounds = true
|
|
return view
|
|
}()
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 10)
|
|
label.textColor = .colorFFFFFF()
|
|
label.text = "movia_member_tip_text".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var collectionViewLayout: WaterfallMutiSectionFlowLayout = {
|
|
let layout = WaterfallMutiSectionFlowLayout()
|
|
layout.delegate = self
|
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
|
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")
|
|
}
|
|
|
|
///设置数据
|
|
func setDataArr(dataArr: [SPPayTemplateItem]?) {
|
|
self.dataArr = dataArr
|
|
|
|
UIView.performWithoutAnimation { [weak self] in
|
|
self?.collectionView.reloadData()
|
|
}
|
|
|
|
self.collectionView.performBatchUpdates(nil) { [weak self] _ in
|
|
self?.invalidateIntrinsicContentSize()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension SPMemberRechargeView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(titleBgView)
|
|
titleBgView.addSubview(titleLabel)
|
|
addSubview(collectionView)
|
|
|
|
titleBgView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview()
|
|
make.height.equalTo(23)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(17)
|
|
make.centerY.equalToSuperview()
|
|
make.right.lessThanOrEqualToSuperview().offset(-17)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(30)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//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 {
|
|
self?.buyFinishHandle?()
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//MARK: -------------- WaterfallMutiSectionDelegate --------------
|
|
extension SPMemberRechargeView: WaterfallMutiSectionDelegate {
|
|
|
|
func columnNumber(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> Int {
|
|
return 1
|
|
}
|
|
|
|
func heightForRowAtIndexPath(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, indexPath: IndexPath, itemWidth: CGFloat) -> CGFloat {
|
|
let model = dataArr?[indexPath.row]
|
|
if model?.vip_type_key == .year {
|
|
return 129
|
|
} else {
|
|
return 102
|
|
}
|
|
}
|
|
|
|
func lineSpacing(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloat {
|
|
return 9
|
|
}
|
|
|
|
func insetForSection(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> UIEdgeInsets {
|
|
return .init(top: 0, left: 15, bottom: 0, right: 15)
|
|
}
|
|
|
|
|
|
}
|