<div id="app" v-cloak>
    <div class="frame">
        <div class="login-box">
            <div class="login-title">系统登录</div>

            <el-form :model="form" :rules="rules" ref="form" class="form">
                <el-form-item prop="username">
                    <el-input placeholder="用户名" v-model="form.username">
                        <template slot="prepend"><i class="icon iconfont el-icon-user"></i></template>
                    </el-input>
                </el-form-item>

                <el-form-item prop="password">
                    <el-input placeholder="密码" v-model="form.password" type="password">
                        <template slot="prepend"><i class="icon iconfont el-icon-lock"></i></template>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" style="width: 100%" :loading="isLogin" :disabled="isLogin"
                               @click="submitForm('form')">登录
                    </el-button>
                </el-form-item>
            </el-form>

            <a class="tip">系统登录</a>
        </div>
    </div>

</div>
<style>
    #app {
        width: 100%;
        height: 100%;
        padding: 0;
        margin: 0;
        display: flex;
        background: #001d3a;
        justify-content: center;
        align-items: center;
    }

    .frame {
        width: 600px;
        height: 500px;
        background: #42424263;
        border-radius: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        box-shadow: 0 0 10px 0 #afafaf52;
    }

    .login-box {
        display: inline-block;
        background: #fff;
        border-radius: 5px;
        text-align: left;
    }

    .login-title {
        line-height: 50px;
        border-bottom: 1px solid #e8e8e8;
        font-weight: bold;
        text-align: left;
        padding-left: 20px;
        font-size: 15px;
        height: 50px;
        color: #757575;
    }

    .form {
        width: 300px;
        margin-top: 20px;
        margin-left: 20px;
        margin-right: 20px;
    }

    .form .el-input-group__prepend {
        padding: 10px;
    }

    .tip {
        padding: 5px;
        display: inline-block;
        text-align: center;
        color: #b7b7b7;
        width: 100%;
        margin-bottom: 10px;
    }

</style>

<script type="text/javascript">
    var app = new Vue({
        el: "#app",
        data: {
            form: {
                username: '',
                password: ''
            },
            rules: {
                username: [
                    {required: true, message: '请输入用户名', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '请输入密码', trigger: 'change'}
                ],
            },
            isLogin: false
        },
        mounted: function () {

        },
        methods: {
            submitForm: function (formName) {
                this.$refs[formName].validate(function (valid) {
                    if (valid) {
                        this.isLogin = true;
                        ajax.login(this.form).then(function (response) {
                            this.isLogin = false;
                            if (response.errors.length > 0) {
                                nav.e(response.errors[0].message);
                            } else {
                                location.href = "/"
                            }
                        }.bind(this))
                    } else {
                        return false;
                    }
                }.bind(this));
            },
            resetForm: function (formName) {
                this.$refs[formName].resetFields();
            }
        },
    })
</script>
