<template>
  <div class="className" style="height:calc(100vh - 310px);width:100%"/>
</template>

<script>
import * as echarts from 'echarts';
require('echarts/theme/macarons')
import { getPageViewTotalList } from '@/api/index'

export default {
  name: 'pageView',
  data() {
    return {
      chart: null,
      chartData: {
        pvData: [205, 225, 127, 202, 204, 25, 57, 330,315,518,201,405,251,236,309],
        dateTimeData: ['2025-02-26','2025-02-27','2025-02-28','2025-03-01','2025-03-02','2025-03-03','2025-03-04','2025-03-05','2025-03-06','2025-03-07','2025-03-08','2025-03-09','2025-03-10','2025-03-11','2025-03-12'],
        legendData: ["访问量（PV）"]
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
      this.getPageViewTotalInfo();
    })
  },
  methods: {
    getPageViewTotalInfo() {
      getPageViewTotalList().then(response => {
        if (response.data != null) {
          this.chartData = response.data;
          this.chartData.legendData = ["访问量（PV）"];
          this.setOptions(this.chartData);
        }
      });
    },
    initChart() {
      if (!this.chart) {
        this.chart = echarts.init(this.$el, 'macarons')
      }
      this.setOptions(this.chartData)
    },
    setOptions({ pvData, dateTimeData, legendData } = {}) {
      this.chart.setOption({
        xAxis: {
          data: dateTimeData,
          boundaryGap: false,
          axisTick: {
            show: false
          }
        },
        grid: {
          left: 10,
          right: 10,
          bottom: 20,
          top: 30,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          data: legendData,
        },
        series: [{
          name: legendData[0],
          smooth: true,
          type: 'line',
          itemStyle: {
            normal: {
              color: '#3888fa',
              lineStyle: {
                color: '#3888fa',
                width: 2
              },
              areaStyle: {
                color: '#a2c2f1'
              }
            }
          },
          data: pvData,
          animationDuration: 2800,
          animationEasing: 'quadraticOut'
        },]
      })
    }
  }
}
</script>
