verificationCodeDialog.vue 3.28 KB
<!-- 安全验证码 -->
<template>
  <!--   btn-ok-label="全部下载" -->
  <d2-dialog title="安全验证码"
             :is-visible="verificationCodeVisible"
             class="verificationCode"
             width="750px"
             @closeDialog="handleClose"
             @confirmDialog="handleConfirm">
    <p class="title-tips">注意: 成功提交后,首次设置规则立即生效,修改规则第二天生效!</p>
    <el-form ref="form"
             :model="form"
             :rules="rules"
             label-suffix=":"
             label-width="180px">
      <el-form-item label="管理员手机号验证">
        {{ adminInfo.name }} {{ adminInfo.phone }}
        <el-button :size="size"
                   @click="handleSend"
                   :disabled="isSend">
          {{ isSend ? sendMsg + '秒后,重试' : '发送验证短信' }}
        </el-button>
      </el-form-item>
      <el-form-item label="验证码"
                    prop="smsCode">
        <el-input placeholder="请填写验证码"
                  v-model="form.smsCode"
                  :size="size"
                  style="width: 220px;" />
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
import { sendSms, getAdminInfo } from '@api/merchant'
export default {
  name: 'VerificationCodeDialog',
  props: {
    visible: {
      // 弹窗是否展示
      type: Boolean,
      default: false
    }
  },
  computed: {
    verificationCodeVisible: {
      // return this.
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', false)
      }
    }
  },
  data() {
    return {
      size: 'small',
      form: {
        merchantId: '',
        bizType: '1'
      },
      rules: {
        smsCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      // 短信模块
      isSend: false,
      sendMsg: '发送验证短信',
      adminInfo: {
        name: '',
        phone: ''
      }

    }
  },
  mounted() {
    getAdminInfo({}).then(res => {
      this.adminInfo = res
    })
  },
  methods: {
    handleClose() {
      // this.$emit('dialogClose')
      // this.$update
      this.verificationCodeVisible = false
    },

    // 短信模块-start
    handleSend() {
      sendSms({}).then((res) => {
        this.notice.okTips('已发送,30分钟内有效')
        this.isSend = true
        this.sendMsg = 60
        this.msgDown()
      })
    },
    msgDown() {
      var time = setTimeout(() => {
        clearTimeout(time)
        if (this.sendMsg > 1) {
          --this.sendMsg
          this.msgDown()
        } else {
          this.isSend = false
        }
      }, 1000)
    },
    // 短信模块-end

    handleConfirm() {
      // if (this.stepStat === 3) {
      //   this.$refs['step' + this.stepStat].handleConfirm()
      //   return true
      // }
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 清空倒计时
          this.sendMsg = 1
          this.$emit('handleConfirm', this.form.smsCode)
          this.handleClose()
          // this.$refs['step' + this.stepStat].handleConfirm()
        }
      })
    }
  }
}
</script>

<style>
</style>