<template>
  <ve-line :data="chartData" :title="title" :settings="chartSettings"/>
</template>

<script>
import { countbyTime } from '@/api/statistics'
export default {
  name: 'PassOneDay',
  data() {
    this.title = {
      text: '单日通行趋势'
    }
    this.chartSettings = {
      labelMap: {
        'total': '通行人数'
      },
      metrics: ['total'],
      dimension: ['time']
    }
    return {
      chartData: {
        columns: ['time', 'total'],
        rows: []
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  activated() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const date = new Date().toLocaleDateString().split('/').join('-')
      // const date = '2020-05-15'
      const listQuery = {
        date: date
      }
      countbyTime(listQuery).then(response => {
        const data = response.data
        if (data.length !== 0) {
          this.chartData.rows = data
        }
      })
    }
  }
}
</script>
