//
|
// BankWithdrawVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/21.
|
//
|
|
import UIKit
|
import QMUIKit
|
import JQTools
|
|
let WithDrawReply_Noti = Notification.Name.init("WithDrawReply_Noti")
|
|
class BankWithdrawVC: BaseVC {
|
|
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var tf_withdraw: UITextField!
|
@IBOutlet weak var cons_height: NSLayoutConstraint!
|
@IBOutlet weak var label_income: UILabel!
|
@IBOutlet weak var btn_complete: UIButton!
|
private var selectIndexPath:IndexPath?
|
|
private var bankModels = [BankInfoModel]()
|
private var income:CGFloat = 0
|
|
required init(income:Double){
|
super.init(nibName: nil, bundle: nil)
|
self.income = income
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "余额提现"
|
label_income.text = "可提现余额:¥" + income.jq_formatFloat
|
getBanks()
|
|
btn_complete.isEnabled = false
|
btn_complete.alpha = 0.6
|
tf_withdraw.delegate = self
|
}
|
|
override func setUI() {
|
// view.backgroundColor = UIColor(hexString: "f6f6f6")
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.backgroundColor = .clear
|
tableView.register(UINib(nibName: "BankInfoTCell", bundle: nil), forCellReuseIdentifier: "_BankInfoTCell")
|
cons_height.constant = 0
|
}
|
|
override func setRx() {
|
// AddBank_Noti
|
|
NotificationCenter.default.rx.notification(AddBank_Noti, object: nil).take(until: self.rx.deallocated).subscribe(onNext: { _ in
|
self.getBanks()
|
}).disposed(by: disposeBag)
|
|
tf_withdraw.rx.text.orEmpty.subscribe(onNext: {[weak self] text in
|
self?.btn_complete.isEnabled = !text.isEmpty
|
self?.btn_complete.alpha = text.isEmpty ? 0.6:1.0
|
}).disposed(by: disposeBag)
|
|
}
|
|
private func getBanks(){
|
Services.getMyBankList().subscribe(onNext: {data in
|
self.bankModels = data.data ?? []
|
self.tableView.reloadData()
|
self.cons_height.constant = CGFloat(self.bankModels.count) * 84.0
|
}).disposed(by: disposeBag)
|
}
|
|
@IBAction func addBankCardAction(_ sender: QMUIButton) {
|
let vc = AddBankInfoVC()
|
push(vc: vc)
|
}
|
|
@IBAction func withdrawAllAction(_ sender: UIButton) {
|
tf_withdraw.resignFirstResponder()
|
tf_withdraw.text = income.jq_formatFloat
|
}
|
|
@IBAction func withdrawHandleAction(_ sender: UIButton) {
|
|
tf_withdraw.resignFirstResponder()
|
|
guard selectIndexPath != nil else {
|
alertError(msg: "请选择提现银行卡");return
|
}
|
|
guard !tf_withdraw.text!.isEmpty else {
|
alertError(msg: tf_withdraw.placeholder ?? "请输入提现余额");return
|
}
|
|
let handleMoney = tf_withdraw.text?.toDouble ?? 0
|
|
|
guard income >= handleMoney else {
|
alertError(msg: "提现余额不足");return
|
}
|
|
|
Services.withdraw(bankId: bankModels[selectIndexPath!.row].id, money: tf_withdraw.text!.toDouble).subscribe(onNext: {data in
|
self.income -= self.tf_withdraw.text!.toDouble
|
alertSuccess(msg: "提现申请已提交")
|
self.tf_withdraw.text = ""
|
self.label_income.text = "可提现余额:¥\(self.income.jq_formatFloat)"
|
NotificationCenter.default.post(name: WithDrawReply_Noti, object: nil)
|
self.tf_withdraw.resignFirstResponder()
|
}).disposed(by: disposeBag)
|
}
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
btn_complete.localGradientColor(cornerRadius: 20)
|
}
|
}
|
|
extension BankWithdrawVC:UITableViewDelegate & UITableViewDataSource{
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
selectIndexPath = indexPath
|
tableView.reloadData()
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_BankInfoTCell", for: indexPath) as! BankInfoTCell
|
cell.isSelect(indexPath == selectIndexPath)
|
cell.setBankInfoModel(bankModels[indexPath.row])
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
return true
|
}
|
|
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
let id = bankModels[indexPath.row].id
|
CommonAlertView.show(title: "提示", content: "是否删除此张银行卡?") { state in
|
if state{
|
Services.deleteBank(id).subscribe(onNext: { _ in
|
self.tableView.beginUpdates()
|
self.bankModels.remove(at: indexPath.row)
|
self.tableView.deleteItemsAtIndexPaths([indexPath], animationStyle: .left)
|
self.tableView.endUpdates()
|
self.cons_height.constant = CGFloat(self.bankModels.count) * 84.0
|
UIView.animate(withDuration: 0.4) {
|
self.view.layoutIfNeeded()
|
}
|
}).disposed(by: self.disposeBag)
|
}
|
}
|
}
|
|
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
|
return .delete
|
}
|
|
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
|
return "删除"
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return bankModels.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 84
|
}
|
}
|
|
extension BankWithdrawVC:UITextFieldDelegate{
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
return textField.jq_filterDecimals(replacementString: string, range: range)
|
}
|
}
|