<template>
    <div class="boxLeft" :style="height">
        <!-- 在线监测规模 -->

        <el-card>
            <template #header>
                <div class="card-header">
                    <span>在线监测规模</span>
                </div>
            </template>
            <MyEChart :style="boxHeight" :options="onlineCharts" />
        </el-card>

        <!-- 监测终端状态 -->
        
        <el-card>
            <template #header>
                <div class="card-header">
                    <span>监测终端状态</span>
                </div>
            </template>
            <div>
                <MyEChart :style="boxHeight" :options="terminalCharts" />
            </div>
        </el-card>
        <!-- 监测点 -->
        <el-card>
            <template #header>
                <div class="card-header">
                    <span>监测点</span>
                </div>
            </template>
            <MyEChart :style="boxHeight" :options="dotCharts" />
        </el-card>
     


    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, provide } from 'vue'
import MyEChart from '@/components/echarts/MyEchart.vue'
import { useDictData } from '@/stores/dictData'
import { mainHeight } from '@/utils/layout'

import { getPracticalRunDeviceInfo, getGridDiagramCityDev, getGridDiagramLineData } from '@/api/device-boot/panorama'

const dictData = useDictData()
const height = mainHeight(20)
const boxHeight: any = mainHeight(220, 3)

const formRow: any = ref({})
const terminalCharts: any = ref({})

const dotCharts = ref()

const onlineCharts = ref()


const info = (row: any) => {
    let form = {
        ...row,
        id: row.orgNo,
        deptIndex: row.orgNo,
        orgId: row.orgNo,
        ids: [],
        statisticalType: dictData.getBasicData('Statistical_Type', ['Report_Type'])[0],
        isUpToGrid: row.isUpToGrid,
        monitorFlag: row.isUpToGrid
    }
    let loadType = dictData.getBasicData('Statistical_Type').find(item => item.code == 'Load_Type')

    formRow.value = form
    // 变电站
    getPracticalRunDeviceInfo(form).then(res => {
        onlineCharts.value = {
            tooltip: {},
            yAxis: {
                type: 'value'
            },

            xAxis: {
                type: 'category',
                data: ['变电站', '监测装置', '监测点'],
                axisLabel: {
                    color: '#000',
                    fontSize: 12
                }
            },
            grid: {
                top: '30px',
                left: '10px',
                right: '20px'
            },

            options: {
                dataZoom: null,
                series: [
                    {
                        name: '',
                        type: 'bar',
                        data: [
                            res.data[0].subIndexes.length,
                            res.data[0].deviceIndexes.length,
                            res.data[0].lineIndexes.length
                        ],
                        label: {
                            show: true,
                            position: 'top',
                            fontSize: 12
                        }
                    }
                ]
            }
        }
    })
    // 终端
    getGridDiagramCityDev({ ...form, deviceInfoParam: form, pageNum: 1, pageSize: 1000 }).then(res => {
        terminalCharts.value = {
            title: {
                text: ''
            },
            legend: {
                show: true,
                right: 90
            },
            xAxis: {
                data: ['运行', '检修', '退运']
            },
            yAxis: [
                {
                    name: '个数',
                    type: 'value'
                },
                {
                    type: 'value',
                    name: '在线率',
                    splitLine: {
                        show: false
                    },
                    max: 100
                }
            ],
            grid: {
                top: '35px',
                left: '20px',
                right: '20px'
            },
            options: {
                dataZoom: null,
                series: [
                    {
                        name: '终端个数',
                        type: 'bar',

                        data: [res.data[0], res.data[2], res.data[4]],
                        label: {
                            show: true,
                            position: 'top',
                            fontSize: 12
                        }
                    },
                    {
                        name: '在线率',
                        type: 'bar',
                        yAxisIndex: 1,
                        data: [res.data[1]],
                        label: {
                            show: true,
                            position: 'top',
                            fontSize: 12
                        }
                    }
                ]
            }
        }
    })

    // 监测点
    getGridDiagramLineData({ ...form, statisticalType: loadType }).then(res => {
        dotCharts.value = {
            title: {
                text: ''
            },
            // str.replace(/\(\d+\)/, "\n$&");
            xAxis: {
                data: res.data.map((item: any) => {
                    return item.orgName.length > 4
                        ? item.orgName.slice(0, 4) + '\n ' + item.orgName.slice(4)
                        : item.orgName
                }),
                axisLabel: {
                    color: '#000',
                    fontSize: 12
                }
            },
            yAxis: {
                name: '',
                min: 0,
                max: 100
            },
            grid: {
                top: '30px',
                left: '0px',
                right: '20px'
            },
            options: {
                dataZoom: null,
                series: [
                    {
                        name: '数据完整性',
                        type: 'bar',

                        data: res.data.map((item: any) => item.integrityRate),
                        label: {
                            show: true,
                            position: 'top',
                            fontSize: 12
                        }
                    }
                ]
            }
        }
    })
}

defineExpose({ info })
</script>

<style lang="scss" scoped>
.boxLeft {
    background-color: #fff;
    width: 25%;
    padding: 10px 0px 10px 10px;
    font-size: 13px;
    overflow: hidden;
}

.title {
    // height: ;
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    height: 22px;
    line-height: 23px;
    padding-left: 5px;
    width: 100%;
    background-image: linear-gradient(to right, #a4e5da, #fff);

    .info {
        font-weight: normal;
        display: flex;
        font-size: 12px;
        cursor: pointer;
    }
}
.evaluate {
    height: 60px;
    border: 1px solid #ccc;
    margin: 10px 0;
    padding: 10px 0;
    display: flex;
    justify-content: space-around;
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
}
.boxR {
    border: 1px solid #ccc;
    margin: 10px 0;
    padding: 5px;
    .num {
        color: #2478f2;
    }
    .top {
        display: flex;
        justify-content: space-between;
    }
    .bottom {
        margin: 0;
        border: 0px;
    }
}
:deep(.el-select) {
    min-width: 120px;
}
.col {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: center;
}
.imgR {
    position: absolute;
    padding: 10px;
    top: calc(50% - 80px);
    left: -23px;
    z-index: 1;
    height: 200px;
    cursor: pointer;
}
:deep(.el-card) {
    .el-card__header {
        padding: 5px 20px;
        font-size: 1.2rem;
        &::before {
            width: 0.3rem;
            height: 1.2rem;
            margin-top: 0.3rem;
            position: absolute;
            content: '';
            background: var(--el-color-primary);
            border-radius: 0.02rem;
            left: 1.2rem;
        }
    }
    .el-card__body {
        padding: 10px;
    }
    margin-bottom: 10px;
    margin-right: 10px;
}
</style>
