<template>
    <div class="sidebar-pack" :style="{'width': sidebarClosed ? '64px' : '256px'}">
        <div class="menu-header-pack" :style="'height: menuHeight'">
            <el-menu
                :collapse="sidebarClosed"
                :default-active="$route.path"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose"
                background-color="#001529"
                text-color="#bcbcbc"
                active-text-color="#fff">

                <sidebar-item
                    v-for="route in routers"
                    :key="route.path"
                    :item="route"
                    :base-path="route.path">
                </sidebar-item>
            </el-menu>
        </div>
        <div class="support-pack" :style="{'display': sidebarClosed ? 'none' : 'block'}">山东万腾电子科技有限公司提供技术支持</div>
    </div>
</template>

<script>
    import { mapState, mapGetters } from 'vuex'

    import SidebarItem from './SidebarItem'

    export default {
        components: {
            SidebarItem
        },
        name: 'Sidebar',
        data () {
            return {
                // 菜单栏区域高度
                menuHieght: 0
            }
        },
        computed: {
            ...mapState({
                sidebarClosed: state => state.sidebarClosed,
                routers: state => state.Permission.routers
            })
        },
        methods: {
            handleOpen (key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose (key, keyPath) {
                console.log(key, keyPath);
            }
        },
        mounted () {
            setTimeout(() => {
                this.menuHeight = document.querySelector('.menu-header-pack').offsetHeight - 65;
            }, 0)
        }
    }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
    @import "@/styles/mixin.scss";
    .sidebar-pack {
        position: absolute;
        top: 64px;
        bottom: 0;
        overflow-y: auto;
        background-color: #001529;

        z-index: 10;
        -webkit-box-sizing: 2px 0 6px rgba(0,21,41,.35);
        -moz-box-sizing: 2px 0 6px rgba(0,21,41,.35);
        -ms-box-sizing: 2px 0 6px rgba(0,21,41,.35);
        -o-box-sizing: 2px 0 6px rgba(0,21,41,.35);
        box-shadow: 2px 0 6px rgba(0,21,41,.35);

        transition: width 0.4s;
        -moz-transition: width 0.4s;
        -webkit-transition: width 0.4s;
        -o-transition: width 0.4s;

        .menu-header-pack {
            position: absolute;
            overflow-y: auto;
            bottom: 40px;
            top: 0;
            left: 0;
            right: 0;

            .el-menu {
                border-right: 0px solid #333440;
            }
        }

        .support-pack {
            position: absolute;
            bottom: 0;
            font-size: 12px;
            width: 100%;
            height: 40px;
            line-height: 40px;
            color: rgb(188, 188, 188);
            text-align: center;
        }
    }
</style>
