fix
杨锴
2024-10-09 2e91ee1387ef545ecef49230f2024b89b2f82a58
XQMuse/Root/Me/VC/VIPCenterVC.swift
@@ -7,21 +7,64 @@
import UIKit
import JQTools
import StoreKit
class VIPCenterVC: BaseVC {
            @IBOutlet weak var collectionView: UICollectionView!
            private var selectIndex = 0
    @IBOutlet weak var btn_isRead: UIButton!
    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()
        }
    }
    @IBAction func completeAction(_ sender: UIButton) {
        guard btn_isRead.isSelected else {
            alert(msg: "请先阅读并同意《会员用户协议》");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)
    }
}
@@ -34,12 +77,13 @@
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! VipCenterCCell
                        cell.isSelect(indexPath.row == selectIndex)
        let product = products[indexPath.row]
        cell.isSelect(indexPath.row == selectIndex,product: product)
                        return cell
            }
            func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                        return 5
        return products.count
            }
}
@@ -59,9 +103,9 @@
class VipCenterCCell:UICollectionViewCell{
            private var label_title:UILabel!
            private var label_price:UILabel!
            private var lable_priorDay:UILabel!
            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)
@@ -73,7 +117,7 @@
            func setUI(){
                        label_title  = UILabel()
                        label_title.text = "年度会员"
                        label_title.text = "--会员"
                        label_title.textAlignment = .center
                        label_title.textColor = UIColor(hexString: "#353535")
                        label_title.font = .systemFont(ofSize: 16, weight: .medium)
@@ -107,17 +151,20 @@
                        }
            }
            func isSelect(_ state:Bool){
    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: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: .white).add(string: "199", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: .white).mutableAttributedString
                                    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: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: UIColor(hexString: "#353535")!).add(string: "199", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
                                    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
                        }
            }