package com.fangxinxing.xxfxx.ui.mine.money_bag
|
|
import android.text.InputFilter
|
import android.text.Spanned
|
import com.fangxinxing.xxfxx.R
|
import com.fangxinxing.xxfxx.base.MyBaseActivity
|
import com.fangxinxing.xxfxx.bean.LastWithdrawInfo
|
import com.fangxinxing.xxfxx.bean.UserBankInfoBean
|
import com.fangxinxing.xxfxx.bean.UserBean
|
import com.fangxinxing.xxfxx.netUtls.Api
|
import com.fangxinxing.xxfxx.netUtls.callNet
|
import com.fangxinxing.xxfxx.netUtls.getMapByAny
|
import com.fangxinxing.xxfxx.utils.Cache.CacheKey
|
import com.fangxinxing.xxfxx.utils.clickDelay
|
import com.fangxinxing.xxfxx.utils.getContent
|
import com.fangxinxing.xxfxx.utils.getFormatTwo
|
import kotlinx.android.synthetic.main.activity_apply_withdraw.et_money
|
import kotlinx.android.synthetic.main.activity_apply_withdraw.tv_withdraw
|
import org.jetbrains.anko.toast
|
|
//申请提现页面
|
class ApplyWithdrawActivity : MyBaseActivity() {
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_apply_withdraw)
|
}
|
|
override fun initView() {
|
setTitleText("申请提现")
|
et_money.hint = "${getFormatTwo(CacheKey.getUserInfo().balance)}元可提现"
|
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
|
}
|
})
|
callMine()
|
}
|
|
private fun callMine() {
|
val map = getMapByAny()
|
callNet(Api.queryInfo, map) {
|
val user = gson.fromJson<UserBean>(it, UserBean::class.java)
|
CacheKey.saveUserInfo(user.data)
|
et_money.hint = "${getFormatTwo(CacheKey.getUserInfo().balance)}元可提现"
|
}
|
}
|
|
override fun setOnclick() {
|
tv_withdraw.clickDelay {
|
if (et_money.getContent().isEmpty()) {
|
toast("请输入提现金额")
|
return@clickDelay
|
}
|
val money = et_money.getContent().toDoubleOrNull() ?: 0.0
|
if (money <= 0) {
|
toast("提现金额必须大于0")
|
return@clickDelay
|
}
|
if (money > CacheKey.getUserInfo().balance) {
|
toast("提现金额不能大于${CacheKey.getUserInfo().balance}元")
|
return@clickDelay
|
}
|
val map = getMapByAny()
|
callNet(Api.queryLastWithdrawal, map) {
|
val userBankInfoBean =
|
gson.fromJson<UserBankInfoBean>(it, UserBankInfoBean::class.java)
|
userBankInfoBean.apply {
|
data = (data ?: LastWithdrawInfo()).apply {
|
this.money = money.toString()
|
}
|
}
|
startActivity(SetWithdrawAccountActivity.getIntent(this, userBankInfoBean.data))
|
finish()
|
}
|
}
|
}
|
}
|