From 642175113bf6f2c90894e689dacda50278cad570 Mon Sep 17 00:00:00 2001 From: 杨锴 <841720330@qq.com> Date: 星期四, 19 九月 2024 15:50:11 +0800 Subject: [PATCH] complete most UI & Mock API --- XQMuse/Root/Me/VC/BankWithdrawVC.swift | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 85 insertions(+), 4 deletions(-) diff --git a/XQMuse/Root/Me/VC/BankWithdrawVC.swift b/XQMuse/Root/Me/VC/BankWithdrawVC.swift index 669744b..772661a 100644 --- a/XQMuse/Root/Me/VC/BankWithdrawVC.swift +++ b/XQMuse/Root/Me/VC/BankWithdrawVC.swift @@ -8,15 +8,33 @@ import UIKit import QMUIKit +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! - private var selectIndexPath = IndexPath(row: 0, section: 0) + @IBOutlet weak var label_income: UILabel! + 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() } override func setUI() { @@ -26,12 +44,64 @@ tableView.separatorStyle = .none tableView.backgroundColor = .clear tableView.register(UINib(nibName: "BankInfoTCell", bundle: nil), forCellReuseIdentifier: "_BankInfoTCell") - cons_height.constant = 84 * 2 + 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) + + } + + 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) } } @@ -45,6 +115,7 @@ 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 } @@ -53,7 +124,18 @@ } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + let id = bankModels[indexPath.row].id CommonAlertView.show(title: "提示", content: "是否删除此张银行卡?") { _ in + 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) } } @@ -66,9 +148,8 @@ return "删除" } - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 2 + return bankModels.count } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { -- Gitblit v1.7.1