<template>
  <ve-ring :data="chartData" :title="title" :settings="chartSettings" :legend="legends" />
</template>

<script>
import { peopleCountByDevice } from '@/api/statistics'

export default {
  name: 'PassCount',
  data() {
    this.title = {
      text: '通行人数'
    }
    this.legends = {
      orient: 'horizontal',
      x: 'right', // 可设定图例在左、右、居中
      padding: [0, 0, 0, 100]
    }
    this.chartSettings = {
      label: {
        normal: {
          show: true
        }
      }
    }
    return {
      chartData: {
        columns: ['deviceName', 'count'],
        rows: [
          { 'deviceName': '设备1', 'count': '23' },
          { 'deviceName': '设备2', 'count': '23' },
          { 'deviceName': '设备3', 'count': '23' },
          { 'deviceName': '设备5', 'count': '23' },
          { 'deviceName': '设备6', 'count': '23' },
          { 'deviceName': '设备7', 'count': '23' },
          { 'deviceName': '设备8', 'count': '23' },
          { 'deviceName': '设备9', 'count': '23' },
          { 'deviceName': '设备4', 'count': '23' }
        ]
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  activated() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      // const beginTime = (new Date().toLocaleDateString().split('/').join('-')) + ' 00:00:00'
      // const endTime = new Date().toLocaleDateString().split('/').join('-') + ' 23:59:59'
      const startTime = '2020-06-01 00:00:00'
      const endTime = '2020-06-20 00:00:00'
      const listQuery = {
        startTime: startTime,
        endTime: endTime
      }
      peopleCountByDevice(listQuery).then(response => {
        const data = response.data
        if (data.length === 0) {
          var data0 = {}
          data0['deviceName'] = ''
          data0['count'] = 0
          data.push(data0)
          this.chartSettings.label.normal.show = false
        }
        this.chartData.rows = data
      })
    }
  }
}
</script>
