<template>
    <div class="container">
        <el-steps :space="180" :active="2" align-center>
            <el-step title="验证当前手机号"></el-step>
            <el-step title="绑定新手机号"></el-step>
            <el-step title="修改完成"></el-step>
        </el-steps>
        <el-form :label-position="labelPosition" ref="form2" label-width="290px" :model="ruleForm" :rules="rules">
            <el-form-item
                label="新手机号"
                prop="phone"
                :rules="{
                    pattern: /^1[3-9]\d{9}$/,
                    message: '请输入正确的手机号',
                    trigger: 'blur'
                }"
            >
                <el-input
                    type="number"
                    style="width: 300px"
                    v-model="ruleForm.phone"
                    placeholder="请输入新的手机号码"
                ></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="code">
                <el-input style="width: 300px" type="number" v-model="ruleForm.code" placeholder="请输入4位验证码">
                    <span @click="send" style="color: #fdfb60; cursor: pointer; font-size: 13px" slot="suffix">{{
                        time === 0 ? '发送验证码' : `重新发送${time}s`
                    }}</span>
                </el-input>
            </el-form-item>
        </el-form>
        <div class="btn1">
            <div class="btn2">
                <el-button type="primary" @click="phoneSend">确认</el-button>
                <div class="btn3" @click="Jump">返回</div>
            </div>
        </div>
    </div>
</template>
<script>
import { mapState } from 'vuex';
import phone from '../mixins/phone';
export default {
    mixins: [phone],
    data() {
        return {
            labelPosition: 'right',
            ruleForm: {
                phone: '',
                code: ''
            },
            time: 0,
            rules: {
                phone: { required: true, message: '请输入您的真实姓名', trigger: 'blur' },
                code: { required: true, message: '请输入验证码', trigger: 'blur' }
            }
        };
    },
    computed: {
        ...mapState(['userInfo'])
    },
    methods: {
        send() {
            if (this.time === 0) {
                this.sendMsg(this.ruleForm.phone);
            }
        },
        phoneSend() {
            this.$refs.form2.validate(valid => {
                if (valid) {
                    this.verifyMsg(this.ruleForm.phone, this.ruleForm.code)
                        .then(() => {
                            return this.$http.post('/user/bindPhone?phone=' + this.ruleForm.phone);
                        })
                        .then(() => {
                            this.$message.warning('更改成功');
                            setTimeout(() => {
                                this.$router.push('/securitysuccess');
                            }, 1000);
                        })
                        .catch(e => {
                            if (e) {
                                this.$message.warning(e.error);
                            }
                        });
                }
            });
        },
        Jump() {
            this.$emit('Jump');
        }
    }
};
</script>
<style>
input[type='number'] {
    -moz-appearance: textfield;
}
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
</style>
<style lang="less" scoped>
/deep/ .el-steps {
    margin-left: 329px;
}
/deep/.el-step:nth-child(1) {
    .el-step__icon {
        background: linear-gradient(143deg, @prim 0%, @warn 100%, @warn 100%);
        color: #ffffff;
        border: 0;
    }
}
/deep/.el-step:nth-child(2) {
    .el-step__icon {
        background: linear-gradient(143deg, @prim 0%, @warn 100%, @warn 100%) !important;
        color: #ffffff;
        border: 0;
    }
}
/deep/.el-step:nth-child(3) {
    .el-step__icon {
        background: #c8c9cc;
        color: #ffffff;
        border: 0;
    }
}
/deep/ .el-step__title.is-process {
    font-weight: 400;
    color: #939599;
}
/deep/ .el-step__title.is-wait {
    color: #939599;
}
/deep/ .el-form-item__error {
    left: 175px;
}
.container {
    .btn1 {
        margin-left: 10px;
        .btn2 {
            display: flex;
            justify-content: center;
            margin-top: 87px;
            .btn3 {
                width: 130px;
                height: 36px;
                background: #c4c7cc;
                border-radius: 4px;
                cursor: pointer;
                color: #ffffff;
                font-size: 13px;
                text-align: center;
                line-height: 36px;
                margin-left: 20px;
            }
        }
    }
}
</style>
