Step2.vue 5.5 KB
Newer Older
1 2
<template>
  <div>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    <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"
          :style="{width:'310px'}"
          :value="accountName"
          disabled>
        </a-input>
      </a-form-item>
      <a-form-item
        label="手机"
        :labelCol="{span: 5}"
        :wrapperCol="{span: 19}"
      >
        <a-input
          type="text"
          autocomplete="false"
          :style="{width:'310px'}"
          v-decorator="['phone',{initialValue: defaultPhone, rules: validatorRules.phone.rule}]"
          placeholder="请输入手机号">
          <a-icon slot="prefix" type="phone" :style="{ color: 'rgba(0,0,0,.25)'}"/>
        </a-input>
      </a-form-item>
31
      <a-form-item
32
        label="验证码"
33 34 35
        :labelCol="{span: 5}"
        :wrapperCol="{span: 19}"
        v-if="show">
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
        <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>
53 54
      </a-form-item>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
55 56 57
        <a-button style="margin-left: 8px" @click="prevStep">上一步</a-button>
        <a-button type="primary" @click="nextStep" style="margin-left: 20px">下一步</a-button>
      </a-form-item>
58 59 60 61 62 63

    </a-form>
  </div>
</template>

<script>
64 65
  import {postAction} from '@/api/manage'

66 67
  export default {
    name: "Step2",
68 69
    props: ['userList'],
    data() {
70 71 72
      return {
        form: this.$form.createForm(this),
        loading: false,
73 74
        accountName: this.userList.username,
        dropList: "0",
75
        captcha: "",
76
        show: true,
77 78 79 80 81 82 83 84
        state: {
          time: 60,
          smsSendBtn: false,
        },
        formLogin: {
          captcha: "",
          mobile: "",
        },
85 86 87
        validatorRules: {
          captcha: {rule: [{required: true, message: '请输入短信验证码!'}, {validator: this.validateCaptcha}]},
          phone: {rule: [{required: true, message: '请输入手机号码!'}]},
88 89 90
        },
      }
    },
91 92 93 94 95 96 97 98
    computed: {
      defaultPhone: function(){
        if(this.userList.isPhone){
          return this.userList.phone
        }
        return null;
      }
    },
99
    methods: {
100
      nextStep() {
101 102 103 104 105
        let that = this
        that.loading = true
        this.form.validateFields((err, values) => {
          console.log(values);
          if (!err) {
106 107
            if (that.dropList == "0") {
              if (values.captcha == undefined) {
108
                this.cmsFailed("请输入短信验证码!");
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
              } else {
                var params = {}
                params.phone = this.userList.phone;
                params.smscode = values.captcha;
                postAction("/sys/user/phoneVerification", params).then((res) => {
                  if (res.success) {
                    console.log(res);
                    var userList = {
                      username: this.userList.username,
                      phone: this.userList.phone,
                      smscode: res.result
                    };
                    setTimeout(function () {
                      that.$emit('nextStep', userList)
                    }, 0)
                  } else {
                    this.cmsFailed(res.message);
                  }
                })
128 129 130 131 132

              }
            }


133 134
          }
        })
135
      },
136 137
      prevStep() {
        this.$emit('prevStep', this.userList);
138
      },
139
      getCaptcha(e) {
140 141
        e.preventDefault();
        let that = this;
142 143 144
        this.state.smsSendBtn = true;
        let interval = window.setInterval(() => {
          if (that.state.time-- <= 0) {
145 146 147 148 149 150 151 152 153 154 155 156
            that.state.time = 60;
            that.state.smsSendBtn = false;
            window.clearInterval(interval);
          }
        }, 1000);

        const hide = this.$message.loading('验证码发送中..', 0);
        let smsParams = {
          mobile: this.userList.phone,
          smsmode: "2"
        };
        postAction("/sys/sms", smsParams).then(res => {
157 158 159 160 161 162
          if (!res.success) {
            setTimeout(hide, 1);
            this.cmsFailed(res.message);
          }
          setTimeout(hide, 500);
        })
163
      },
164 165
      cmsFailed(err) {
        this.$notification['error']({
166
          message: "验证错误",
167
          description: err,
168 169 170
          duration: 4,
        });
      },
171 172
      handleChangeSelect(value) {
        var that = this;
173
        console.log(value);
174 175 176 177 178 179 180
        if (value == 0) {
          that.dropList = "0";
          that.show = true;
        } else {
          that.dropList = "1";
          that.show = false;
        }
181 182 183 184 185 186 187 188 189 190
      },
    }

  }
</script>

<style lang="scss" scoped>
  .stepFormText {
    margin-bottom: 24px;
  }
191 192 193 194 195

  .ant-form-item-label,
  .ant-form-item-control {
    line-height: 22px;
  }
196 197 198 199 200 201 202

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