import {Device} from '../../base/Device';
/**
 * @author yeyuchao
 * @description menu
 */
let interVal = null;
let imageUrl = "";
export default {
  data() {
    return {
      titleList: [],
      device:null,
      mouseOverState:false,
      backgroundImage:"",
      menuShow:false,
      currentIdx:-1,
    };
  },
  mounted() {
    const that = this;
    broadcast.$on('menuClickEvent',(val)=>{
      console.log("mounted:"+val);
      that.menuShow = true;
    })
  },
  created() {
    this.titleList = [{index:0,title:'ELAB是谁',subtitle:'WHO IS ELAB'},{index:1,title:'ELAB在做什么',subtitle:'WHAT ELAB DO'}, {index:2,title:'新闻中心',subtitle:'NEWS'}, {index:3,title:'作品案例',subtitle:'PROJECT'}, {index:4,title:'加入我们',subtitle:'CAREERS'}];
    this.device = new Device();
    const that = this;
    interVal = setInterval(()=>{
      if(this.backgroundImage !== imageUrl){
        if(this.backgroundImage === ""){
          that.backgroundImage = imageUrl;
          that.mouseOverState = true;
        }else {
          that.mouseOverState = false;
          setTimeout(function () {
            if(imageUrl !== ""){
              that.backgroundImage = imageUrl;
              that.mouseOverState = true;
            }
          },650);
        }
      }
    },1300)
  },
  methods:{
    getTarget() {
      return this.$el;
    },
    titleMouseOver(idx){
      console.log("titleMouseOver:"+idx);
      this.currentIdx = idx;
      switch (idx) {
        case 0:
          imageUrl = "https://dm.static.elab-plus.com/elabGuanWang/elab_what.png";
          break;
        case 1:
          imageUrl = "https://dm.static.elab-plus.com/elabGuanWang/elab_do.png";
          break;
        case 2:
          imageUrl = "https://dm.static.elab-plus.com/elabGuanWang/elab_news.png";
          break;
        case 3:
          imageUrl = "https://dm.static.elab-plus.com/elabGuanWang/elab_project.png";
          break;
        case 4:
          imageUrl = "https://dm.static.elab-plus.com/elabGuanWang/elab_join.png";
          break;
      }
    },
    titleMouseOut(){
      imageUrl = "";
      this.currentIdx = -1;
    },
    closeMenu(){
      this.menuShow = false;
    },
    navigateToModule(idx){
      console.log("navigateToModule:"+idx);
      if(window.itemType === (idx+1)){
        this.menuShow = false;
        return
      }
      switch (idx) {
        case 0:
          window.itemType = 1;
          this.$router.push('/elabIntroduce');
          break;
        case 1:
          window.itemType = 2;
          this.$router.push('/elabDo');
          break;
        case 2:
          window.itemType = 3;
          this.$router.push('/news');
          break;
        case 3:
          window.itemType = 4;
          this.$router.push('/article');
          break;
        case 4:
          window.itemType = 5;
          this.$router.push('/careers');
          break;
      }
    }
  }
};
