//
|
// VIPCenterVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/15.
|
//
|
|
import UIKit
|
import JQTools
|
import StoreKit
|
import WebKit
|
|
class VIPCenterVC: BaseVC {
|
|
@IBOutlet weak var bg_vip: UIImageView!
|
@IBOutlet weak var label_vipHint: UILabel!
|
@IBOutlet weak var collectionView: UICollectionView!
|
@IBOutlet weak var btn_isRead: UIButton!
|
@IBOutlet weak var label_expirtTime: UILabel!
|
@IBOutlet weak var webView: WKWebView!
|
@IBOutlet weak var webViewHeiCons: NSLayoutConstraint!
|
private var selectIndex = 0
|
|
private var productList = Set<String>()
|
private var products = [SKProduct]()
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "会员中心"
|
|
productList.insert("com.XQMuse.VIP.month.0")
|
productList.insert("com.XQMuse.VIP.semester.0")
|
productList.insert("com.XQMuse.VIP.year.0")
|
productList.insert("com.XQMuse.VIP.year.renewing.0")
|
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.showsHorizontalScrollIndicator = false
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
|
collectionView.register(VipCenterCCell.self, forCellWithReuseIdentifier: "cell")
|
|
InPurchaseManager.instance().setProductList(productList) { products in
|
self.products = Array(products)
|
self.products.sort { p1, p2 in
|
return p1.price.doubleValue < p2.price.doubleValue
|
}
|
self.collectionView.reloadData()
|
}
|
|
|
if UserViewModel.getAvatarInfo().isVip == .yes{
|
self.bg_vip.image = UIImage(named: "bg_vip")
|
self.label_vipHint.text = "您将享受所有会员专享音频,尽情畅游心泉·疗愈世界"
|
self.label_expirtTime.text = UserViewModel.getAvatarInfo().vipExpireTime.components(separatedBy: " ").first! + "到期"
|
}else{
|
self.bg_vip.image = UIImage(named: "bg_vip_u")
|
self.label_vipHint.text = "升级为会员,解锁会员专属体验"
|
self.label_expirtTime.text = "你还未开通会员服务"
|
}
|
|
Services.getVipContent(type: 1).subscribe(onNext: { data in
|
if let string = data.data{
|
self.webView.loadHTMLString(string.jq_wrapHtml(), baseURL: nil)
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
override func setRx() {
|
webView.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
|
if let size = size{
|
return size.height
|
}
|
return nil
|
}.subscribe(onNext: { [unowned self](height) in
|
if let height = height{
|
self.webViewHeiCons.constant = height
|
}
|
}).disposed(by: disposeBag)
|
|
}
|
|
@IBAction func completeAction(_ sender: UIButton) {
|
guard btn_isRead.isSelected else {
|
alert(msg: "请先阅读并同意《会员用户协议》");return
|
}
|
|
guard products.count != 0 else {return}
|
|
let product = products[selectIndex]
|
|
InPurchaseManager.purchaseProduct(ID: product.productIdentifier, applicationUsername: "") { m in
|
|
} errorClouse: { error in
|
alertError(msg: error.localizedDescription)
|
}
|
}
|
|
@IBAction func readAction(_ sender: UIButton) {
|
btn_isRead.isSelected = !btn_isRead.isSelected
|
|
}
|
|
@IBAction func agreementAction(_ sender: UIButton) {
|
let vc = WebVC(type: .user)
|
push(vc: vc)
|
}
|
}
|
|
extension VIPCenterVC:UICollectionViewDelegate & UICollectionViewDataSource{
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
selectIndex = indexPath.row
|
collectionView.reloadData()
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! VipCenterCCell
|
let product = products[indexPath.row]
|
cell.isSelect(indexPath.row == selectIndex,product: product)
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return products.count
|
}
|
}
|
|
extension VIPCenterVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSize(width: 111, height: 132)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 11.5
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 11.5
|
}
|
}
|
|
class VipCenterCCell:UICollectionViewCell{
|
|
private(set) var label_title:UILabel!
|
private(set) var label_price:UILabel!
|
private(set) var lable_priorDay:UILabel!
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
contentView.jq_cornerRadius = 10
|
contentView.backgroundColor = UIColor(hexString: "#EFF2F2")
|
setUI()
|
}
|
|
|
func setUI(){
|
label_title = UILabel()
|
label_title.text = "--会员"
|
label_title.textAlignment = .center
|
label_title.textColor = UIColor(hexString: "#353535")
|
label_title.font = .systemFont(ofSize: 16, weight: .medium)
|
contentView.addSubview(label_title)
|
label_title.snp.makeConstraints { make in
|
make.top.equalTo(31)
|
make.centerX.equalToSuperview()
|
make.height.equalTo(15)
|
}
|
|
label_price = UILabel()
|
label_price.attributedText = AttributedStringbuilder.build().add(string: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: UIColor(hexString: "#353535")!).add(string: "0", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
|
label_price.textAlignment = .center
|
label_price.font = .systemFont(ofSize: 16, weight: .medium)
|
contentView.addSubview(label_price)
|
label_price.snp.makeConstraints { make in
|
make.top.equalTo(label_title.snp.bottom).offset(15.5)
|
make.centerX.equalToSuperview()
|
make.height.equalTo(15)
|
}
|
|
lable_priorDay = UILabel()
|
lable_priorDay.text = "¥0/天"
|
lable_priorDay.textAlignment = .center
|
lable_priorDay.font = .systemFont(ofSize: 11, weight: .medium)
|
contentView.addSubview(lable_priorDay)
|
lable_priorDay.snp.makeConstraints { make in
|
make.top.equalTo(label_price.snp.bottom).offset(15.5)
|
make.centerX.equalToSuperview()
|
make.height.equalTo(15)
|
}
|
}
|
|
func isSelect(_ state:Bool,product:SKProduct){
|
label_title.text = product.localizedTitle
|
let priorDayPrice = product.price.doubleValue / 365.0
|
lable_priorDay.text = String(format:"%@%@/天", product.priceLocale.currencySymbol!,priorDayPrice.jq_formatFloat)
|
if state{
|
contentView.backgroundColor = UIColor(hexString: "#A6C586")
|
label_title.textColor = .white
|
lable_priorDay.textColor = .white
|
label_price.attributedText = AttributedStringbuilder.build().add(string: product.priceLocale.currencySymbol!, withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: .white).add(string: "\(product.price.intValue)", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: .white).mutableAttributedString
|
}else{
|
contentView.backgroundColor = UIColor(hexString: "#EFF2F2")
|
label_title.textColor = UIColor(hexString: "#353535")
|
lable_priorDay.textColor = UIColor(hexString: "#B7B7B7")
|
label_price.attributedText = AttributedStringbuilder.build().add(string: product.priceLocale.currencySymbol!, withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: UIColor(hexString: "#353535")!).add(string: "\(product.price.intValue)", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
|
}
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
}
|