Step2.vue 5.4 KB
Newer Older
1 2
<template>
  <div>
3 4 5 6 7 8 9 10 11
    <a-form :form="form" style="max-width: 500px; margin: 40px auto 0;" @keyup.enter.native="nextStep">
      <a-form-item
        label="手机"
        :labelCol="{span: 5}"
        :wrapperCol="{span: 19}"
      >
        <a-input
          type="text"
          autocomplete="false"
12 13
          style="width:310px;margin-left:-10px"
          v-decorator="['phone',{ rules: validatorRules.phone.rule}]"
14 15 16 17
          placeholder="请输入手机号">
          <a-icon slot="prefix" type="phone" :style="{ color: 'rgba(0,0,0,.25)'}"/>
        </a-input>
      </a-form-item>
18
      <a-form-item
19
        label="验证码"
20 21 22
        :labelCol="{span: 5}"
        :wrapperCol="{span: 19}"
        v-if="show">
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        <a-row :gutter="16" style="margin-left: 2px">
          <a-col class="gutter-row" :span="12">
            <a-input
              v-decorator="['captcha',validatorRules.captcha]"
              type="text"
              placeholder="手机短信验证码">
            </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>
40 41
      </a-form-item>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
42
        <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
43 44
        <a-button type="primary" @click="nextStep" style="margin-left: 20px">下一步</a-button>
      </a-form-item>
45 46 47 48 49
    </a-form>
  </div>
</template>

<script>
50 51
  import {postAction} from '@/api/manage'

52 53
  export default {
    name: "Step2",
54 55
    props: ['userList'],
    data() {
56 57 58
      return {
        form: this.$form.createForm(this),
        loading: false,
59
        // accountName: this.userList.username,
60
        dropList: "0",
61
        captcha: "",
62
        show: true,
63 64 65 66 67 68 69 70
        state: {
          time: 60,
          smsSendBtn: false,
        },
        formLogin: {
          captcha: "",
          mobile: "",
        },
71 72
        validatorRules: {
          captcha: {rule: [{required: true, message: '请输入短信验证码!'}, {validator: this.validateCaptcha}]},
73
          phone: {rule: [{required: true, message: '请输入手机号码!'}, {validator: this.validatePhone}]},
74 75 76
        },
      }
    },
77 78
    computed: {
    },
79
    methods: {
80
      nextStep() {
81 82 83 84 85
        let that = this
        that.loading = true
        this.form.validateFields((err, values) => {
          console.log(values);
          if (!err) {
86 87
            if (that.dropList == "0") {
              if (values.captcha == undefined) {
88
                this.cmsFailed("请输入短信验证码!");
89 90
              } else {
                var params = {}
91
                params.phone = values.phone;
92 93 94 95 96
                params.smscode = values.captcha;
                postAction("/sys/user/phoneVerification", params).then((res) => {
                  if (res.success) {
                    console.log(res);
                    var userList = {
97 98 99
                      username: res.result.username,
                      phone: values.phone,
                      smscode: res.result.smscode
100 101 102 103 104 105 106 107
                    };
                    setTimeout(function () {
                      that.$emit('nextStep', userList)
                    }, 0)
                  } else {
                    this.cmsFailed(res.message);
                  }
                })
108 109 110 111 112

              }
            }


113 114
          }
        })
115
      },
116
      getCaptcha(e) {
117 118
        e.preventDefault();
        let that = this;
119 120 121 122 123
        let phone=that.form.getFieldValue("phone")
        if(!phone){
          this.cmsFailed("手机号不能为空!");
          return;
        }
124 125 126
        this.state.smsSendBtn = true;
        let interval = window.setInterval(() => {
          if (that.state.time-- <= 0) {
127 128 129 130 131 132 133 134
            that.state.time = 60;
            that.state.smsSendBtn = false;
            window.clearInterval(interval);
          }
        }, 1000);

        const hide = this.$message.loading('验证码发送中..', 0);
        let smsParams = {
135
          mobile: phone,
136 137 138
          smsmode: "2"
        };
        postAction("/sys/sms", smsParams).then(res => {
139 140 141 142 143 144
          if (!res.success) {
            setTimeout(hide, 1);
            this.cmsFailed(res.message);
          }
          setTimeout(hide, 500);
        })
145
      },
146 147
      cmsFailed(err) {
        this.$notification['error']({
148
          message: "验证错误",
149
          description: err,
150 151 152
          duration: 4,
        });
      },
153 154
      handleChangeSelect(value) {
        var that = this;
155
        console.log(value);
156 157 158 159 160 161 162
        if (value == 0) {
          that.dropList = "0";
          that.show = true;
        } else {
          that.dropList = "1";
          that.show = false;
        }
163
      },
164 165 166 167 168 169 170 171 172 173 174 175
      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()
          }
      }
176 177 178 179 180
    }

  }
</script>

181
<style lang="less" scoped>
182 183 184
  .stepFormText {
    margin-bottom: 24px;
  }
185 186 187 188 189

  .ant-form-item-label,
  .ant-form-item-control {
    line-height: 22px;
  }
190 191 192 193 194 195 196

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