<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.defaultIcon"
        :alt="tab.title"
      >
      <span class="tab-title">{{ tab.title }}</span>
    </div>
  </div>
</template>

<script>
const defaultIcon = require('@/assets/nav/ic_statistical_top_default.png')
const activeIcon = require('@/assets/nav/ic_statistical_top_check.png')

export default {
  name: 'StatisticsTabs',
  data() {
    return {
      tabList: [
        {
          path: '/statisticsCharts/flight',
          title: '航班量统计',
          defaultIcon,
          activeIcon
        },
        {
          path: '/statisticsCharts/node',
          title: '扫描节点与位置分析',
          defaultIcon,
          activeIcon
        },
        {
          path: '/statisticsCharts/baggage',
          title: '行李量统计',
          defaultIcon,
          activeIcon
        },
        {
          path: '/statisticsCharts/specialBaggage',
          title: '特殊行李量统计',
          defaultIcon,
          activeIcon
        },
        {
          path: '/statisticsCharts/passenger',
          title: '旅客量统计',
          defaultIcon,
          activeIcon
        }
      ],
      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>
