package com.fanghua.driver.ui.mine.money_bag
|
|
import android.text.InputFilter
|
import android.text.Spanned
|
import android.util.Log
|
import cn.sinata.xldutils.utils.clickDelay
|
import cn.sinata.xldutils.utils.getContent
|
import com.fanghua.driver.R
|
import com.fanghua.driver.base.Const
|
import com.fanghua.driver.base.MyBaseActivity
|
import com.fanghua.driver.bean.BaseBean
|
import com.fanghua.driver.bean.DriverBean
|
import com.fanghua.driver.netUtls.Api
|
import com.fanghua.driver.netUtls.callNet
|
import com.fanghua.driver.netUtls.getMapByAny
|
import com.fanghua.driver.ui.DialogUtil
|
import com.google.gson.Gson
|
import com.umeng.socialize.UMAuthListener
|
import com.umeng.socialize.UMShareAPI
|
import com.umeng.socialize.UMShareConfig
|
import com.umeng.socialize.bean.SHARE_MEDIA
|
import kotlinx.android.synthetic.main.activity_apply_money.*
|
import kotlinx.android.synthetic.main.dialog_sure_and_del.*
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
|
class ApplyMoneyActivity : MyBaseActivity(), UMAuthListener {
|
private var balance = 0.0
|
private var isWechat = false //微信是否授权
|
private val type by lazy { //1=余额提现,2=佣金提现
|
intent.getIntExtra("type",1)
|
}
|
override fun setContentView() {
|
setContentView(R.layout.activity_apply_money)
|
}
|
|
override fun initView() {
|
setTitleText("申请提现")
|
getInfo()
|
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_money.getContent().isEmpty()) {
|
toast("请输入提现金额")
|
return@clickDelay
|
}
|
try {
|
if (et_money.getContent().toDouble() == 0.0) {
|
toast("提现金额不能为0")
|
return@clickDelay
|
}
|
}catch (e:Exception){
|
toast("请输入正确提现金额")
|
return@clickDelay
|
}
|
|
if (et_money.getContent().toDouble() > balance) {
|
toast("最多可提现${balance}元")
|
return@clickDelay
|
}
|
if (!isWechat){
|
val config = UMShareConfig()
|
config.isNeedAuthOnGetUserInfo(true)
|
UMShareAPI.get(this).setShareConfig(config)
|
UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.WEIXIN, this)
|
return@clickDelay
|
}
|
var map = getMapByAny()
|
map["money"] = et_money.getContent()
|
map["type"] = type
|
callNet(Api.withdrawal, map) {
|
val onlySureDialog = DialogUtil.getOnlySureDialog(this, "到账3~7个工作日") {
|
startActivity<WalletActivity>()
|
}
|
onlySureDialog.window?.decorView?.apply {
|
tv_hint_base.text = "提交成功"
|
}
|
}
|
}
|
}
|
|
private fun getInfo() {
|
var map = getMapByAny()
|
callNet(false,Api.queryInfo, map) {
|
var data = gson.fromJson<DriverBean>(it, DriverBean::class.java)
|
if (data.resultUtil.code == 10000) {
|
balance = if (type == 1) data.resultUtil.data.withdrawBalance else data.resultUtil.data.commission
|
isWechat = data.resultUtil.data.wechatAuthorization == 1
|
et_money.hint = "可提现金额${balance}元"
|
}else
|
toast(data.resultUtil.msg)
|
}
|
}
|
|
override fun onStart(p0: SHARE_MEDIA?) {
|
Log.e(TAG,"开始授权")
|
}
|
|
override fun onComplete(p0: SHARE_MEDIA?, p1: Int, p2: MutableMap<String, String>?) {
|
val map = getMapByAny()
|
map["openid"] = p2?.get("openid")
|
callNet(Api.saveDriverInfo,map){
|
val bean = Gson().fromJson(it, BaseBean::class.java)
|
if (bean.resultUtil.code == 10000){
|
toast("微信绑定成功")
|
isWechat = true
|
}else
|
toast(bean.resultUtil.msg)
|
}
|
}
|
|
override fun onError(p0: SHARE_MEDIA?, p1: Int, p2: Throwable?) {
|
Log.e(TAG,"授权失败:" + p2?.message)
|
if (p1 == 2008)
|
toast("未安装微信")
|
}
|
|
override fun onCancel(p0: SHARE_MEDIA?, p1: Int) {
|
Log.e(TAG,"取消授权")
|
}
|
}
|