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

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

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