lmw
2024-05-27 c00669a852702e1aa1326872bb916f9a079b57e2
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
package com.future.driver.ui.mine.money_bag
 
import android.text.InputFilter
import android.text.Spanned
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.getContent
import com.future.driver.R
import com.future.driver.base.MyBaseActivity
import com.future.driver.bean.CardListBean
import com.future.driver.bean.UserBean
import com.future.driver.netUtls.Api
import com.future.driver.netUtls.callNet
import com.future.driver.netUtls.getMapByAny
import com.future.driver.ui.DialogUtil
import com.future.driver.ui.adapter.CardListPopAdapter
import com.future.driver.utils.Cache.CacheKey
import kotlinx.android.synthetic.main.activity_apply_money.*
import kotlinx.android.synthetic.main.item_card_select.view.*
import org.jetbrains.anko.toast
 
class ApplyMoneyActivity : MyBaseActivity() {
 
    var maxMoney = CacheKey.getUserInfo().balance
 
    val type by lazy {
        intent.getStringExtra("type")
    }
 
    override fun setContentView() {
        setContentView(R.layout.activity_apply_money)
    }
 
    override fun initView() {
        maxMoney = if (type == "2"){
            CacheKey.getUserInfo().laveBusinessMoney
        }else{
            CacheKey.getUserInfo().balance
        }
        setTitleText("申请提现")
        et_money.hint = "填写提现金额(最多可提¥$maxMoney)"
 
        et_money.filters = arrayOf<InputFilter>(object : InputFilter {
            override fun filter(
                source: CharSequence,
                start: Int,
                end: Int,
                dest: Spanned,
                dstart: Int,
                dend: Int
            ): CharSequence? {
                if (source == "." && dest.toString().isEmpty()) {
                    return "0."
                }
                if (dest.toString().contains(".")) {
                    val index: Int = dest.toString().indexOf(".")
                    val length: Int = dest.toString().substring(index).length
                    if (length == 3) {
                        return ""
                    }
                }
                return null
            }
        })
    }
 
    override fun setOnclick() {
        tv_get_money.clickDelay {
//            if (et_card_num.getContent().trim().isEmpty()){
//                toast("请输入银行卡号码")
//                return@clickDelay
//            }
//            if (et_name.getContent().isEmpty()){
//                toast("请输入名字")
//                return@clickDelay
//            }
            if (et_money.getContent().isEmpty()){
                toast("请输入提现金额")
                return@clickDelay
            }
//            if (!PhoneCheckUtil.checkBankCard(et_card_num.getContent().trim())){
//                toast("银行卡号码错误")
//                return@clickDelay
//            }
            if (et_money.getContent().toDouble() > maxMoney){
                toast("提现金额不能超过最大余额")
                return@clickDelay
            }
            if (bankBean == null){
                toast("请选择银行卡")
                return@clickDelay
            }
            var map = getMapByAny()
            map["code"] = bankBean!!.code
            map["money"] = et_money.getContent()
            map["name"] = bankBean!!.name
            map["type"] = type
            callNet(Api.withdrawal,map){
                DialogUtil.getOnlySureDialog(this, "提交成功!我们将尽快为您处理!") {
                    onBackPressed()
                }
                callNet(Api.queryInfo, getMapByAny()){
                    var user = gson.fromJson<UserBean>(it, UserBean::class.java)
                    CacheKey.saveUserInfo(user.data)
                    maxMoney = CacheKey.getUserInfo().balance
                    et_money.hint = "填写提现金额(最多可提¥$maxMoney)"
 
                }
 
            }
        }
 
        rl_select_card.clickDelay {
            var pop = DialogUtil.getPopupwindow(this,R.layout.item_card_select)
            pop.contentView.recycler_view_card.layoutManager = LinearLayoutManager(this)
            var adapter = CardListPopAdapter()
            pop.contentView.recycler_view_card.adapter = adapter
            pop.contentView.view_close.clickDelay {
                pop.dismiss()
            }
            var map = getMapByAny()
            map["pageNum"] = 1
            map["size"] = 10
            callNet(Api.queryBankCard,map,{
                var beanList = gson.fromJson<CardListBean>(it, CardListBean::class.java).data
                adapter.data.addAll(beanList)
                adapter.notifyDataSetChanged()
                if (adapter.data.isNullOrEmpty()){
                    pop.dismiss()
                    toast("暂未绑定银行卡,请前往绑定银行卡")
                }
                adapter.setOnItemClickListener { view, position ->
                    bankBean = adapter.data[position]
                    tv_select_card.text = adapter.data[position].bank
                    pop.dismiss()
                }
            }){
                pop.dismiss()
            }
            pop.showDown(window.decorView)
        }
    }
 
    var bankBean:CardListBean.DataBean? = null
}