<template>
  <Box title="畜牧业">
    <div class="h-full flex flex-col">
      <div class="py-10px">
        <ul class="flex items-center justify-center m-0">
          <li
            class="mx-11px text-white text-12px cursor-pointer"
            :class="{ active: currentTab == item.key }"
            @click="changeTab(item.key)"
            v-for="item in tabList"
            :key="item.key"
            >{{ item.value }}</li
          >
        </ul>
      </div>
      <div class="flex-1" ref="chartRef"> </div>
    </div>
  </Box>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, Ref, onMounted } from 'vue'
  import Box from './Box.vue'
  import { useECharts } from '/@/hooks/web/useECharts'
  import echarts from '/@/utils/lib/echarts'
  export default defineComponent({
    components: {
      Box,
    },
    setup() {
      const tabList = reactive([
        {
          key: '0',
          value: '全部',
        },
        {
          key: '1',
          value: '猪',
        },
        {
          key: '2',
          value: '牛',
        },
      ])

      const currentTab = ref<String>('0')

      const chartRef = ref<HTMLDivElement | null>(null)

      const changeTab = (key: String) => {
        if (currentTab.value == key) return
        currentTab.value = key
        chartsInit()
      }

      const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>)

      const chartsInit = () => {
        setOptions({
          grid: { left: '2%', right: '2%', top: '10%', bottom: '2%', containLabel: true },
          legend: {
            data: ['销售水量', '主营业务'],
            top: '0%',
            right: '0',
            textStyle: {
              color: '#ffffff',
            },
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              lineStyle: {
                width: 1,
                color: '#019680',
              },
            },
          },
          xAxis: {
            type: 'category',
            data: [...new Array(10)].map((_item, index) => `${index + 6}:00`),
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              color: '#fff',
            },
          },
          yAxis: [
            {
              type: 'value',
              axisTick: {
                show: false,
              },
              splitLine: {
                lineStyle: {
                  type: 'solid',
                  color: '#8EEEFF',
                  opacity: 0.3,
                },
              },
              axisLabel: {
                color: '#fff',
              },
            },
          ],
          series: [
            {
              name: '销售水量',
              data: [11, 22, 40, 18, 3, 55, 66, 33, 14, 30],
              type: 'line',
              symbol: 'none',
              itemStyle: {
                color: '#00F4B9',
              },
              areaStyle: {
                color: 'rgba(0, 244, 185, 0.4)',
              },
            },
            {
              name: '主营业务',
              data: [11, 22, 40, 18, 3, 55, 66, 33, 14, 30].reverse(),
              type: 'line',
              symbol: 'none',
              itemStyle: {
                color: '#28F2E6',
              },
              areaStyle: {
                color: 'rgba(40, 242, 230, 0.4)',
              },
            },
          ],
        })
      }

      onMounted(() => {
        chartsInit()
      })

      return {
        tabList,
        currentTab,
        chartRef,
        changeTab,
      }
    },
  })
</script>

<style scoped lang="less">
  .active {
    @apply font-bold text-15px text-[#76E9F0];
  }
</style>
