发送验证码加倒计时功能

      <div class="card-group">
        <p class="left">手机号码</p>
        <p class="right">{{desPhone(mobile)}}</p>
      </div>
      <div class="card-group">
        <input
          type="number"
          class="auth-code fl"
          @input="changeInput"
          placeholder="请输入验证码"
          v-model="authCode"
        />
        <input
          type="button"
          class="send-btn fr"
          v-model="getCode"
          @click="sendCode"
          :disabled="isAble"
        />
      </div>
      <div
        class="query-btn"
        :class="{'active':card_name==''||card_no==''||authCode==''}"
        @click="finish"
      >
        立即查询
      </div>

以下是js逻辑

data() {
          return {
            InterValObj: false, //控制倒计时
            count: 60, //
            authCode: "", //验证码
            num: 0, //倒计时
            getCode: "获取验证码",
            isAble: false, //发送控制,
        },
        mounted() {},
        methods: {
          // 验证码截取
          changeInput() {
            this.authCode = this.authCode.slice(0, 6);
          },
          sendCode() {
            //发送验证码
            let _this = this;
            ajax(
              "/interf/frontEnd/SMS/SMS1",
              {
                user_id: "",
                ses_id: "",
                mobile: "",
                sms_type: "10",
                channel: "01",
              },
              true,
              "POST",
              function (data) {
                vant.Toast(data.msg);
                if (data.result == "0") {
                  _this.countDown();
                }
              }
            );
          },
          
          countDown: function () {
            this.num = this.count;
            this.isAble = true;
            this.getCode = this.num + "s";
            this.InterValObj = window.setInterval(() => {
              this.SetRemainTime();
            }, 1000);
          },

          SetRemainTime() {
            if (this.num == 0) {
              this.isAble = false;
              window.clearInterval(this.InterValObj);
              this.getCode = "重新发送";
            } else {
              this.num--;
              this.getCode = this.num + "s";
            }
          },

          finish() {
            if (this.authCode.length < 6) {
              vant.Toast("请输入验证码");
              return false;
            }
            let _this = this;
            ajax(
              "/interf/frontEnd/SMS/SMS2",
              {
                user_id: "",
                ses_id: "",
                mobile: "",
                sms_type: "05",
                auth_code: "",
              },
              true,
              "POST",
              function (data) {
                if (data.result == "0") {
                  this.query();
                }
              }
            );
          },
          onInput() {
            this.card_no = this.card_no.replace(/[^A-Za-z0-9]/g, "");
          },
          onCancel() {
            this.showPicker = false;
          },
          onConfirm(value) {
            this.certType.text = value.text;
            this.certType.value = value.value;
            this.showPicker = false;
          },

          query() {
            let _this = this;
            if (this.card_no == "" || this.card_name == "") {
              return false;
            }
            ajax(
              "/interf/frontEnd/AC/AC08",
              {
                name: "",
                cert_no: "",
                cert_type:"",
              },
              true,
              "POST",
              function (data) {
                if (data.result == "0") {
                  console.log('这里就成功了,qq4717529')
                }
              }
            );
          },

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值