<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

import { menuStatusStore, userInfoStore } from '@/stores';

import CpdmLeave from '../components/CpdmLeave.vue'
const leave = ref()
// import url from '../assets/home/trademark.png';
//选中的索引
const userInfo = userInfoStore()

const menuStatus = menuStatusStore()

const activeIndex = ref<string>()
activeIndex.value = menuStatus.activeIndex
// app.config.globalProperties.$globalMsg = '2'

const visible = ref<boolean>(false)

//选中菜单事件
const handleSelect = (key: string, keyPath: []) => {
    menuStatus.saveActiveIndex(key)
    activeIndex.value = key;
    if (key == '1') {
        router.push({ name: 'homeView' })

    } else if (key == '2') {
        router.push({ name: 'popularizationScience' })

    } else if (key == '3') {
        router.push({ name: 'community', })

    } else if (key == '4') {
        router.push({ name: 'plan', })

    } else if (key == '5') {
        router.push({ name: 'testRecord' })

    }
    // menuStatus.saveActiveIndex(key)
}
//点击登录按钮
const login = () => {
    menuStatus.saveActiveIndex('6')
    router.push({ name: 'login', params: {} })
}
const falgMenu = ref<boolean>(false)
//鼠标移入事件
const comeMenu = () => {
    falgMenu.value = true
}
//鼠标移出事件
const leaveMenu = () => {
    falgMenu.value = false
}

const updatePassFun = () => {
    menuStatus.saveActiveIndex('6')
    router.push({ name: 'updatePas' })
}

const exitFun = () => {
    //退出登录清除缓存
    visible.value = true
    // userInfo.clearUserInfo()
    //跳转到首页

}
const comT = () => {
    visible.value = false
    userInfo.clearUserInfo()
    //跳转到首页
    router.push({ name: 'homeView' })
}
//设置显示字段长度
const formatterName = (val: string) => {
    if (val == undefined) {
        return ''
    }
    if (val.length > 3) {
        return val.substring(0, 3) + '...'
    } else {
        return val
    }
}
//打开弹出框--显示弹出框
const leaveFun = () => {
    leave.value.open()
}
</script>

<template>

    <!-- :style="{ backgroundColor: activeIndex == '1' ? '#ffffff' : '' }" -->
    <div class="header_qp" :style="{ backgroundColor: activeIndex == '1' ? 'transparent' : '#3B3B3B' }">
        <div class="header_p">
            <div class="header_image">
                <!-- <img style="width: 239px; height: 55px" src="../assets/home/trademarkNew.png"></img> -->
                <!-- <img style="width: 239px; height: 55px" src="../assets/home/trademarkNew.png"></img> -->
                <!-- <div>学生心理健康测评系统</div> -->
                <div style="display: flex;align-items: center;">
                    <span class="home_line_1"></span>
                    <img width="30px" style="margin-left: 10px;" src="../assets/logo_white.png" alt="">
                    <!-- <img style="width: 20vw;" src="../assets/home/group_title.png" alt=""> -->
                    <div style="display: flex;flex-direction: column;margin-left:6px">
                        <span style="color: #ffffff;font-size: 26px;font-weight: 100;">学生心理健康测评系统</span>
                        <span style="color: #ffffff;font-weight: 100;font-size: 14px;">Student psychological health
                            assessment system</span>
                    </div>
                </div>
            </div>
            <el-menu :default-active="activeIndex" class="el-menu-demo" style="display: flex;" mode="horizontal"
                :ellipsis="false" @select="handleSelect">
                <el-menu-item index="1"><span
                        :class="{ 'underlined-text': activeIndex == '1' }">首&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;页</span></el-menu-item>


                <!-- <el-badge :value="200" :max="99" class="item">
                <el-menu-item index="4">测试计划</el-menu-item>
            </el-badge> -->
                <el-menu-item index="4">
                    <div class="badge_custom" v-show="userInfo.planCurrentNum != 0">
                        {{ userInfo.planCurrentNum }}
                    </div>
                    <span :class="{ 'underlined-text': activeIndex == '4' }">测试计划</span>
                </el-menu-item>
                <el-menu-item index="5">
                    <div class="badge_custom" v-show="userInfo.unreadNum != 0">
                        {{ userInfo.unreadNum }}
                    </div>
                    <span :class="{ 'underlined-text': activeIndex == '5' }">测试记录</span>

                </el-menu-item>
                <el-menu-item index="2"><span
                        :class="{ 'underlined-text': activeIndex == '2' }">更多测试</span></el-menu-item>
                <el-menu-item index="3"><span
                        :class="{ 'underlined-text': activeIndex == '3' }">留言社区</span></el-menu-item>
            </el-menu>
            <span class="home_line"></span>
            <div class="login_button_bg" @mouseenter="comeMenu" @mouseleave="leaveMenu"
                v-show="userInfo.userInfo.userName">
                <span :title="userInfo.userInfo.userName">{{ formatterName(userInfo.userInfo.userName) }}</span>
                <transition>
                    <div class="login_user" v-show="falgMenu">
                        <div class="update_pass" @click="updatePassFun">
                            修改密码
                        </div>
                        <!-- <div class="exit_login" @click="leaveFun">
                            我的请假
                        </div> -->
                        <div class="exit_login" @click="exitFun">
                            退出登录
                        </div>
                    </div>
                </transition>

            </div>

            <div class="login_button_bg" v-show="!userInfo.userInfo.userName" @click="login">

                <span v-if="!userInfo.userInfo?.userName">登录</span>
            </div>
            <el-dialog v-model="visible" :show-close="true" width="500" style="border-radius: 40px;" class="dig_kg">
                <template #header="{ close, titleId, titleClass }">
                    <div class="my-header" style="text-align: center;">
                        <div class="exit_login_title">退出登录</div>
                        <div class="exit_login_info">是否退出当前账号?</div>
                        <div class="start_button_out">
                            <div class="start_button_self" @click="comT">
                                确定
                            </div>
                        </div>

                    </div>
                </template>


            </el-dialog>
        </div>
    </div>
    <CpdmLeave ref="leave" />
</template>
<style scoped>
.home_line_1 {
    display: flex;
    width: 1px;
    height: 50px;
    background-color: #ffffff;
}

.home_line {
    width: 1px;
    height: 50%;
    border-left: 1px solid #ffffff;
    /* background-color: #ffffff; */
}

.underlined-text {
    position: relative;
    display: inline-block;
}

.underlined-text::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 10px;
    border-bottom: 1px solid;
}


:deep(.dig_kg> .el-dialog__header) {
    padding-right: 0px !important;
}
</style>
<style lang="scss" scoped>
.el-menu {
    background-color: transparent !important
}

.exit_login_title {
    text-align: center;
    color: #222222;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 3px;
}

.exit_login_info {
    text-align: center;
    letter-spacing: 3px;
    font-size: 18px;
    margin-top: 20px;
}

.start_button_out {
    margin-top: 40px;
    // margin-bottom: 40px;
    display: flex;
    flex-direction: row;
    justify-content: center;

    .start_button_self {
        cursor: pointer;
        // width: 100px;
        border-radius: 5px;
        // border: 1px solid #48D68E;
        color: #ffffff;
        background-color: #3B3B3B;
        // margin-right: 20px;
        padding: 5px 50px;
        cursor: pointer;
        display: flex;
        align-items: center;
        background: url(../assets/zs/bottom_new.png) no-repeat;
        background-size: 100% 100%;

    }
}

.badge_custom {
    position: absolute;
    background-color: #FF52CE;
    right: -18px;
    top: 0px;
    text-align: center;
    line-height: 18px;
    width: 18px;
    color: 10px;

    font-weight: 300;
    font-size: 10px;
    color: #3B3B3B;
    font-weight: 700;
    border-radius: 18px;
}

//整个菜单底部样式
.el-menu--horizontal.el-menu {

    border-bottom: 0px solid var(--el-menu-border-color);
    display: flex;
    align-items: center;
}

.el-menu--horizontal>.el-menu-item {
    width: 120px;
    height: 40px;
    align-items: center;
    border-bottom: 0px solid transparent;
    // color: var(--el-menu-text-color);

    color: #ffffff;
    display: inline-flex;
    // height: 100%;
    justify-content: flex-end;
    padding: 0px;
    align-items: center;
    border-radius: 12px;
    margin: 0;
}

.el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
.el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
    background-color: transparent;
    color: #ffffff !important;
    border-radius: 12px;
}

//激活某个菜单时   底部样式
.el-menu--horizontal>.el-menu-item.is-active {
    border-bottom: 0px solid var(--el-menu-active-color);
    // color: var(--el-menu-active-color) !important;
    color: #ffffff !important;
    background: transparent;
    border-radius: 12px;
    height: 40px;
    font-weight: 700;

}

.header_qp {

    display: flex;
    justify-content: center;
    width: 100%;

    .header_p {
        // background-color: #ffffff;
        padding-top: 10px;
        padding-bottom: 10px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 1200px;


        .header_image {
            // flex: 1
            // margin-right: 100px;

            div {
                color: #48D68E;
                font-weight: 700;
                // font-size: 26px;
                // -webkit-transform: skew(-10deg);
                // letter-spacing: 2px;
                // /* for Chrome||Safari */
                // -ms-transform: skew(-10deg);
                // /* for IE */
                // -moz-transform: skew(-10deg);
                // /* for Firefox */
                // -o-transform: skew(-10deg);
                // /* for Opera */
            }
        }

        .login_button_bg {
            position: relative;

            // border-radius: 4px;
            border: 1px solid #ffffff;
            color: #216EE2;
            font-weight: 700;
            padding: 8px 20px;
            cursor: pointer;
            display: flex;
            align-items: center;
            width: 60px;
            justify-content: center;
            background-color: #ffffff;

            .login_user {
                background-color: #236EE3;
                width: 100px;
                position: absolute;
                // background-color: #ffffff;
                // bottom: -105px;
                bottom: -105px;
                // margin-left: calc(10% - 20px);
                z-index: 200;
                color: #000000;
                border: 1px solid #ffffff;

                .update_pass {
                    text-align: center;
                    margin-top: 20px;
                    // padding: 5px;
                    color: #ffffff
                }

                .update_pass:hover {
                    text-align: center;
                    margin-top: 20px;
                    color: #48D68E // padding: 5px;
                }

                .exit_login {
                    text-align: center;
                    // padding: 5px;
                    margin-top: 20px;
                    margin-bottom: 20px;
                    color: #ffffff
                }

                .exit_login:hover {
                    text-align: center;
                    // padding: 5px;
                    margin-top: 20px;
                    margin-bottom: 20px;
                    color: #48D68E // padding: 5px;
                }
            }
        }

        .flex-grow {
            flex: 1;
        }

        .menu_gen {
            width: 80px;
            height: 20px;
            font-family: Alibaba PuHuiTi 2.0;
            font-weight: normal;
            font-size: 20px;
            color: #333333;
            line-height: 26px
        }
    }

}
</style>
