<template>
    <body id="login-page">
        <el-form class="login-container" label-position="left" label-width="0px">
            <h3 class="login_title">请选择系统</h3>
            <el-form-item style="width: 100%">
                <el-button color="#87CEFA" style="width: 100%;  border: none" @click="loginToWms">WMS系统</el-button>
            </el-form-item>
            <!-- <el-form-item style="width: 100%">
                <el-button color="#87CEEB" style="width: 100%;  border: none" @click="loginToPda">手持入库系统</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
                <el-button color="#AFEEEE" style="width: 100%;  border: none" @click="loginToSideScan">线边扫码系统</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
                <el-button color="#ADD8E6" style="width: 100%;  border: none" @click="loginToWcs">WCS系统</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
                <el-button color="#B0E0E6" style="width: 100%;  border: none" @click="loginToMonitor">监控系统</el-button>
            </el-form-item> -->
        </el-form>
    </body>
</template>

<script setup>
import { getUser } from '@/api/login.js'
import { ElMessage, ElLoading } from 'element-plus'
import { onMounted } from 'vue';
import store from '@/store'
import router from '@/router'
const user = store.getters.getUserNam// 用户名
const token = store.getters.getToken// 密码
// 登录到WMS系统
const loginToWms = () => {
    router.replace({ path: '/home' })
}
const loginToPda = () => {
    router.replace({ path: '/goodsInPda' })
}
const loginToSideScan = () => {
    router.replace({ path: '/sideScan' })
}
// 登录到WCS系统
const loginToWcs = () => {
    const wcsUrl = `https://cxlasrs.ecorp.cat.com/wcs/#/login?user=user&pwd=user`
    window.location.href = wcsUrl// 打开新窗口
}
const loginToMonitor = () => {
    const mpnitorUrl = `https://cxlasrs.ecorp.cat.com?user=${user}&token=${token}`
    window.location.href = mpnitorUrl// 当前窗口跳转
}

onMounted(() => {
    if (router.currentRoute.value.query.code != undefined) {
        console.log(router.currentRoute.value.query.code)
        const loading = ElLoading.service({
            lock: true,
            text: 'Loading',
            background: 'rgba(0, 0, 0, 0.7)',
        })
        const codeInfo = {
            code: router.currentRoute.value.query.code,
            state: router.currentRoute.value.query.state
        }
        getUser(codeInfo).then(res => {
            loading.close()
            if (res.data.code == 0) {
                store.commit('mutationUser', res.data.returnData.user)// 用户信息
                store.commit('mutationMenu', res.data.returnData.menuList)// 菜单信息
                router.replace({ path: '/' })
            } else {
                ElMessage.error(res.data.message)
            }
        }).catch(err => {
            console.log(err)
            loading.close()
            ElMessage.error('登录失败！')
        })
    }
})
</script>
  
<style scoped>
#login-page {
    /* background: url("../assets/img/bg.jpg") no-repeat; */
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
}

body {
    margin: 0px;
}

.login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
}

.login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
}
</style>  