<template>
    <div class="login">
        <div class="login-par">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
                <div class="login-logo">
                    <img src="../assets/image/login_logo.png" style="width:80px;height:80px;"/>
                </div>
                <h3 class="title">工时管家</h3>
                <el-form-item class="login-input" prop="account">
                    <el-input type="text" v-model="ruleForm.account" autocomplete="off" placeholder="账号" clearable prefix-icon="el-icon-user-solid"></el-input>
                </el-form-item>
                <el-form-item class="login-input" prop="password">
                    <el-input type="password" v-model="ruleForm.password" @keyup.enter.native="handleSubmit" autocomplete="off" placeholder="密码" show-password prefix-icon="el-icon-lock"></el-input>
                </el-form-item>
                <el-form-item class="login-button" style="width:100%;">
                    <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit" :loading="logining">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                logining: false,
                // 登录信息
                ruleForm: {
                    account: '',
                    password: ''
                },
                rules: {
                    account: [{ required: true, message: '请输入账号', trigger: 'blur' },],
                    password: [{ required: true, message: '请输入密码', trigger: 'blur' },]
                }
            };
        },
        methods: {
            handleReset2() {
                this.$refs.ruleForm.resetFields();
            },

            handleSubmit(ev) {
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        var _this = this;
                        this.logining = true;
                        this.http.post(this.port.manage.login, this.ruleForm , res => {
                            this.logining = false;
                            if (res.code == "ok") {
                                sessionStorage.setItem('user', JSON.stringify(res.data));
                                this.$router.push({ path: '/desktop' });
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }, error => {
                            this.logining = false;
                            this.$message({
                                message: error,
                                type: 'error'
                            });
                        })
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
    .login {
        height: 100%;
        .login-par {
            width: 100%;
            min-height: 100%;
            background: #f0f2f5 url('../assets/image/background.png') no-repeat 50%;
            background-size: 100%;
            padding: 110px 0 144px;
            position: relative;
            box-sizing: border-box;
            .login-logo {
                text-align: center;
                margin: 0 0 20px 0;
            }
            .login-container {
                -webkit-border-radius: 5px;
                border-radius: 5px;
                -moz-border-radius: 5px;
                background-clip: padding-box;
                width: 315px;
                height: 365px;
                padding: 25px 35px 25px 35px;
                background: #fff;
                border: 1px solid #eaeaea;
                box-shadow: 0 0 5px #cac6c6;
                border-top: 10px solid #20a0ff;
                margin:auto;
                .title {
                    font-size: 20px;
                    margin: 0px auto 40px auto;
                    text-align: center;
                    color: #505458;
                }
                .remember {
                    margin: 0px 0px 35px 0px;
                }
                .login-input {
                    margin: 30px 0 0 0;
                }
                .login-button {
                    margin: 30px 0 0 0;
                }
                .login-button .el-button {
                    padding: 14px;
                }
            }
        }
    }
</style>