<template>
  <el-row>
    <el-col>
      <el-card shadow="never">
        <el-col>
          <div class="flagBoxStyle">
            <div class="flagStyle" />
            <div>设备总体情况</div>
          </div>
        </el-col>
        <el-col class="cardStyle">
          <el-col :span="10">
            <el-card>
              <div>
                <span class="ttileStyle">设备总数</span>
                <span class="countStyle">123</span>
                <span>个</span>
              </div>
            </el-card>
          </el-col>
          <el-col :span="10">
            <el-card>
              <div>
                <span class="ttileStyle">低电量设备总数</span>
                <span class="countStyle">123</span>
                <span>个</span>
              </div>
            </el-card>
          </el-col>
        </el-col>
        <el-col>
          <div class="flagBoxStyle">
            <div class="flagStyle" />
            <div>设备数量分析</div>
          </div>
        </el-col>
        <el-col>
          <ve-histogram
            :data="chartData"
            :grid="grid"
            :extend="extend"
            :settings="chartSettings"
          />
        </el-col>
      </el-card>
    </el-col>
  </el-row>
</template>

<script>
import { deviceStaticsByType } from '@/api/data/dataStatics'
export default {
  name: 'DeviceCountByType',
  data() {
    return {
      extend: {
        xAxis: {
          axisLabel: {
            rotate: 30,
            margin: 30,
            textStyle: {
              align: 'center'
            }
          }
        },
        series: {
          label: { show: true, position: 'top' },
          barMaxWidth: 35 // 最大柱宽度
        }
      },
      grid: {
        right: 60
      },
      chartSettings: {
        itemStyle: {
          'barCategoryGap': 5
        },
        barWidth: 15,
        labelMap: {
          'deviceType': '权属单位',
          'deviceCount': '设备数量（个）'
        },
        dimension: ['deviceType'],
        metrics: ['deviceCount']
      },
      chartData: {
        columns: ['deviceType', 'deviceCount'],
        rows: []
      }
    }
  },
  created() {
    this.fetchDeviceType()
  },
  methods: {
    fetchDeviceType() {
      deviceStaticsByType().then(response => {
        this.chartData.rows = response.data
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.flagBoxStyle {
  display: flex;
  margin-bottom: 20px;
}
.flagBoxStyle div:nth-child(2){
  line-height: 30px;
  font-weight: 600;
}
.flagStyle {
  width: 4px;
  height: 30px;
  margin-right: 6px;
  background: rgb(64 121 242);
}
.cardStyle {
  display:flex;
  margin-bottom: 60px;
  justify-content: space-around;
}
.ttileStyle {
  font-size: 12px;
}
.countStyle {
  font-size: 20px;
  margin: 0 10px;
}
</style>
