lmw
2025-04-24 718f31c92e2029d05260810435a2c70cef6e6ce5
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
package com.sinata.xqmuse.ui.mine
 
import android.app.Activity
import android.content.Intent
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.sinata.xqmuse.R
import com.sinata.xqmuse.dialog.TipDialog
import com.sinata.xqmuse.network.HttpManager
import com.sinata.xqmuse.network.entity.BankInfo
import com.sinata.xqmuse.network.request
import com.sinata.xqmuse.ui.TransparentStatusBarActivity
import com.sinata.xqmuse.ui.mine.adapter.BankCardAdapter
import com.sinata.xqmuse.utils.Const
import com.sinata.xqmuse.utils.event.EmptyEvent
import kotlinx.android.synthetic.main.activity_withdraw.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
import java.lang.Exception
 
class WithdrawActivity : TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_withdraw
 
    private var balance = 0.0
    private val list = arrayListOf<BankInfo>()
    private val adapter = BankCardAdapter(list)
    override fun initClick() {
        adapter.callback = object : BankCardAdapter.OnItemClickCallback {
            override fun onItemClick(position: Int) {
                adapter.checked = position
                adapter.notifyDataSetChanged()
            }
 
            override fun onDelClick(position: Int) {
                val tipDialog = TipDialog()
                tipDialog.arguments = bundleOf("msg" to "是否刪除此银行卡?","cancel" to "取消")
                tipDialog.showAllowingStateLoss(supportFragmentManager, "del")
                tipDialog.setCallback(object : TipDialog.OnClickCallback {
                    override fun onOk() {
                        HttpManager.deleteBank(list[position].id ?: "")
                            .request(this@WithdrawActivity) { _, _ ->
                                list.removeAt(position)
                                adapter.notifyDataSetChanged()
                            }
                    }
 
                    override fun onCancel() {
                    }
                })
            }
        }
 
        tv_add.setOnClickListener {
            startActivityForResult<BindCardActivity>(1)
        }
 
        tv_all.setOnClickListener {
            et_money.setText(balance.toString())
        }
 
        tv_action.onClick {
            if (adapter.checked == -1) {
                toast("请选择提现银行卡")
                return@onClick
            }
            var money = 0.0
            val moneyS = et_money.text.toString()
            if (moneyS.isEmpty())
                toast("请填写提现金额")
            else {
                try {
                    money = moneyS.toDouble()
                    if (money == 0.0)
                        toast("提现金额不能为0")
                    else if (money > balance)
                        toast("最多可提现%.2f元".format(balance))
                    else {
                        withdraw(money)
                    }
                } catch (e: Exception) {
                    toast("提现金额有误")
                }
            }
        }
 
    }
 
    private fun withdraw(money: Double) {
        tv_action.isEnabled = false
        HttpManager.withdraw(list[adapter.checked].id!!, money).request(this, success = { _, _ ->
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.REFRESH_WALLET)) //成功,刷新钱包
                finish()
        }) { _, _->
            tv_action.isEnabled = true
 
        }
    }
 
    override fun initView() {
        balance = intent.getDoubleExtra("balance", 0.0)
        tv_balance.text = "可提现余额:¥%.2f".format(balance)
        rv_card.layoutManager = LinearLayoutManager(this)
        rv_card.adapter = adapter
 
        getCard()
    }
 
    private fun getCard() {
        HttpManager.bankList().request(this) { _, data ->
            list.clear()
            list.addAll(data ?: arrayListOf())
            adapter.notifyDataSetChanged()
        }
    }
 
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK)
            getCard()
    }
}