<template>
  <div class="container ui" style="padding:0 75px;">
    <div class="menu">
      <div class="menu-l">
        <div class="menu-item" v-for="(item, index) in list" :key="index" :class="focusIndex == index ? 'focused' : ''"
          @click="changeMenu(item, index)">
          {{ item.title }}
        </div>
      </div>
      <div class="menu-r"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "TopMenu",
  props: {
    menu: { type: Number, default: -1 },
  },
  components: {},
  data() {
    return {
      focusIndex: 0,
      list: [{
        key: 'tech_view',
        title: '按科技项目查看',
        url: '/tech/tech_view',
      }, {
        key: 'repo_view',
        title: '按项目成果查看',
        url: '/tech/repo_view',
      },/* {
        key: '',
        title: '我申请的项目',
        url: '',
      }*/],
    };
  },
  methods: {
    changeMenu(item, index) {
      if (this.focusIndex == index) return;
      this.focusIndex = index;
      window.location.href = item.url;
    }
  },
  beforeMount() {
    this.focusIndex = this.menu;
  },
  mounted() { },
};
</script>

<style scoped lang="less">
.menu {
  display: flex;
  align-items: center;
  justify-content: space-between;

  .menu-l {
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }

  .menu-r {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  .menu-item {
    display: flex;
    border-color: rgb(187, 187, 187);
    border-width: 1px 1px 0px 0px;
    border-style: solid;
    font-size: 14px;
    line-height: 20px;
    color: rgba(255, 255, 255, 0.7);
    align-items: center;
    text-align: center;
    justify-content: center;
    background: rgba(104, 50, 165, 0.2);
    height: 40px;
    width: 178px;
    cursor: pointer;

    &:first-child {
      border-left-width: 1px;
    }

    &.focused {
      cursor: default;
      color: rgb(255, 255, 255);
      background: rgba(249, 249, 249, 0.2);
    }
  }
}
</style>
