<template>
  <div>

    <mt-field label="手机号" placeholder="请输入正确的手机号" type="tel" v-model="phone" :attr="{ maxlength: 13 }"></mt-field>

    <mt-field label="验证码" v-model="codeText" :disabled="disabled">
      <div class="getCode" @click="getCode">{{timeNum}}</div>
    </mt-field>

    <div style="margin-top: 34px" class="leftRightPadding">
      <mt-button type="danger" size="large">绑定</mt-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'binDing',
  data() {
    return {
      codeText: '',
      phone: '',
      timeText: '获取验证码',
      time: 0,
      disabled:false
    }
  },
  created(){
    this.timeNum = this.timeText
  },
  methods: {
    getCode: function () {
      var reg=11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/;
      //var url="/nptOfficialWebsite/apply/sendSms?mobile="+this.ruleForm.phone;
      if(this.phone==''){
        this.$vux.toast.text('请输入手机号码', 'top')
      }else if(!reg.test(this.phone)){
        this.$vux.toast.text('手机格式不正确', 'top')
      }else{
        this.time=60;
        this.disabled=true;
        this.timer();
        /*axios.post(url).then(
            res=>{
            this.phonedata=res.data;
        })*/
      }
    },
    timer() {
      if (this.time > 0) {
        this.time--;
        this.btntxt=this.time+"s后重新获取";
        setTimeout(this.timer, 1000);
      } else{
        this.time=0;
        this.btntxt="获取验证码";
        this.disabled=false;
      }
    },
  }
}
</script>

<style scoped lang="scss">
  .getCode {
    width: 100px;
    height: 48px;
    line-height: 48px;
    background: #ef4f4f;
    color: #fff;
    text-align: center;
  }
</style>
