fix
杨锴
2024-10-09 2e91ee1387ef545ecef49230f2024b89b2f82a58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
//  VIPCenterVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/15.
//
 
import UIKit
import JQTools
import StoreKit
 
class VIPCenterVC: BaseVC {
 
                @IBOutlet weak var collectionView: UICollectionView!
    @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)
    }
}
 
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: "199", 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")
                }
}