<template>
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item>
                <Area @click="handleNodeClick" ref="area"></Area>
            </el-form-item>

            <el-form-item>
                <Timeinterval :interval="3" ref="interval"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" class="ml10" icon="el-icon-search" @click="monitoringindicators">
                    查询
                </el-button>
                <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>

                <!-- <el-button type="primary" icon="el-icon-refresh" @click="Reset">重置</el-button> -->
            </el-form-item>
        </el-form>

        <el-row>
            <el-col :span="24">
                <!-- <div class="button mb10"><el-button type="primary" icon="el-icon-share">导出报表</el-button></div> -->
                <vxe-table
                    :data="monitoringindicatorsdata"
                    :height="height"
                    border
                    :row-config="{ isCurrent: true, isHover: true }"
                    size="mini"
                    ref="monitoringindicators"
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                >
                    <template v-for="(item, index) in tableHeaderMonitoringindicators">
                        <vxe-table-colgroup
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :key="index"
                            :min-width="item.width"
                        >
                            <template v-for="(item, index) in item.children">
                                <vxe-table-colgroup
                                    align="center"
                                    :field="item.prop"
                                    :title="item.label"
                                    :key="index"
                                    :min-width="item.width"
                                >
                                    <template v-for="(item, index) in item.children">
                                        <vxe-table-column
                                            align="center"
                                            :field="item.prop"
                                            :title="item.label"
                                            :key="index"
                                            :min-width="item.width"
                                        ></vxe-table-column>
                                    </template>
                                </vxe-table-colgroup>
                            </template>
                        </vxe-table-colgroup>
                    </template>
                </vxe-table>
                <el-pagination
                    background
                    align="right"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[20, 30, 40, 50, 100]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="monitoringindicatorsdata.length"
                    class="mt10"
                ></el-pagination>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Area from '@/views/components/Area/Area.vue'
import Timeinterval from '../../../../components/Timeinterval.vue'
import { getMonitoringIndexDataQualityVerification } from '@/api/Management-operation/mainnetwork/mainnetwork'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: ''
            },

            tableHeaderMonitoringindicators: [
                { prop: 'orgName', label: '单位', width: 100 },
                {
                    prop: 'question',
                    label: '稳态指标有问题数量',
                    children: [
                        {
                            prop: 'fundamentalVoltageAbnormal',
                            label: '基波电压指标数值不合理',
                            width: 180
                        },
                        {
                            prop: 'frequencyAbnormal',
                            label: '频率指标数值不合理',
                            width: 180
                        },
                        {
                            prop: 'vdevAbnormal',
                            label: '电压偏差指标数值不合理',
                            width: 180
                        },
                        {
                            prop: 'harmonicVoltageAbnormal',
                            label: '谐波电压指标数值不合理',
                            width: 200
                        },
                        {
                            prop: 'centreHarmonicVoltage',
                            label: '间谐波电压指标数值不合理',
                            width: 250
                        },
                        {
                            prop: 'tpVoltageUnbalance',
                            label: '三相电压不平衡指标数值不合理',
                            width: 250
                        },
                        {
                            prop: 'vdevLastOverlimit',
                            label: '电压偏差连续超标',
                            width: 250
                        },
                        {
                            prop: 'tractionStationMeasurementNone',
                            label: '换流站监测点基波电压无数据或零',
                            width: 250
                        },
                        {
                            prop: 'irregularAddress',
                            label: '电气化铁路监测点',
                            children: [
                                {
                                    prop: 'railwayFundamentalVoltageAbnormal',
                                    label: '基波电压数值不合理或无数值',
                                    width: 250
                                },
                                {
                                    prop: 'railwayFundamentalCurrentAbnormal',
                                    label: '基波电流数值不合理或为0值',
                                    width: 250
                                },
                                {
                                    prop: 'railwayTotalActivePowerAbnormal',
                                    label: '总有功功率不合理',
                                    width: 250
                                },
                                {
                                    prop: 'railwayHarmonicVoltageContentAbnormal',
                                    label: '谐波电压含有率不合理',
                                    width: 250
                                }
                            ]
                        }
                    ]
                },
                {
                    prop: 'question1',
                    label: '暂态指标有问题数量',
                    children: [
                        { prop: 'freqUploadEvent', label: '频繁上传暂态事件', width: 180 },
                        {
                            prop: 'waveUploadError',
                            label: '录波文件未正确上传',
                            width: 180
                        },
                        {
                            prop: 'irregularName',
                            label: '暂态事件',
                            children: [
                                {
                                    prop: 'eventLastTimeAbnormal',
                                    label: '持续时间不合理',
                                    width: 150
                                },
                                {
                                    prop: 'eventTypeAmplitudeAtypism',
                                    label: '类型与特征幅值不一致',
                                    width: 180
                                },
                                {
                                    prop: 'eventTypeAmplitudeAbnormal',
                                    label: '特征幅值不合理',
                                    width: 150
                                },
                                {
                                    prop: 'eventPhaseNone',
                                    label: '相别为“未知”或“NONE”',
                                    width: 250
                                }
                            ]
                        },
                        {
                            prop: 'irregularName',
                            label: '运行电压',
                            children: [
                                {
                                    prop: 'runVolatgeUp',
                                    label: '偏高（非实际电压暂升事件）',
                                    width: 200
                                },
                                {
                                    prop: 'runVolatgeLow',
                                    label: '偏低（非实际电压暂降事件）',
                                    width: 200
                                }
                            ]
                        }
                    ]
                }
            ],
            monitoringindicatorsdata: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.monitoringindicators()
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },
        //获取主网运行指标统计数据
        monitoringindicators() {
            this.isLoading = true
            ;(this.$refs.interval.timeOptions = [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
                // { label: "周", value: 4 },
                // // { label: "自定义", value: 5 },
            ]),
                (this.form.type = this.$refs.interval.intervald)
            this.item = this.$refs.interval.timeValue
            this.form.startTime = this.item[0]
            this.form.endTime = this.item[1]
            getMonitoringIndexDataQualityVerification(this.form).then(res => {
                this.isLoading = false
                this.monitoringindicatorsdata = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            //console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.monitoringindicators()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.monitoringindicators()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        //导出
        exportEvent() {
            this.$refs.monitoringindicators.exportData({
                filename: 'export', // 文件名字
                sheetName: 'Sheet1',
                type: 'xlsx', //导出文件类型 xlsx 和 csv
                useStyle: true,
                data: this.totalData // 数据源 // 过滤那个字段导出 // columnFilterMethod: function(column, $columnIndex) { //   return !(column.$columnIndex === 0 ) //   // 0是复选框 不导出 // }
            })
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../../styles/comStyle.less');
</style>
