<template>
  <div class="menus-box">
    <span 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 }}
    </span>
  </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(() => {
      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 {
    padding: 1px 15px 1px;
    font-size: 20px;
    font-weight: 400;
    font-family: Source Han Sans CN;
    color: #FFFFFF;
    line-height: 48px;
    cursor:pointer;
    user-select: none;
  }
  .menus-item:hover {
    color: #F7601A;
  }
  .active {
    color: #FFFFFF;
    font-weight: 600;
  }
}
</style>
