<template>
    <div class="wrapper" style="min-width:1300px;">
        <div class="img-block">
            <img src="../../assets/image/jz-logo.png" />
        </div>
        <div class="right-block">
            <div class="login-container">
                <div class="login-title">
                    <p>欢迎登录</p>
                    <p>鲸致生活-<span style="color:#20B6EB;">{{ menuTitle }}V3.11</span></p>
                    <p class="slogan">因为有你 所以鲸致 JINGZHI LIFE</p>
                </div>
                <el-form :model="param" :rules="rules" ref="login" label-position="left" class="login-form"> 
                    <el-form-item prop="username">
                        <el-input v-model="param.username" placeholder="用户名">
                            <i slot="prepend" class="el-icon-user" style="font-size: 20px;"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        
                        <el-input type="password" show-password placeholder="密码" v-model="param.password"    @keyup.enter.native="submitForm()">
                            <i slot="prepend" class="el-icon-lock" style="font-size: 20px;"></i>
                        </el-input>
                    </el-form-item>
                    <div class="login-btn">
                        <el-button type="primary"
                            style=" background-color: #20B6EB;  border-color: #20B6EB;  height: 48px;  font-size: 18px;width: 100%;"
                            @click="submitForm()">登录</el-button>
                    </div>
                </el-form>

                <div class="bottom-company">
                    <div class="line"></div>
                    <div class="compangy-name">上海宅易丞鲸致网络科技有限公司</div>
                    <div class="line"></div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import ajaxAuth from '@/script/api/auth.js';
import globalData from '@/components/common/globaldata/global.data';
export default {
    data: function () {
        return {
            menuTitle: '',
            param: {
                username: '',
                password: ''
            },
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
            }
        };
    },
    mounted() {
        this.isIETrue()
    },
    created() {
        let currentHost = window.location.host;
        // console.log(currentHost);
        if (currentHost.indexOf('lixiang') != -1) {
            this.menuTitle = '狸想培训信息管理系统';
        } else {
            this.menuTitle = '数据分析系统';
        }
    },

    methods: {
        //是IE浏览器就提示信息
        isIETrue() {
            var userAgent = navigator.userAgent;
            // console.log(userAgent)
            var isIeL = !!window.ActiveXObject || 'ActiveXObject' in window;
            console.log('IELLQ ' + isIeL); //判断是否IE浏览器
            if (isIeL) {
                var body = document.getElementsByTagName('body')[0];
                var p = document.createElement('p');
                p.className = 'navigator-tip';
                p.innerHTML = '本网站在谷歌chrome浏览器下效果最佳，建议使用谷歌chrome浏览器访问！';
                body && body.insertBefore(p, body.firstChild);
            }
        },

        submitForm() {
            this.$refs.login.validate(valid => {
                if (valid) {
                    ajaxAuth
                        .$ajaxLogin({
                            userAccount: this.param.username,
                            userPassword: this.param.password
                        })
                        .then(res => {
                            // console.log(res);
                            if (navigator.userAgent.indexOf('Trident') > -1) {
                                res = eval('(' + res.data + ')');
                                res = { data: res };
                            }

                            if (res.data.errno == 0) {

                                globalData.userInfo = res.data.data.user;
                                globalData.token = res.data.data.token;


                                window.localStorage.setItem('menulist', JSON.stringify(res.data.data.menulist));
                                window.localStorage.setItem('userInfo', JSON.stringify(res.data.data.user));
                                window.localStorage.setItem('token', res.data.data.token);

                                this.$message.success('登录成功！');
                                localStorage.setItem('ms_username', this.param.username);
                                this.$router.push('/');
                            }
                            if (res.data.errno == -1) {
                                this.$message.warning(res.data.data + ' !');
                            }
                        })
                        .catch(err => {
                            console.log(err);
                            this.$message.warning(err.data.data + ' !');
                        });
                } else {
                    this.$message.error('请输入账号和密码');
                    console.log('error submit!!');
                    return false;
                }
            });
        }
    }
};
</script>

<style  lang="scss">
.login-container .el-input input {
    color: #333;
}

.login-container {

    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 80px 40px;

    .login-form {
        position: relative;
        width: 454px;
        margin: 0 auto;
    }

    .tips {
        font-size: 14px;
        color: #fff;
        margin-bottom: 10px;

        span {
            &:first-of-type {
                margin-right: 16px;
            }
        }
    }

    .svg-container {
        padding: 6px 5px 6px 15px;
        vertical-align: middle;
        width: 30px;
        display: inline-block;
        color: #888;
    }

    .logo-form {
        border: 0px;
        text-align: center;
    }

    .logo {
        width: 100px;
    }

    .title-container {
        position: relative;

        .title {
            font-size: 26px;
            color: #333;
            margin: 0px auto 40px auto;
            text-align: center;
            font-weight: bold;
        }
    }

    .copyright {
        font-size: 12px;
        color: #fff;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translate(-50%, -50%);
        margin-bottom: 20px;
        letter-spacing: 0.6px;

        a {
            font-weight: bold;
            border-bottom: 1px solid #fff;
            font-family: "PingFangSC-Semibold", sans-serif;
        }
    }

    .el-input {
        // display: inline-block;
        height: 47px;
        width: 98%;
        line-height: 47px;

        input {
            background: transparent;
            border: 0px;
            -webkit-appearance: none;
            border-radius: 0px;
            padding: 12px 5px 12px 15px;
            color: #333;
            height: 47px;
            caret-color: #333;
            background-color: #fff;

            &:-webkit-autofill {
                background-color: #fff;
                box-shadow: 0 0 0px 1000px #fff inset !important;
            }
        }
    }
    .el-input-group__prepend{
        background-color: #fff;
        border: 0px;
    }

    .el-form-item {
        border: 1px solid #ccc;
        border-radius: 5px;
    }

    .el-form-item:hover {
        border: 1px solid #09afff;
    }
}

.el-input_inner {
    color: #fff;
}

.bottom-company {
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #AFBCCC;
    font-size: 13px;
    margin-top: 40px;
}

.bottom-company .compangy-name {
    margin: 0 20px;
}

.bottom-company .line {
    width: 100px;
    height: 1px;
    background: #AFBCCC;

}

.right-block {
    flex: 2;
    background: url('../../assets/image/login-right.png') no-repeat center center;
    background-size: cover;
    min-height: 600px;
    height: 100%;
    display: flex;
    align-items: center;
}

.login-title {
    width: 454px;
}

.login-title p {
    color: #000;
    font-size: 24px;
    font-weight: bold;
}

.login-title p.slogan {
    font-size: 14px;
    color: #B3B3B3;
    margin: 20px 0 40px;
}

.wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 600px;
}

.img-block {
    flex: 3;
    background: url('../../assets/image/login-left.png') no-repeat center center;
    background-size: cover;
    height: 100%;
    min-height: 480px;
    padding: 88px 0 0 88px;
    min-width: 800px;
}

.img-block img {
    width: 200px;
    /* height:60px; */
}
 
</style>