无故事王国
2023-10-17 77041c81c325c0bc88c94dc28d732f656cc4c885
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
//
//  RechargeCenterVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/28.
//
 
import UIKit
import JQTools
import QMUIKit
 
class RechargeCenterVC: BaseVC {
 
    struct RechargeItem {
        var coin = 0
        var money:Double = 0
    }
 
    @IBOutlet weak var view_topBg: UIView!
    @IBOutlet weak var view_cion: JQ_RollNumberLabel!
    @IBOutlet weak var btn_rechange: UIButton!
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var btn_rechargeInfo: UIButton!
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var cons_collectHei: NSLayoutConstraint!
    
    private var items = [RechargeItem]()
    private let cellW = (JQ_ScreenW - 88) / 3.0
    private let cellH = ((JQ_ScreenW - 88) / 3.0) * 0.5148
    private var selectIndex = 0
 
    var viewModel:RechargeRecordViewModel!
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        view_cion.valueNumber = NSNumber(value: viewModel.coin.value)
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "充值中心"
        view_cion.font = UIFont.init(name: "Impact", size: 36)!
        view_cion.textColor = .white
 
        Services.voucherCenter().subscribe(onNext: {[weak self] data in
            guard let weakSelf = self else { return }
            for v in data.data ?? []{
                weakSelf.items.append(RechargeItem(coin: v.wpGold, money: v.amount))
            }
 
            let h = ceil(Double(weakSelf.items.count) / 3.0) * weakSelf.cellH + (floor(Double(weakSelf.items.count) / 3.0) - 1) * 18.0
            weakSelf.cons_collectHei.constant = h
            weakSelf.collectionView.reloadData()
        }).disposed(by: disposeBag)
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let colors = [UIColor(hexStr: "#FD8C02").cgColor,
                      UIColor(hexStr: "#FD7202").cgColor,]
        view_topBg.jq_gradientColor(colorArr: colors,bounds: CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.5923))
        btn_rechange.jq_gradientNibColor(colorArr: colors, cornerRadius: 20)
    }
 
    override func setUI() {
 
 
 
        let attribute = AttributedStringbuilder()
        attribute.add(string: "储值说明?", withFont: UIFont.systemFont(ofSize: 14), withColor: Def_ThemeColor)
        attribute.underLine(color: Def_ThemeColor)
        btn_rechargeInfo.titleLabel?.attributedText = attribute.mutableAttributedString
 
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.isScrollEnabled = false
        collectionView.contentInset = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12)
        collectionView.register(UINib(nibName: "RechargeItemCCell", bundle: nil), forCellWithReuseIdentifier: "_RechargeItemCCell")
    }
 
 
    @IBAction func introAction(_ sender: UIButton) {
        Services.rechargeDescription().subscribe(onNext: {[weak self] data in
            if let string = data.data{
                let vc = JQ_CommonWebViewController(htmlText: string, baseURL: nil)
                self?.present(vc, animated: true)
            }
        }).disposed(by: disposeBag)
    }
 
 
    @IBAction func rechargeAction(_ sender: UIButton) {
        let item = items[selectIndex]
        PaymentView.show(money: (ali:item.money,wx:item.money,coin:nil,course:nil,integral:nil)) {[weak self] type in
            guard let weakSelf = self else { return }
            Services.useBenefitPayment(amount: item.money, payType:type).subscribe(onNext: {data in
                if let m = data.data{
                    switch type {
                        case .aliPay:
                            YYPaymentManager.shared.sendPaymentRequest(YYAlipayRequest(orderString: m.orderString)) {[weak self] result in
                                guard let weakSelf = self else { return }
                                switch result {
                                    case .success:
                                        let vc = PaymentResultVC(result: .success, objType: .activityApply)
                                        vc.modalPresentationStyle = .fullScreen
                                        weakSelf.present(vc, animated: true)
                                    case .cancel:
                                        alert(msg: "交易已取消")
                                    case .failure(let error):
                                        alertError(msg: error.localizedDescription)
                                }
                            }
                        case .wechat:break
                        default:break
                    }
                }
            }).disposed(by: weakSelf.disposeBag)
        }
    }
}
 
extension RechargeCenterVC:UICollectionViewDelegate{
 
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        selectIndex = indexPath.row
    }
 
}
 
extension RechargeCenterVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let item = items[indexPath.row]
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_RechargeItemCCell", for:indexPath) as! RechargeItemCCell
        cell.isSelected = indexPath.row == selectIndex
        cell.label_coin.text = "\(item.coin)币"
        cell.label_moeny.text = item.money.currency()
        return cell
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items.count
    }
}
 
extension RechargeCenterVC:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 18
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 18
    }
 
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: cellW, height: cellH)
    }
}