<template>
  <div class="statistics-tabs">
    <div
      v-for="(tab, index) in tabList"
      :key="tab.path"
      :class="['tab-bar', { 'tab-active': activeIndex === index }]"
      @click="clickHandler(index)"
    >
      <img
        class="tab-icon"
        :src="activeIndex === index ? tab.activeIcon : tab.icon"
        :alt="tab.title"
      >
      <span class="tab-title">{{ tab.title }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StatisticsTabs',
  data() {
    return {
      tabList: [
        {
          path: '/statisticsCharts/flight',
          icon: require('@/assets/nav/ic_statistical_top_default.png'),
          activeIcon: require('@/assets/nav/ic_statistical_top_check.png'),
          title: '航班量统计'
        },
        {
          path: '/statisticsCharts/node',
          icon: require('@/assets/nav/ic_statistical_top_default.png'),
          activeIcon: require('@/assets/nav/ic_statistical_top_check.png'),
          title: '扫描节点与位置分析'
        },
        {
          path: '/statisticsCharts/baggage',
          icon: require('@/assets/nav/ic_statistical_top_default.png'),
          activeIcon: require('@/assets/nav/ic_statistical_top_check.png'),
          title: '行李统计'
        }
      ],
      activeIndex: null
    }
  },
  watch: {
    '$route.path': {
      handler(val) {
        this.activeIndex = this.tabList.findIndex(tab => tab.path === val)
      },
      immediate: true
    },
    activeIndex(val) {
      this.$router.push({
        path: this.tabList[val].path
      })
    }
  },
  methods: {
    clickHandler(index) {
      this.activeIndex = index
    }
  }
}
</script>

<style lang="scss" scoped>
.statistics-tabs {
  display: flex;
  .tab-bar {
    min-width: 216px;
    height: 56px;
    background-color: #ffffff;
    padding-left: 24px;
    display: flex;
    align-items: center;
    box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    cursor: pointer;
    &:not(:last-child) {
      margin-right: 16px;
    }
    .tab-icon {
      width: 16px;
      height: 16px;
      margin-right: 15px;
    }
    .tab-title {
      font-size: 16px;
      font-family: Helvetica 'Microsoft YaHei';
      font-weight: bold;
      color: #101116;
    }
    &.tab-active {
      background-color: #2d67e3;
      .tab-title {
        color: #ffffff;
      }
    }
  }
}
</style>
