<template>
    <my-echart v-loading="loading" class="mt10" :style="`height: calc(${tableStore.table.height} - 135px)`"
        :options="options" />
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import MyEchart from '@/components/echarts/MyEchart.vue'
import TableHeader from '@/components/table/header/index.vue'
import { useDictData } from '@/stores/dictData'
const dictData = useDictData()
const options = ref({})



const TableHeaderRef = ref()
const tableStoreParams: any = ref({})
const loading = ref(false)
const getTableStoreParams = async (val: any) => {
    tableStoreParams.value = val
    loading.value = true
    setTimeout(() => {
        tableStore.index()
    }, 1500)
}
const tableStore = new TableStore({
    url: '/harmonic-boot/tHDistortion/getTHDistortionCensus',
    showPage: false,
    method: 'POST',
    column: [],
    beforeSearchFun: () => {
        tableStore.table.params = tableStoreParams.value
    },
    loadCallback: () => {
        // tableStore.table.data.type
        let code = tableStore.table.params.statisticalType.code
        let title = '',
            titleX = ''
        if (code == 'Power_Network') {
            title = '区域'
            titleX = '区域'
        } else if (code == 'Manufacturer') {
            title = '终端厂家'
            titleX = '终端\n厂家'
        } else if (code == 'Voltage_Level') {
            title = '电压等级'
            titleX = '电压\n等级'
        } else if (code == 'Load_Type') {
            title = '干扰源类型'
            titleX = '干扰\n源类型'
        } else if (code == 'Report_Type') {
            title = '上报类型'
            titleX = '上报\n类型'
        }
        options.value = {
            title: {
                text: title
            },

            // tooltip: {
            //     formatter: function (params: any) {
            //         var tips = ''

            //         for (var i = 0; i < params.length; i++) {
            //             if (params[i].value == 1) {
            //                 tips += params[i].name + '</br>'
            //                 tips += '总畸变率:暂无数据'
            //             } else {
            //                 tips += params[i].name + '</br>'
            //                 tips += '总畸变率:' + params[i].value.toFixed(2)
            //             }
            //         }
            //         return tips
            //     }
            // },

            xAxis: {
                name: titleX,
                data: tableStore.table.data.type
            },
            yAxis: {
                name: '%',
                max: 100
            },
            series: [
                {
                    name: '总畸变率',
                    type: 'bar',
                 
                    data: tableStore.table.data.single,


                }
            ]
        }
        loading.value = false
    }
})


provide('tableStore', tableStore)

onMounted(() => { })
defineExpose({ getTableStoreParams })
</script>
<style scoped lang="scss"></style>
