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

            <el-form class="content" :model="form" :rules="rules" ref="form">
                <el-form-item prop="username">
                    <el-input placeholder="用户名" v-model="form.username" size="small" prefix-icon="el-icon-user"></el-input>
                </el-form-item>

                <el-form-item prop="password">
                    <el-input placeholder="密码" v-model="form.password" size="small" type="password" prefix-icon="el-icon-lock"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" style="width: 100%" size="small"  :loading="isSubmit" :disabled="isSubmit" @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;
    }

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

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

    .wrapper .login-box .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;
    }

    .wrapper .login-box .content {
        width: 250px;
        margin-top: 20px;
        margin-left: 20px;
        margin-right: 20px;
    }

    .wrapper .login-box .el-form-item{
        margin-bottom: 15px;
    }

    .wrapper .login-box .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({
        mixins: [mixin],
        el: "#app",
        data: {
            form: {
                username: '',
                password: ''
            },
            rules: {
                username: [
                    {required: true, message: '请输入用户名', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '请输入密码', trigger: 'change'}
                ],
            }
        },
        mounted: function () {

        },
        methods: {
            submitForm: function (formName) {
                this.$refs[formName].validate(function (valid) {
                    if (valid) {
                        this.isSubmit = true;
                        new Ajax("wsys", "User").method("login").post(this.form, function (response) {
                            this.isSubmit = false;
                            if (response.errors.length > 0) {
                                nav.e(response.errors[0].message);
                            } else {
                                nav.i("登录成功.", function () {
                                    nav.toHome();
                                });
                            }
                        }.bind(this));
                    } else {
                        return false;
                    }
                }.bind(this));
            },
            resetForm: function (formName) {
                this.$refs[formName].resetFields();
            }
        },
    })
</script>
