<template>
  <div>
    <!--标题-->
    <ToPBarNormal :title="title"></ToPBarNormal>
    <!--提示信息-->
    <div class="result-cont">
      <p style="padding:10px;text-align: center">更改手机号码需要短信验证。</p>
      <div class="phone_edit">
        <group>
          <x-input title="+86" v-model="mobile" :max="11" is-type="china-mobile" keyboard="number"
                   placeholder="请输入手机号"></x-input>
        </group>
      </div>
      <div style="margin-top: 20px" class="login-exit" @click="_next">下一步</div>
    </div>
  </div>
</template>

<script>
  import ToPBarNormal from '../../../components/topBar/TopBarNormal'
  import {XInput, Group} from 'vux'

  export default {
    components: {
      ToPBarNormal,
      XInput,
      Group,
    },
    name: "phone-edit",
    data() {
      return {
        title: '手机号码',
        mobile: ''
      }
    },
    methods: {
      //获取验证码
      _next() {
        if (this.mobile) {
          let myReg = /^1\d{10}$/;
          if (myReg.test(this.mobile)) {
            this._ok();
          } else {
            this._msg('号码填写错误');
          }
        } else {
          this._msg('请输入手机号');
        }
      },
      _ok() {
        let data = {
          mobile: this.mobile,
          module: 'bindChangeMobile'
        };
        this.$store.dispatch('SystemManage/getCode', data).then(() => {
          if (this.$store.state.SystemManage.model) {
            this.$router.push({path: '/sys/sms', query: {mobile: this.mobile}});
          } else {
            this._msg('验证码发送失败');
          }
        });
      },
      //提示
      _msg(msg) {
        this.$vux.toast.show({
          type: 'text',
          width: '10em',
          text: msg,
          time: 1000
        });
      },
    }
  }
</script>
