<template>
    <div class="verifyAccountBox">
        <el-form  :model="ruleForm" class="verifyAccount" ref="ruleForm"  style="width: 18%">
            <h1>神州餐厅管理系统-验证账号</h1>
            <br><br>
            <!--账号-->
            <el-form-item label="账号：" prop="us">
                <el-input v-model="ruleForm.us"
                          placeholder="请输入账号名"
                          maxlength="18"
                          show-word-limit></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" round @click="nextBtnClick('ruleForm')">下一步</el-button>
                <el-button type="primary" round @click="cancelBtnClick">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>


<script>
    const axios=require('axios');
    import Cookies from 'js-cookie';
    export default {
        data(){
            return{
                ruleForm:{
                    us:'',
                    emailAddress:''
                },
                rules:{
                    us:[
                        {required: true, message: '请输入账号', trigger: 'blur'},
                        {min: 5, max: 18, message: '长度在 5-18 个字符', trigger: 'blur'}
                    ],
                }
            }
        },
        created() {
            if (Cookies.get('username')) {
                this.ruleForm.us = Cookies.get('username');
            }
        },
        methods: {
//下一步
            nextBtnClick(){
                //刚进来直接点忘记密码，就设置Cookie，取消清空Cookie
                Cookies.set('username',this.ruleForm.us,1);

                axios.post('https://mz.tshe.cn/restauantCH/user/verifyAccount',{
                    us:this.ruleForm.us
                })
                    .then((res)=>{
                        console.log(res,'res!')
                        if(res.data.code==0){
                            this.$message.success(res.data.msg)
                            this.$router.push('/forgetPwd');
                        }
                        else if(res.data.code==-1){
                            this.$message.error(res.data.msg)
                        }
                        else if(res.data.code==-2){
                            this.$message.error(res.data.msg)
                        }
                        else if(res.data.code==-3){
                            this.$message.error(res.data.msg)
                        }
                    })
            },
//取消
            cancelBtnClick(){
                Cookies.remove('username',0);
                Cookies.remove('passWord',0);
                this.$router.go(-1);
            },
        }
    }
</script>

<style>
    .verifyAccount {
        margin: 250px auto 0  ;
    }
    .verifyAccountBox {
        text-align: center;
    }
</style>
