<template>
  <div ref="dlChartRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
import { PropType, Ref, defineComponent, onMounted, ref } from 'vue';
import { queryDomainlevel } from '../StProjectStaticsChart.api';
import { useECharts } from '/@/hooks/web/useECharts';

export default defineComponent({
  props: {
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: 'calc(100vh - 250px)',
    },
    depId:{
      type:String as PropType<string>,  
    }
  },
  setup(props) {
    const dlChartRef = ref<HTMLDivElement | null>(null);
    const { setOptions } = useECharts(dlChartRef as Ref<HTMLDivElement>);
    onMounted(() => {
      queryDomainlevel({}).then(rep=>{
        if(!rep || rep.names==null||rep.names.length==0){
          return
        }
        setOptions({
          tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          }
        },
        legend: {
          bottom: '15%'
        },
        grid: {
          top: '3%',
          left: '15%',
          right: '4%',
          bottom: '25%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: rep.names||[]
        },
        series: [
          {
            name: '高',
            type: 'bar',
            stack: 'total',
            label: {
              show: true,
            },
            emphasis: {
              focus: 'series'
            },
            data: rep.hightLevel||[]
          },
          {
            name: '中',
            type: 'bar',
            stack: 'total',
            label: {
              show: true,
            },
            emphasis: {
              focus: 'series'
            },
            data: rep.level||[]
          },
          {
            name: '低',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: rep.lowLevel||[]
          },
        ]
        })
      })
    })
    return { dlChartRef }
  },
})
</script>
