<template>
  <div class="menus-box">
    <div v-for="(item, index) in menus" :key="index" class="menus-item" :class="(currentMenuObj===item?'active':'')+(index===menus.length-1?' tc-orange':'')" @click="menuClick(item)">
      {{ item.name }}
      <div v-if="currentMenuObj===item" class="menus-line"><div /></div>
    </div>
  </div>
</template>
<script>
import { HttpReq } from '@/api/common'

export default {
  props: {
    menuIndex: {
      type: String,
      default: '0'
    }
  },
  data() {
    return {
      menus: [
        { name: '首页', url: '/home' }, { name: '优质产品', url: '/product' }, { name: '优质供应商', url: '/supplier' }, { name: '解决方案与服务', url: '/project' }, { name: '软件系统', url: '/software' }, { name: '专业培训', url: '/course' }, { name: '行业资讯', url: '/information' }, { name: '信息发布', url: '/publish' }
      ],
      currentMenuObj: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$nextTick(() => {
        HttpReq.webClientApi.homePageGetHeader({
          preview: false
        }).then((res) => {
          this.menus = res.data.menus
          this.currentMenuObj = this.menuIndex > this.menus.length ? { name: '个人中心', url: '/console' } : this.menus[this.menuIndex]
          this.$store.dispatch('app/setCurrentMenu', this.currentMenuObj)
        })
      })
    })
  },
  methods: {
    menuClick(item) {
      this.currentMenuObj = item
      this.$router.push({ path: item.url || '/home' })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.tc-orange {
  color: #F7601A !important;
}
.menus-box {
  .menus-item {
    position: relative;
    display: inline-block;
    padding: 0 15px;
    font-size: 20px;
    font-weight: 400;
    font-family: Source Han Sans CN;
    color: #666666;
    cursor:pointer;
    user-select: none;
  }
  .menus-item:hover {
    color: #F7601A;
  }
  .active {
    color: #000;
    font-weight: 600;
  }
  .menus-line {
    position: absolute;
    top: 46px;
    left: 0;
    width: 100%;
    height: 4px;
    padding: 0 15px;
    div {
      width: 100%;
      height: 100%;
      background: #1961C5;
    }
  }
}
</style>
