<template>
  <ve-pie :data="chartData" :extend="extend" :legend="legend" :title="title" />
</template>

<script>
import { deviceStaticByStatus } from '@/api/data/dataStatics'

export default {
  data() {
    return {
      chartData: {
        columns: ['onlineStatus', 'deviceCount'],
        rows: []
      },
      title: {
        text: '设备在线情况统计'
      },
      extend: {
        series: {
          label: { show: true, position: 'outside', formatter: '{b}:{c}' }
        }
      },
      chartSettings: {
        labelMap: {
          'onlineStatus': '在线状态',
          'deviceCount': '设备数量'
        },
        dimension: 'onlineStatus',
        metrics: 'deviceCount'
      },
      legend: {
        right: 10
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      deviceStaticByStatus().then(response => {
        const data = response.data
        this.chartData.rows = [
          { 'onlineStatus': '在线', 'deviceCount': data.online },
          { 'onlineStatus': '离线', 'deviceCount': data.offline }
        ]
      })
    }
  }
}
</script>
