<template>
    <div class='page-header'>
        <div id='page-header-logo' class='page-logo'>
            <a href='index.html'>
                <img src='@/assets/logo.png' alt='logo' class='logo-default'>
            </a>
            <div class='menu-toggler sidebar-toggler' @click.stop='toggleSidebar'>
                <span>
                    <i class='el-icon-fa-bars'></i>
                </span>
            </div>
        </div>
        <div id='page-header-data-menu' class='data-menu'>
            <el-select v-model='selectedProjectId' placeholder='请选择'>
                <el-option v-for='item in projects' :key='item.id' :label='item.name' :value='item.id'></el-option>
            </el-select>
        </div>
        <div id='page-header-user-menu' class='user-menu'>
            <el-dropdown trigger='hover' class='user-menu-dropdown' @command='userMenuCommand'>
                <span class='el-dropdown-link'>
                    {{userInfo.username}}
                    <i class='el-icon-fa-user el-icon--right'></i>
                </span>
                <el-dropdown-menu slot='dropdown'>
                    <el-dropdown-item icon='el-icon-plus' command='logout'>退出</el-dropdown-item>
                    <el-dropdown-item icon='el-icon-circle-plus'>修改密码</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </div>
</template>
<script>
import frameworkApi from '@/api/framework'
import { mapGetters, mapMutations } from 'vuex'
export default {
    name: 'PageHeader',
    props: [],
    data() {
        return {
            selectedProjectId: null
        }
    },
    computed: {
        ...mapGetters('layout', ['sidebarClosed', 'userInfo', 'projects', 'currentProjectId'])
    },
    watch: {
        selectedProjectId(n, o) {
            this.setCurrentProjectId(n)
        }
    },
    methods: {
        ...mapMutations('layout', ['setSidebarClosed', 'setCurrentProjectId']),
        handleSelect() {},
        toggleSidebar() {
            this.setSidebarClosed(!this.sidebarClosed)
        },
        userMenuCommand(cmd) {
            // console.log('userMenuCommand ', cmd)
            if (cmd == 'logout') {
                frameworkApi.toLogout()
            }
        }
    },
    created() {
        // console.log('--------------------- PageHeader created')
        this.selectedProjectId = this.currentProjectId
    },
    mounted() {},
    components: {}
}
</script>