//
|
// 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)
|
}
|
}
|