宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  MineWithdrawalVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/17.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
/// 提现
class MineWithdrawalVC: YYViewController {
    
    /// 提交
    @IBOutlet weak var button_submit: YYButton!
    
    /// 持卡人姓名
    @IBOutlet weak var textField_name: YYTextField!
    
    /// 卡号
    @IBOutlet weak var textField_cardNum: YYTextField!
    
    /// 金额
    @IBOutlet weak var textFied_money: YYTextField!
    
    /// 余额
    private var money: Double = app.userInfo.balance
 
    let viewModel = MineWithdrawalViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
    }
    
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "提现"
        textFied_money.placeholder = "\(money)元可提现"
        navigationItem.rightBarButtonItem = UIBarButtonItem.yy_creat(title: "提现记录", UIFont.systemFont(ofSize: 14), UIColor.color(light: UIColor.color(hexString: "#666666"), dark: UIColor.color(hexString: "#666666")), target: self, action: #selector(withdrawalRecord)).item
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        
        textFied_money.rx.text.orEmpty.map{ value in
            return value.wy_toDouble()
        }.bind(to: viewModel.money).disposed(by: disposeBag)
        
        textField_cardNum.rx.text.orEmpty.bind(to: viewModel.code).disposed(by: disposeBag)
        
        textField_name.rx.text.orEmpty.bind(to: viewModel.name).disposed(by: disposeBag)
        
        button_submit.rx.tap.subscribe(onNext: {[unowned self] (_) in
            if self.textFied_money.isEmpty(empty: "请输入提交金额"){
                return
            }
            if self.textField_cardNum.isEmpty(empty: "请输入卡号"){
                return
            }
            if self.textField_name.isEmpty(empty: "请输入持卡人姓名"){
                return
            }
            self.viewModel.withdrawal()
        }).disposed(by: disposeBag)
        
        viewModel.queryUserInfoSubject
        .subscribe(onNext: {[unowned self] (status) in
            switch status{
            case .loading:
//                self.show()
                break
            case .success(_):
//                self.hide()
                self.yy_pop()
                break
            case .error(let error):
//                self.hide()
                alert(text: error.localizedDescription)
                break
            }
        }).disposed(by: rx.disposeBag)
        /// 提现
        viewModel.requestSubject
        .subscribe(onNext: {[unowned self] (status) in
            switch status{
            case .loading:
                self.show()
                break
            case .success(_):
                self.hide()
                alert(text: "提交成功!我们将尽快处理,请您注意查看到账情况")
                self.viewModel.queryUserInfo()
//                alert(popup: .single, title: "提示", text: , submitTitle: "确定", cancelTitle: nil, submitClick: {
//
//                }) {}
                break
            case .error(let error):
                self.hide()
                alert(text: error.localizedDescription)
                break
            }
        }).disposed(by: rx.disposeBag)
    }
    
    
    /// 提现记录
    @objc func withdrawalRecord(){
        let vc = MineWithdrawalRecordVC()
        self.yy_push(vc: vc)
    }
}