Step2.vue 5.3 KB
Newer Older
1 2
<template>
  <div>
3 4 5 6 7 8 9 10 11 12 13 14
    <a-form-model ref="form" :model="model" :rules="validatorRules" class="password-retrieval-form" @keyup.enter.native="nextStep">
      <a-form-model-item label="手机" required prop="phone" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
        <a-row :gutter="16">
          <a-col class="gutter-row" :span="20">
            <a-input v-model="model.phone" type="text" autocomplete="false" placeholder="请输入手机号">
              <a-icon slot="prefix" type="phone" :style="{ color: 'rgba(0,0,0,.25)'}"/>
            </a-input>
          </a-col>
        </a-row>
      </a-form-model-item>
      <a-form-model-item v-if="show" required prop="captcha" label="验证码" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
        <a-row :gutter="16">
15
          <a-col class="gutter-row" :span="12">
16 17
            <a-input v-model="model.captcha" type="text" placeholder="手机短信验证码">
              <a-icon slot="prefix" type="code" :style="{ color: 'rgba(0,0,0,.25)'}"/>
18 19 20 21 22 23 24 25 26 27 28
            </a-input>
          </a-col>
          <a-col class="gutter-row" :span="8">
            <a-button
              tabindex="-1"
              size="default"
              :disabled="state.smsSendBtn"
              @click.stop.prevent="getCaptcha"
              v-text="!state.smsSendBtn && '获取验证码' || (state.time+' s')"></a-button>
          </a-col>
        </a-row>
29 30
      </a-form-model-item>
      <a-form-model-item :wrapperCol="{span: 19, offset: 5}">
31
        <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
32
        <a-button type="primary" @click="nextStep" style="margin-left: 20px">下一步</a-button>
33 34
      </a-form-model-item>
    </a-form-model>
35 36 37 38
  </div>
</template>

<script>
39 40
  import {postAction} from '@/api/manage'

41 42
  export default {
    name: "Step2",
43 44
    props: ['userList'],
    data() {
45
      return {
46
        model: {},
47
        loading: false,
48
        // accountName: this.userList.username,
49
        dropList: "0",
50
        captcha: "",
51
        show: true,
52 53 54 55 56 57 58 59
        state: {
          time: 60,
          smsSendBtn: false,
        },
        formLogin: {
          captcha: "",
          mobile: "",
        },
60
        validatorRules: {
61 62 63 64 65 66 67
          phone: [
            { required: true, message: '请输入手机号码!' },
            { validator: this.validatePhone }
          ],
          captcha: [
            { required: true, message: '请输入短信验证码!' }
          ]
68 69 70
        },
      }
    },
71 72
    computed: {
    },
73
    methods: {
74
      nextStep() {
75 76
        let that = this
        that.loading = true
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        this.$refs['form'].validate((success) => {
          if(success==true){
            let params = {
              phone: this.model.phone,
              smscode: this.model.captcha
            }
            postAction("/sys/user/phoneVerification", params).then((res) => {
              if (res.success) {
                console.log(res);
                let userList = {
                  username: res.result.username,
                  phone: params.phone,
                  smscode: res.result.smscode
                };
                setTimeout(function () {
                  that.$emit('nextStep', userList)
                }, 0)
94
              } else {
95
                this.cmsFailed(res.message);
96
              }
97
            });
98
          }
99

100
        })
101
      },
102
      getCaptcha(e) {
103
        e.preventDefault();
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        const that = this
        that.$refs['form'].validateField('phone', err=>{
          if(!err){
            that.state.smsSendBtn = true;
            let interval = window.setInterval(() => {
              if (that.state.time-- <= 0) {
                that.state.time = 60;
                that.state.smsSendBtn = false;
                window.clearInterval(interval);
              }
            }, 1000);
            const hide = that.$message.loading('验证码发送中..', 0);
            let smsParams = {
              mobile: that.model.phone,
              smsmode: "2"
            };
            postAction("/sys/sms", smsParams).then(res => {
              if (!res.success) {
                setTimeout(hide, 1);
                that.cmsFailed(res.message);
              }
              setTimeout(hide, 500);
            })
          }else{
            that.cmsFailed(err);
129 130
          }
        })
131
      },
132 133
      cmsFailed(err) {
        this.$notification['error']({
134
          message: "验证错误",
135
          description: err,
136 137 138
          duration: 4,
        });
      },
139 140
      handleChangeSelect(value) {
        var that = this;
141
        console.log(value);
142 143 144 145 146 147 148
        if (value == 0) {
          that.dropList = "0";
          that.show = true;
        } else {
          that.dropList = "1";
          that.show = false;
        }
149
      },
150 151 152 153 154 155 156 157 158 159 160 161
      validatePhone(rule,value,callback){
          if(value){
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if(!myreg.test(value)){
              callback("请输入正确的手机号")
            }else{
              callback();
            }
          }else{
            callback()
          }
      }
162 163 164 165 166
    }

  }
</script>

167
<style lang="less" scoped>
168 169 170
  .stepFormText {
    margin-bottom: 24px;
  }
171 172 173 174 175

  .ant-form-item-label,
  .ant-form-item-control {
    line-height: 22px;
  }
176 177 178 179 180 181

  .getCaptcha {
    display: block;
    width: 100%;
    height: 40px;
  }
182
</style>