cashDialog.vue 3.6 KB
<!-- 提现弹窗 -->
<template>
  <d2-dialog
    title="提现"
    :is-visible.sync="cashVisible"
    width="60%"
    @confirmDialog="handleCashConfirm"
    @closeDialog="handleCashClose">
    <span slot="sub-title">提现后不能撤回,确保资金安全,请谨慎操作!</span>
    <el-form
      ref="cashDialog"
      :model="cashForm"
      :rules="cashRules"
      label-width="120px">
      <el-form-item label="可提现余额:">
        <span>¥ {{ cashForm.balance }}</span>
      </el-form-item>
      <el-form-item label="提现金额:">
        <span>¥ {{ +cashForm.balance - 2 }}</span><span style="margin-left: 40px;">注:每提现一笔会扣除2元手续费</span>
      </el-form-item>
      <el-form-item label="到账账户:">
        <p>{{ cashForm.bankAccountName }}</p>
        <p>{{ cashForm.bankName }}({{ cashForm.bankAccountNo }})<span>预计24小时内到账</span></p>
      </el-form-item>
      <el-form-item
        label="验证码:"
        prop="smsCode">
        <el-input
          v-model="cashForm.smsCode"
          placeholder="请输入验证码"
          style="width: 200px" />
        <el-button
          type="primary"
          size="small"
          @click="handleSend"
          :disabled="isSend"
          class="cash-btn">
          {{ isSend ? sendMsg + '秒后,重试' : '获取验证码' }}
        </el-button>
        <p v-show="showtips">
          已向尾号为{{ cashForm.withdrawPhone ? cashForm.withdrawPhone.slice(-4) : '' }}的手机号发送验证码,验证码30分钟内有效
        </p>
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
import { createWithdraw } from '@api/account'
import { sendToSmsCodeApi } from '@/api/sys.base'
export default {
  data() {
    return {
      cashRules: {
        smsCode: [{ required: true, message: '请输入验证码', trigger: 'change' }]
      },
      // 验证码
      showtips: false,
      isSend: false,
      sendMsg: '获取验证码',
      time: ''
    }
  },

  props: {
    cashVisible: {
      type: Boolean,
      default: false
    },
    cashForm: {
      type: Object,
      default: () => { }
    }
  },

  watch: {
    cashVisible(newVal, val) {
      newVal ? this.reset() : this.closeReset()
    }
  },

  mounted() { },

  methods: {
    reset() {
      this.$refs.cashDialog && this.$refs.cashDialog.resetFields()
    },
    closeReset() {
      this.isSend = false
      this.showtips = false
      this.time && clearTimeout(this.time)
    },
    handleCashConfirm() {
      this.$refs.cashDialog.validate(valid => {
        if (valid) {
          createWithdraw({ totalAmount: (+this.cashForm.balance - 2), smsCode: this.cashForm.smsCode }).then(res => {
            this.notice.okTips()
            this.$emit('handleCashConfirm')
          })
        }
      })
    },
    handleCashClose() {
      this.$emit('handleCashClose')
    },
    handleSend() {
      sendToSmsCodeApi({ phone: this.cashForm.withdrawPhone }).then((res) => {
        this.notice.okTips('已发送,30分钟内有效')
        this.isSend = true
        this.showtips = true
        this.sendMsg = 60
        this.msgDown()
      })
    },
    msgDown() {
      this.time = setTimeout(() => {
        clearTimeout(this.time)
        if (this.sendMsg > 1) {
          --this.sendMsg
          this.msgDown()
        } else {
          this.isSend = false
        }
      }, 1000)
    }
  }
}

</script>
<style scoped>
p {
  margin: 0 0;
}
.cash-btn {
  margin-left: 20px;
}
</style>