<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="username">
                    <el-input type="text" v-model="ruleForm.username" 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>
                <div class="toRegister">
                    <el-link type="primary" class="btn" style="float:left;" :underline="false">联系客服
                        <div class="service">
                            <p style="color: #333">扫码加客服微信</p>
                            <img src="../assets/image/code.jpg">
                            <p><span style="color: #333">QQ：</span><span id="QQ">3052894409</span></p>
                        </div>
                    </el-link>
                    <el-link type="primary" style="margin-right:5px;" @click="dialogVisible=true" :underline="false">
                        使用说明
                    </el-link>
                    <el-link type="primary" @click="jumpTo" :underline="false">企业注册</el-link>
                </div>
            </el-form>
        </div>
        <el-dialog title="使用说明" :visible.sync="dialogVisible" width="500px">
            <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_管理员.docx" download="工时管家使用说明_管理员.docx" 
                        target="_blank">工时管家使用说明_管理员.docx</a></p>
            <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_项目经理.docx" download="工时管家使用说明_项目经理.docx" 
                        target="_blank">工时管家使用说明_项目经理.docx</a></p>
            <p><a style="color:#409EFF;text-decoration:none" href="upload/工时管家使用说明_普通员工.docx" download="工时管家使用说明_普通员工.docx" 
                        target="_blank">工时管家使用说明_普通员工.docx</a></p>
            
        </el-dialog>
    </div>
</template>

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

            jumpTo() {
                this.$router.push({ path: '/register' });
            },

            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: '/daily' });
                            } 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: 380px;
                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;
                }
            }
        }
    }

    .toRegister {
        margin: 15px 0;
        text-align: right;
        position: relative;

        .service {
            display: none;
            width: 120px;
            position: absolute;
            background: #fff;
            text-align: center;
            padding: 10px;
            left: -30px;
            top: -210px;
            border-radius: 5px;
            box-shadow: 3px 3px 10px #dfdfdf;
            img {
                width: 80px;
            }
        }
    }

    .btn:hover .service {
        display: block;
    }
</style>