杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
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
175
176
177
178
179
180
181
//
//  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)
    }
}