<template>
  <el-input type="number" v-model="value" disabled>
    <template slot="append">
      <span @click="getCode()" class="yzm">{{ msg }}</span>
    </template>
  </el-input>
</template>

<script>
export default {
  props: {
    value: {
      type: String
    }
  },
  data() {
    return {
      msg: '获取验证码',
      time: 60,
      flag: true
    };
  },
  mounted() {
    this.ajax({ url: '/work/company/index' }).then((response) => {
      this.form = response.data;
    });
  },
  methods: {
    getCode() {
      if (this.flag) {
        this.$modal.msgSuccess('你的验证码是123456');
        //一分钟倒计时
        var countdown = setInterval(() => {
          this.time--;
          if (this.time == 0) {
            this.flag = true;
            this.msg = '获取短信';
            this.time = 60;
            clearInterval(countdown);
          } else {
            this.flag = false;
            this.msg = '重新获取(' + this.time + ')';
          }
        }, 1000);
      }
    }
  }
};
</script>
