<template>
  <div class="headerMenu menuHeaderCenter" v-clickoutside="handleClickoutside">
    <span class="menuHeaderContent"  @mouseover="handleHeaderContentOver" @mouseleave="handleHeaderContentLeave">
      <span class="menuHeaderContentInner">{{ mainHeadTitle }}</span>
      <i :class="{'menuHeaderIcon':true, 'el-icon-arrow-down': !showMenu, 'el-icon-arrow-up': showMenu}"></i>
    </span>
    <div :class="['menuHeaderExpandbox', {'show': showMenu || mouserInMenuPanel}]">
      <div class="expand-box-header">
        <span class="expandBox-box-title">{{ parentLabel ? parentLabel : menuData[0]? menuData[0].label: '' }}</span>
      </div>
      <div class="expandBox-inner">
        <div class="expand-box-container" @mouseover="mouseIn" @mouseleave="mouseOut">
            <menuPanel @handlePanelItemClick='handlePanelItemClick' :data="menuData"></menuPanel>
        </div>
      </div>
      <span class="triangleUp"></span>
    </div>
  </div>
</template>
<script>
import menuPanel from './menu-panel.vue';
import Clickoutside from 'ifbp-element/lib/utils/clickoutside';
export default {
  data() {
    return {
      showMenu: false,
      mouserInMenuPanel:false,
      mainHeadTitle: '首页',
      menuListData: [],
      parentLabel: null,
       timeout: null,
    };
  },
  props: ['menuData'],
  components: {
    menuPanel,
  },
  directives: { Clickoutside }, // 指令clickoutside
  methods: {
    handleClickoutside() {
      if(this.showMenu) {
        this.showMenu = false;
      }
    },
    handleHeaderContentOver(e){    
      this.showMenu = true;
      e.preventDefault();
      e.stopPropagation();
    },
    handleHeaderContentLeave(e){	
    	
	  clearTimeout(this.timeout);
     this.timeout = setTimeout(() => {
     this.showMenu = false;
    }, 250);         
      e.preventDefault();
      e.stopPropagation();
    },
    mouseIn(e){
      this.mouserInMenuPanel = true;
    	e.preventDefault();
      e.stopPropagation();
    },
    mouseOut(e){ 	  
      this.mouserInMenuPanel = false; 
    	e.preventDefault();
      e.stopPropagation();
    },
    handlePanelItemClick(title){
    	this.parentLabel = title;
    }
    
  }
};
</script>
<style>
.headerMenu.menuHeaderCenter {
  height: 64px;
  line-height: 64px;
  text-align: center;
  font-size: 15px;
}

.headerMenu .menuHeaderContent {
  height: 40px;
  line-height: 40px;
  padding: 0 16px;
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  box-sizing: border-box;
  border-radius: 3px;
  cursor: pointer;
  z-index: 10;
  color: #727171;
  font-size: 16px;
}

.headerMenu .menuHeaderContent:hover {
  background-color: #eeeff1;
  color: #000;
}
.headerMenu .menuHeaderContentInner {
  vertical-align: middle;
}
.headerMenu .menuHeaderIcon {
  color: #C8C8CD;
  font-size: 20px;
  margin-left: 4px;
  vertical-align: middle;
}

.headerMenu .menuHeaderContent:hover .menuHeaderIcon {
  color: #8E8E93;
}

.headerMenu .menuHeaderExpandbox {
  position: absolute;
  background-color: #fff;
  border: 1px solid #d1dbe5;
/*  box-shadow: 2px 2px 15px #a2a0a0;*/
  z-index: 100;
  border-radius: 5px;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: 840px;
  min-width: 769px;
  visibility: hidden;
  transition: all .1s .1s ease-in-out;
}
.headerMenu .menuHeaderExpandbox.show {
  visibility: visible;
  transition: all .1s ease-in-out;
}
.expandBox-inner {
  width: 100%;
  height: 0px;
  position: relative;
  overflow-x: auto;
  overflow-y: auto;
  transition: all .2s ease-in-out;
}
.headerMenu .menuHeaderExpandbox.show .expandBox-inner {
  height: 400px;
  transition: all .2s ease-in-out;
}
.menuHeaderExpandbox .expand-box-header {
  position: relative;
  text-align: center;
  /* font-size: 13px; */
  width: 100%;
  height: 32px;
  line-height: 32px;
  border-bottom: 1px solid #e5e5e5;
}
.menuHeaderExpandbox .expand-box-header .expandBox-box-title {
  font-size: 14px;
  font-weight: 600;
  color: #333333;
}
.menuHeaderExpandbox .expand-box-container {
  width: 100%;
  min-width:767px;
}

.triangleUp {
  width: .8rem;
  height: .8rem;
  position: absolute;
  top: -0.5rem;
  left: 50%;
  transform: translateX(-100%) rotate(-45deg);
  border-top: 1px solid #dcd8d8;
  border-right:1px solid #dcd8d8 ;
  background-color: #fff;
  z-index: 100;
}
.middle-border {
  width: 1px;
  height: 2000px;
  border-left: 1px solid #e5e5e5;
  position: absolute;
  left: 320px;
}
</style>
