<template>
    <bread-page>
        <menu-page>
            <div class="menu-left" slot="menuList">
                <el-menu :default-active="active" router @select="handleSelect">
                    <el-submenu index="1">
                        <template slot="title">
                            <span>个人中心</span>
                        </template>
                        <el-menu-item index="/newsInfo">消息中心</el-menu-item>
                        <el-menu-item index="/publish/patent?caseType=DECLASSIFICATION">我发布的</el-menu-item>
                        <el-menu-item index="/userEdit">编辑资料</el-menu-item>
                        <el-menu-item index="/security">账号安全</el-menu-item>
                    </el-submenu>
                </el-menu>
            </div>

            <div class="main">
                <router-view />
            </div>
        </menu-page>
    </bread-page>
</template>

<script>
import { mapState } from 'vuex';
import BreadPage from '../../components/page/BreadPage.vue';
import MenuPage from '../../components/page/MenuPage.vue';
export default {
    components: { BreadPage, MenuPage },
    computed: {
        active() {
            return this.$route.meta.prePath || this.$route.path;
        },
        // isAuth() {
        //     return this.institutionInfo || this.personalInfo;
        // },
        ...mapState(['userInfo', 'institutionInfo', 'personalInfo', 'loginType']),
        type() {
            return this.userInfo.authorities.find(item => {
                return item.name == 'ROLE_INSTITUTION' || item.name == 'ROLE_PERSONAL';
            });
        }
    },
    created() {
        // if()
        this.handleSelect();
    },
    methods: {
        handleSelect(key) {
            if (key == '/userEdit') {
                if (this.type) {
                    if (this.type.name == 'ROLE_INSTITUTION') {
                        this.$nextTick(() => {
                            if (this.institutionInfo.status == 'PASS') {
                                this.$router.push('/userEdit');
                            } else if (this.institutionInfo.status == 'DENY') {
                                this.$router.push('/Authenticationsfail');
                            } else {
                                this.$router.push('/Authentications');
                            }
                        });
                    } else if (this.type.name == 'ROLE_PERSONAL') {
                        this.$nextTick(() => {
                            if (this.personalInfo.status == 'PASS') {
                                this.$router.push('/userEdit');
                            } else if (this.personalInfo.status == 'DENY') {
                                this.$router.push('/Authenticationfail');
                            } else {
                                this.$router.push('/Authentication');
                            }
                        });
                    }
                } else {
                    this.$router.push('/userEdit');
                }
            }
        }
    }
};
</script>

<style lang="less" scoped>
.menu-left {
    min-height: 600px;
    background-color: #fff;
}

.main {
    .flex-col();
    background-color: #fff;
    flex-grow: 1;
    min-height: 1100px;
}
</style>
