<template>
    <div>
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <Area @click="handleNodeClick"></Area>
            </el-form-item>
            <el-form-item label="监测点类别:">
                <el-select v-model="form.ids" clearable multiple collapse-tags placeholder="请选择监测点类别">
                    <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <Timeinterval :interval="3" ref="interval" :timeOptions="timeOptions"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit" class="ml10" icon="el-icon-search">查询</el-button>
                <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>
            </el-form-item>
        </el-form>
        <vxe-table
            :data="totalData"
            :height="vh"
            border
            stripe
            :row-config="{ isCurrent: true, isHover: true }"
            size="mini"
            ref="Classifiedstatistics"
            v-loading="isLoading1"
            style="width: 100%"
            header-cell-class-name="table_header"
            :cell-style="cellStyle"
        >
            <template v-for="(item, index) in tableHeaderTotal">
                <vxe-table-colgroup
                    align="center"
                    :field="item.prop"
                    :title="item.label"
                    :min-width="item.width"
                    :key="index"
                >
                    <template v-for="(item, index) in item.children">
                        <vxe-table-colgroup
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :min-width="item.width"
                            :key="index"
                        >
                            <template slot-scope="scope">
                                <span>{{ scope.row[item.prop] == null ? '/' : scope.row[item.prop] }}</span>
                            </template>
                            <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"
                                >
                                    <template slot-scope="scope">
                                        <span>{{ scope.row[item.prop] == null ? '/' : scope.row[item.prop] }}</span>
                                    </template>
                                </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, 70, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            class="mt10"
        ></el-pagination>
    </div>
</template>

<script>
import { getPwRStatSubstation } from '@/api/Distributionnetwork/steady-state/steady-state'
import { dicData } from '@/assets/commjs/dictypeData'
import Timeinterval from '@/views/components/Timeinterval.vue'
import Area from '@/views/components/Area/Area.vue'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: undefined,
            date: '',
            input: '',
            height: null,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                ids: [],
                startTime: '',
                type: ''
            },
            //监测点类别数据
            typeList: [],
            isLoading1: false,
            //暂态事件统计
            tableHeaderTotal: [
                { prop: 'orgName', label: '单位', width: 180 },
                { prop: 'monitorSort', label: '监测点类别', width: 120 },
                {
                    label: '有效监测点数',
                    children: [
                        { prop: 'effectiveMeasurementAverage', label: '日均', width: 70 },
                        { prop: 'effectiveMeasurementAccrued', label: '累计', width: 70 }
                    ]
                },
                {
                    label: '超标监测点数',
                    children: [
                        { prop: 'harmonicMeasurementAverage', label: '日均', width: 70 },
                        { prop: 'harmonicMeasurementAccrued', label: '累计', width: 70 }
                    ]
                },
                {
                    label: '频率偏差',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage', label: '日均', width: 70 },
                                { prop: 'taccrued', label: '累计', width: 70, width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage', label: '日均', width: 70 },
                                { prop: 'oaccrued', label: '累计', width: 70, width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage', label: '日均', width: 70 },
                                { prop: 'chainAccrued', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage', label: '日均', width: 70 },
                                { prop: 'sameAccrued', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '电压偏差',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage1', label: '日均', width: 70 },
                                { prop: 'taccrued1', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage1', label: '日均', width: 70 },
                                { prop: 'oaccrued1', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage1', label: '日均', width: 70 },
                                { prop: 'chainAccrued1', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage1', label: '日均', width: 70 },
                                { prop: 'sameAccrued1', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay1', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '长时闪变',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage2', label: '日均', width: 70 },
                                { prop: 'taccrued2', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage2', label: '日均', width: 70 },
                                { prop: 'oaccrued2', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage2', label: '日均', width: 70 },
                                { prop: 'chainAccrued2', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage2', label: '日均', width: 70 },
                                { prop: 'sameAccrued2', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay2', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '谐波电流',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage4', label: '日均', width: 70 },
                                { prop: 'taccrued4', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage4', label: '日均', width: 70 },
                                { prop: 'oaccrued4', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage4', label: '日均', width: 70 },
                                { prop: 'chainAccrued4', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage4', label: '日均', width: 70 },
                                { prop: 'sameAccrued4', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay4', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '谐波电压',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage3', label: '日均', width: 70 },
                                { prop: 'taccrued3', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage3', label: '日均', width: 70 },
                                { prop: 'oaccrued3', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage3', label: '日均', width: 70 },
                                { prop: 'chainAccrued3', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage3', label: '日均', width: 70 },
                                { prop: 'sameAccrued3', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay3', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '间谐波电压',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage5', label: '日均', width: 70 },
                                { prop: 'taccrued5', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage5', label: '日均', width: 70 },
                                { prop: 'oaccrued5', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage5', label: '日均', width: 70 },
                                { prop: 'chainAccrued5', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage5', label: '日均', width: 70 },
                                { prop: 'sameAccrued5', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay5', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '三相电压不平衡度',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage6', label: '日均', width: 70 },
                                { prop: 'taccrued6', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage6', label: '日均', width: 70 },
                                { prop: 'oaccrued6', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage6', label: '日均', width: 70 },
                                { prop: 'chainAccrued6', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage6', label: '日均', width: 70 },
                                { prop: 'sameAccrued6', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay6', label: '平均超标天数', width: 120 }
                    ]
                },
                {
                    label: '负序电流',
                    children: [
                        {
                            prop: 'monthVoltage',
                            label: '监测点数',
                            children: [
                                { prop: 'taverage7', label: '日均', width: 70 },
                                { prop: 'taccrued7', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '占比',
                            children: [
                                { prop: 'oaverage7', label: '日均', width: 70 },
                                { prop: 'oaccrued7', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '同比',
                            children: [
                                { prop: 'chainAverage7', label: '日均', width: 70 },
                                { prop: 'chainAccrued7', label: '累计', width: 70 }
                            ]
                        },
                        {
                            prop: 'onlineMonitoring',
                            label: '环比',
                            children: [
                                { prop: 'sameAverage7', label: '日均', width: 70 },
                                { prop: 'sameAccrued7', label: '累计', width: 70 }
                            ]
                        },
                        { prop: 'averageOverDay7', label: '平均超标天数', width: 120 }
                    ]
                }
                // { prop: "onlineMonitoring", label: "稳态指标平均超标天数", width: 120, width: 180 },
            ],
            totalData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: undefined, // 总条数
            pageSize: 20, // 每页的数据条数
            timeOptions: [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
                // { label: "周", value: 4 },
                // // { label: "自定义", value: 5 },
            ]
        }
    },
    created() {
        this.getclassificationData()
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
        this.onSubmit()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.vh = window.sessionStorage.getItem('appheight') - 215
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.onSubmit()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.onSubmit()
        },
        transient() {},
        // 表格查询
        onSubmit() {
            this.isLoading1 = true

            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]
            //方法调用获取暂态事件统计数据接口
            getPwRStatSubstation(this.form).then(res => {
                if (res.data == [] || res.data == null) {
                    this.isLoading1 = false
                    this.totalData = res.data
                    this.total = 0
                } else {
                    this.isLoading1 = false
                    this.totalData = res.data
                    this.total = this.totalData.length
                }
            })
        },
        //获取类型
        getclassificationData() {
            var Monitoring = 'Line_Sort'
            this.typeList = dicData(Monitoring, ['Load_Type'])
            this.typeList.forEach(item => {
                this.form.ids.push(item.id)
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        cellStyle(row) {
            this.typeList.forEach(item => {
                if (item.value == row.row.monitorSort) {
                    row.row.monitorSort = item.label
                }
            })
        },
        //导出
        exportEvent() {
            this.$refs.Classifiedstatistics.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>
