<template>
    <DatePicker ref="datePickerRef" style="display: none" theCurrentTime />
    <el-select class="conditions" v-model="formData.conditions" placeholder="请选择指标" style="width: 200px"
        @change="History" filterable>
        <el-option-group v-for="group in indexOptions" :key="group.label" :label="group.label">
            <el-option v-for="item in group.options" :key="item.value" :label="item.label"
                :value="item.value"></el-option>
        </el-option-group>
    </el-select>
    <MyEChart v-loading="loading" :options="list[0]?.option" :style="`height: calc(${rowHeight} - 31px)`" />
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, nextTick } from 'vue'
import { mainHeight } from '@/utils/layout'
import { indexOptions } from '@/utils/dictionary'
import DatePicker from '@/components/form/datePicker/index.vue'
import MyEChart from '@/components/echarts/MyEchart.vue'
import { getHistoryResult } from '@/api/harmonic-boot/harmonic'

const prop = defineProps({
    lineId: {
        type: String
    }
})

const datePickerRef = ref()
const loading = ref(true)
const traceability = ref<any>([])
const list = ref<any>([])
const rowHeight = mainHeight(-80, 3).height
const formData: any = reactive({
    lineId: [],
    searchBeginTime: '',
    searchEndTime: '',
    conditions: '10',
    valueType: 1,
    harmonic: 2,
    inHarmonic: 1,
    ptType: 0
})

const History = () => {
    loading.value = true
    formData.lineId = [prop.lineId]
    formData.searchBeginTime = datePickerRef.value.timeValue[0]
    formData.searchEndTime = datePickerRef.value.timeValue[1]
    formData.condition = [formData.conditions]
    getHistoryResult(formData).then(res => {
        shujuchuli(res)
    })
}
const shujuchuli = (res: any) => {
    list.value = []
    let shujuData = res.data
    shujuData.forEach((item: any, i: number) => {
        //判断是否存在暂降点

        if (item.eventDetail !== null || item.eventDetail.length === 0) {
            //向项别中添加暂降点
            let chufa = []
            item.phaiscType.push('暂态触发点')
            //判断是否有限值(有上下限)
            if (item.topLimit !== 0 && item.lowerLimit !== 0) {
                item.phaiscType.push('上限')
                item.phaiscType.push('下限')
                if (item.minValue !== null && item.maxValue !== null) {
                    //最小值等于下限值

                    //图列为A,B,C,暂降,上限,下限
                    if (item.phaiscType.length == 6) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let topLimit = []
                        let lowerLimit = []
                        item.maxValue = item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //上下限值
                                topLimit.push([item.value[j][0], item.topLimit])
                                lowerLimit.push([item.value[j][0], item.lowerLimit])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([
                                    item.eventDetail[k].time,
                                    item.minValue.toFixed(3),
                                    item.eventDetail[k].id,
                                    99
                                ])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            topLimit: topLimit,
                            lowerLimit: lowerLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,暂降,上限,下限
                    if (item.phaiscType.length == 4) {
                        let gvalue = []
                        let topLimit = []
                        let lowerLimit = []
                        item.maxValue = item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //上下限值
                                topLimit.push([item.value[j][0], item.topLimit])
                                lowerLimit.push([item.value[j][0], item.lowerLimit])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([
                                    item.eventDetail[k].time,
                                    item.minValue.toFixed(3),
                                    item.eventDetail[k].id,
                                    99
                                ])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            gvalue: gvalue,
                            topLimit: topLimit,
                            lowerLimit: lowerLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //有上限值
            if (item.topLimit !== 0 && item.lowerLimit == 0) {
                item.phaiscType.push('上限')
                if (item.minValue !== null && item.maxValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,暂降,上限
                    if (item.phaiscType.length == 5) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let topLimit = []
                        item.maxValue = item.topLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //上限值
                                topLimit.push([item.value[j][0], item.topLimit])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([
                                    item.eventDetail[k].time,
                                    item.minValue.toFixed(3),
                                    item.eventDetail[k].id,
                                    99
                                ])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            topLimit: topLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,暂降,上限
                    if (item.phaiscType.length == 3) {
                        let gvalue = []
                        let topLimit = []
                        item.maxValue = item.topLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //上限值
                                topLimit.push([item.value[j][0], item.topLimit])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([item.eventDetail[k].time, item.minValue.toFixed(3)])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            gvalue: gvalue,
                            topLimit: topLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //有下限值
            if (item.topLimit == 0 && item.lowerLimit !== 0) {
                item.phaiscType.push('下限')
                if (item.minValue !== null && item.maxValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,暂降,下限
                    if (item.phaiscType.length == 5) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let lowerLimit = []
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //下限值
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([item.eventDetail[k].time, item.minValue.toFixed(3)])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            lowerLimit: lowerLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,暂降,下限
                    if (item.phaiscType.length == 3) {
                        let gvalue = []
                        let lowerLimit = []
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //下限值
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([item.eventDetail[k].time, item.minValue.toFixed(3)])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            gvalue: gvalue,
                            lowerLimit: lowerLimit,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //无限值
            if (item.topLimit == 0 && item.lowerLimit == 0) {
                if (item.minValue !== null && item.maxValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,暂降
                    if (item.phaiscType.length == 4) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([
                                    item.eventDetail[k].time,
                                    item.minValue.toFixed(3),
                                    item.eventDetail[k].id,
                                    99
                                ])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue > 1 ? (item.minValue - 0.5).toFixed(3) : item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,暂降
                    if (item.phaiscType.length == 2) {
                        let gvalue = []
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        //不存在一个暂降点或1个 //处理暂降点
                        if (item.eventDetail.length > 0) {
                            for (let k = 0; k < item.eventDetail.length; k++) {
                                chufa.push([
                                    item.eventDetail[k].time,
                                    item.minValue.toFixed(3),
                                    item.eventDetail[k].id,
                                    99
                                ])
                            }
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            gvalue: gvalue,
                            chufa: chufa
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
        } else if (item.eventDetail == null) {
            //判断是否有限值(有上下限)
            if (item.topLimit !== 0 && item.lowerLimit !== 0) {
                item.phaiscType.push('上限')
                item.phaiscType.push('下限')
                if (item.minValue !== null && item.maxValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,上限,下限
                    if (item.phaiscType.length == 5) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let topLimit = []
                        let lowerLimit = []
                        item.maxValue = item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //上下限值
                                topLimit.push([item.value[j][0], item.topLimit.toFixed(3)])
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            topLimit: topLimit,
                            lowerLimit: lowerLimit
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,上限,下限
                    if (item.phaiscType.length == 3) {
                        let gvalue = []
                        let topLimit = []
                        let lowerLimit = []
                        item.maxValue = item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //上下限值
                                topLimit.push([item.value[j][0], item.topLimit.toFixed(3)])
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            gvalue: gvalue,
                            topLimit: topLimit,
                            lowerLimit: lowerLimit,
                            chufa: []
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //有上限值
            if (item.topLimit !== 0 && item.lowerLimit == 0) {
                item.phaiscType.push('上限')
                if (item.minValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,上限
                    if (item.phaiscType.length == 4) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let topLimit = []
                        item.maxValue = item.topLimit
                        // item.minValue=item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //上限值
                                topLimit.push([item.value[j][0], item.topLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            maxValue: item.maxValue.toFixed(3),
                            minValue: item.minValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            topLimit: topLimit
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,上限
                    if (item.phaiscType.length == 2) {
                        let gvalue = []
                        let topLimit = []
                        item.maxValue = item.topLimit
                        // item.minValue=item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //上限值
                                topLimit.push([item.value[j][0], item.topLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            gvalue: gvalue,
                            topLimit: topLimit
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //有下限值
            if (item.topLimit == 0 && item.lowerLimit !== 0) {
                item.phaiscType.push('下限')
                if (item.minValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C,下限
                    if (item.phaiscType.length == 4) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        let lowerLimit = []
                        // item.maxValue=item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                                //下限值
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue,
                            lowerLimit: lowerLimit
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等,下限
                    if (item.phaiscType.length == 2) {
                        let gvalue = []
                        let lowerLimit = []
                        // item.maxValue=item.topLimit
                        item.minValue = item.lowerLimit
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                                //下限值
                                lowerLimit.push([item.value[j][0], item.lowerLimit.toFixed(3)])
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            gvalue: gvalue,
                            lowerLimit: lowerLimit
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
            //无限值
            if (item.topLimit == 0 && item.lowerLimit == 0) {
                if (item.minValue !== null) {
                    //最小值等于下限值
                    //图列为A,B,C
                    if (item.phaiscType.length == 3) {
                        let avalue = []
                        let bvalue = []
                        let cvalue = []
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    avalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    avalue.push([])
                                }
                                //判断存在缺失值b
                                if (item.value[j][2] != undefined) {
                                    bvalue.push([item.value[j][0], item.value[j][2].toFixed(3)])
                                } else {
                                    bvalue.push([])
                                }
                                //判断存在缺失值c
                                if (item.value[j][3] != undefined) {
                                    cvalue.push([item.value[j][0], item.value[j][3].toFixed(3)])
                                } else {
                                    cvalue.push([])
                                }
                            }
                            //数据为空
                        } else {
                            avalue = []
                            bvalue = []
                            cvalue = []
                        }

                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            avalue: avalue,
                            bvalue: bvalue,
                            cvalue: cvalue
                        }
                        list.value.push(shuju)
                    }
                    //图列为频率等
                    if (item.phaiscType.length == 1) {
                        let gvalue = []
                        //判断数据是否存在
                        if (item.value !== null) {
                            for (let j = 0; j < item.value.length; j++) {
                                //判断存在缺失值a
                                if (item.value[j][1] != undefined) {
                                    gvalue.push([item.value[j][0], item.value[j][1].toFixed(3)])
                                } else {
                                    gvalue.push([])
                                }
                            }
                            //数据为空
                        } else {
                            gvalue = []
                        }
                        let shuju = {
                            id: 'qushifenx' + i,
                            title: item.lineName + '--' + item.targetName,
                            targetName: item.targetName,
                            legend: item.phaiscType,
                            valueName: item.unit[0],
                            minValue: item.minValue.toFixed(3),
                            maxValue: item.maxValue.toFixed(3),
                            gvalue: gvalue
                        }
                        list.value.push(shuju)
                    }
                } else {
                    let shuju = {
                        id: 'qushifenx' + i,
                        title: item.lineName + '--' + item.targetName,
                        targetName: item.targetName,
                        legend: item.phaiscType,
                        valueName: item.unit[0],
                        minValue: null,
                        avalue: [],
                        bvalue: [],
                        cvalue: [],
                        topLimit: [],
                        lowerLimit: [],
                        chufa: []
                    }
                    list.value.push(shuju)
                }
            }
        }
    })

    rendering()
}
const rendering = () => {
    list.value.forEach((item: any) => {
        let opitonserise: any[] = []
        item.legend.forEach((item2: any) => {
            if (item.avalue !== undefined && (item2 == 'A相' || item2 == 'AB相' || item2 == '零序电压')) {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color: '#DAA520'
                        }
                    },

                    data: item.avalue
                }
                opitonserise.push(data)
            } else if (item.bvalue !== undefined && (item2 == 'B相' || item2 == 'BC相' || item2 == '正序电压')) {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color: '#2E8B57'
                        }
                    },

                    data: item.bvalue
                }
                opitonserise.push(data)
            } else if (item.cvalue !== undefined && (item2 == 'C相' || item2 == 'CA相' || item2 == '负序电压')) {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#A52a2a'
                        }
                    },
                    data: item.cvalue
                }
                opitonserise.push(data)
            } else if (item.topLimit !== undefined && item2 == '上限') {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color: '#FF33FF',
                            lineStyle: {
                                width: 2,
                                color: '#FF33FF',
                                type: 'dotted' //'dotted'虚线 'solid'实线
                            }
                        }
                    },
                    data: item.topLimit
                }
                opitonserise.push(data)
            } else if (item.lowerLimit !== undefined && item2 == '下限') {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#3399FF',
                            lineStyle: {
                                width: 2,
                                color: '#3399FF',
                                type: 'dotted' //'dotted'虚线 'solid'实线
                            }
                        }
                    },
                    data: item.lowerLimit
                }
                opitonserise.push(data)
            } else if (item.chufa !== undefined && item2 == '暂态触发点') {
               // console.log(123, new URL('@/assets/point.png', import.meta.url).href)

                let data = {
                    name: item2,
                    type: 'scatter',
                    symbol: `image://` + new URL('@/assets/point.png', import.meta.url).href,
                    symbolSize: 16,
                    itemStyle: {
                        width: '16px',
                        height: '16px'
                    },
                    data: item.chufa
                }
                opitonserise.push(data)
            } else if (item.gvalue !== undefined && item2 == '频率') {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    smooth: true,
                    itemStyle: {
                        normal: {
                            color: '#990099',
                            lineStyle: {
                                width: 2,
                                color: '#990099',
                                type: 'solid' //'dotted'虚线 'solid'实线
                            }
                        }
                    },
                    data: item.gvalue
                }
                opitonserise.push(data)
            } else if (item.gvalue !== undefined && item2 == '负序电流') {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#999933'
                        }
                    },
                    data: item.gvalue
                }
                opitonserise.push(data)
            } else if (item.gvalue !== undefined && item2 == '三相电压不平衡度') {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#FF6600'
                        }
                    },
                    data: item.gvalue
                }
                opitonserise.push(data)
            } else if (
                item.gvalue !== undefined &&
                (item2 == '三相总有功功率' || item2 == '三相总无功功率' || item2 == '三相总视在功率')
            ) {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#0033ff'
                        }
                    },
                    data: item.gvalue
                }
                opitonserise.push(data)
            } else if (item.gvalue !== undefined && (item2 == '总视在功率因数' || item2 == '总位移功率因数')) {
                let data = {
                    name: item2,
                    symbol: 'none',
                    symbolSize: 5,
                    type: 'line',
                    barWidth: 22,
                    itemStyle: {
                        normal: {
                            color: '#00FF00'
                        }
                    },

                    data: item.gvalue
                }
                opitonserise.push(data)
            }
        })
        if (item.valueName == undefined) {
            item.valueName = '无'
        }

        // console.log('渲染数据体', opitonserise)
        item.serise = opitonserise
    })
    getEcharts()
}
const getEcharts = () => {
    list.value.forEach((item: any, i: number) => {
        item.option = {
            backgroundColor: '#fff',
            title: {
                left: 'center',
                text: item.title
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    //type: "shadow",
                    type: 'cross', // 默认为直线，可选为：'line' | 'shadow'
                    label: {
                        color: '#fff',
                        fontSize: 16
                    }
                },
                textStyle: {
                    color: '#fff',
                    fontStyle: 'normal',
                    opacity: 0.35,
                    fontSize: 14
                },
                backgroundColor: 'rgba(0,0,0,0.55)',

                formatter: function (params: any) {
                    let tips = ''
                    tips += '时刻:' + params[0].data[0] + '</br/>'
                    for (let i = 0; i < params.length; i++) {
                        if (params[i].seriesName == '暂态触发点') {
                            tips += ''
                            return tips
                        }
                        if (params[i].seriesName == 'A相谐波电流方向') {
                            tips +=
                                params[i].value[1] > 0
                                    ? 'A相谐波电流方向:流入<br/>'
                                    : params[i].value[1] == 0
                                        ? 'A相谐波电流方向:无<br/>'
                                        : 'A相谐波电流方向:流出<br/>'
                        } else if (params[i].seriesName == 'B相谐波电流方向') {
                            tips +=
                                params[i].value[1] > 0
                                    ? 'B相谐波电流方向:流入<br/>'
                                    : params[i].value[1] == 0
                                        ? 'B相谐波电流方向:无<br/>'
                                        : 'B相谐波电流方向:流出<br/>'
                        } else if (params[i].seriesName == 'C相谐波电流方向') {
                            tips +=
                                params[i].value[1] > 0
                                    ? 'C相谐波电流方向:流入<br/>'
                                    : params[i].value[1] == 0
                                        ? 'C相谐波电流方向:无<br/>'
                                        : 'C相谐波电流方向:流出<br/>'
                        } else if (params[i].seriesName == '总谐波电流方向') {
                            tips +=
                                params[i].value[1] > 0
                                    ? '总谐波电流方向:流入<br/>'
                                    : params[i].value[1] == 0
                                        ? '总谐波电流方向:无<br/>'
                                        : '总谐波电流方向:流出<br/>'
                        } else if (params[i].seriesName == '正序电压') {
                            let str = (params[i].value[1] * 1).toString()
                            let reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
                            let str1 = str.replace(reg, '$1,')
                            tips += params[i].seriesName + ':' + str1 + 'kV<br/>'
                        } else if (params[i].seriesName == '零序电压' || params[i].seriesName == '负序电压') {
                            let str = (params[i].value[1] * 1).toString()
                            let reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
                            let str1 = str.replace(reg, '$1,')
                            tips += params[i].seriesName + ':' + str1 + 'V<br/>'
                        } else if (params[i].seriesName !== '正序电压') {
                            let str = (params[i].value[1] * 1).toString()
                            let reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
                            let str1 = str.replace(reg, '$1,')
                            tips += params[i].seriesName + ':' + str1 + '<br/>'
                        } else {
                            let str = (params[i].value[2] * 1).toString()
                            let reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
                            let str1 = str.replace(reg, '$1,')
                            tips += params[i].seriesName + ':' + str1 + '<br/>'

                            let str2 = (params[i].value[3] * 1).toString()
                            let reg2 = str2.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
                            let str12 = str.replace(reg2, '$1,')
                            // if(params[i].seriesName){

                            // }
                            tips += params[i].seriesName + ':' + str12 + '<br/>'
                        }
                    }

                    return tips
                }
            },
            legend: {
                left: '140px',
                verticalAlign: 'top',
                enabled: true,
                itemDistance: 5,
                textStyle: {
                    rich: {
                        a: {
                            verticalAlign: 'middle'
                        }
                    },

                    padding: [0, 0, 0, 0] //[上、右、下、左]
                }
            },
            xAxis: [
                {
                    type: 'time',
                    axisLine: {
                        show: true,
                        onZero: false
                    },
                    axisLabel: {
                        textStyle: {
                            fontFamily: 'dinproRegular'
                        }
                    }
                }
            ],
            toolbox: {
                show: true,
                feature: {
                    dataZoom: {
                        // bottom: '10px',
                        yAxisIndex: 'none'
                    }
                }
            },
            yAxis: [
                {
                    type: 'value',

                    min: item.minValue,
                    name: item.valueName,
                    axisLabel: {
                        interval: 0,
                        formatter: function (value: any) {
                            return value.toFixed(3)
                        },
                        left: '20px'
                    },

                    axisLine: {
                        show: true,
                        onZero: false, //-----------重点
                        lineStyle: {}
                    },
                    splitLine: {
                        lineStyle: {
                            // 使用深浅的间隔色
                            type: 'dashed',
                            opacity: 0.5
                        }
                    }
                }
            ],
            series: item.serise
        }
        let aValues = []
        let bValues = []
        let CValues = []
        let ZValues = []

        if (
            traceability.value.length > 0 &&
            traceability.value[0].value != null &&
            traceability.value[0].value.length > 0
        ) {
            for (let i = 0; i < traceability.value[0].value.length; i++) {
                let T = traceability.value[0].value[i][0]
                let A = traceability.value[0].value[i][1]
                let B = traceability.value[0].value[i][2]
                let C = traceability.value[0].value[i][3]
                let Z = A + B + C
                aValues.push([T, A > 0 ? 1 : A == 0 ? 0 : -1])
                bValues.push([T, B > 0 ? 1 : B == 0 ? 0 : -1])
                CValues.push([T, C > 0 ? 1 : C == 0 ? 0 : -1])
                ZValues.push([T, Z > 0 ? 1 : Z == 0 ? 0 : -1])
            }
        }

        if (item.targetName == '谐波电流方向') {
            item.option.tooltip.axisPointer = null
            item.option.yAxis[0] = {
                type: 'value',
                interval: 1,
                min: -2, //最小值
                max: 2,
                axisLine: {
                    show: true,
                    onZero: false //-----------重点
                },
                splitLine: {
                    lineStyle: {
                        // 使用深浅的间隔色
                        type: 'dashed',
                        opacity: 0.5
                    }
                },
                axisLabel: {
                    formatter: function (value: any) {
                        if (value == 0) {
                            return '无'
                        } else if (value == -1) {
                            return '流出'
                        } else if (value == 1) {
                            return '流入'
                        }
                    }
                }
            }
            item.option.series = [
                {
                    name: 'A相谐波电流方向',
                    type: 'line',

                    data: aValues,
                    symbol: 'none',
                    symbolSize: 0,
                    itemStyle: {
                        normal: {
                            color: '#DAA520'
                        }
                    }
                },
                {
                    name: 'B相谐波电流方向',
                    type: 'line',

                    data: bValues,
                    symbol: 'none',
                    symbolSize: 0,
                    itemStyle: {
                        normal: {
                            color: '#2E8B57'
                        }
                    }
                },
                {
                    name: 'C相谐波电流方向',
                    type: 'line',

                    data: CValues,
                    symbol: 'none',
                    symbolSize: 0,
                    itemStyle: {
                        normal: {
                            color: '#FF3300'
                        }
                    }
                },
                {
                    name: '总谐波电流方向',
                    type: 'line',

                    data: ZValues,
                    symbol: 'none',
                    symbolSize: 0,
                    itemStyle: {
                        normal: {
                            color: '#0033ff'
                        }
                    }
                }
            ]
        }
    })
    loading.value = false
}
onMounted(() => {
    nextTick(() => {
        setTimeout(() => {
            History()
        }, 0)
    })
})
defineExpose({ History })
</script>

<style lang="scss" scoped>
.conditions {
    position: absolute;
    top: 10px;
    right: 10px;
}
</style>
