<template>
    <div>
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <Area @click="handleNodeClick" ref="Area"></Area>
            </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-button type="primary" icon="el-icon-refresh" @click="Reset"
          >重置</el-button
        > -->
            </el-form-item>
        </el-form>
        <vxe-table
            :data="totalData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
            :height="height"
            stripe
            border
            :row-config="{ isCurrent: true, isHover: true }"
            size="mini"
            ref="Interferencestatistics"
            v-loading="isLoading1"
            style="width: 100%"
            header-cell-class-name="table_header"
        >
            <vxe-table-column align="center" field="rowName" title="单位"  show-overflow min-width="220"></vxe-table-column>
            <template v-for="(item, index) in totalData[0].columns">
                <vxe-table-colgroup align="center" :title="item.loadName + '-超标点占比'" :key="index">
                    <vxe-table-colgroup title="电压" field="rowName" align="center">
                        <vxe-table-column title="累计" min-width="60" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].vaccrued }}
                                </span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column title="日均" min-width="60" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].vaverage }}
                                </span>
                            </template>
                        </vxe-table-column>
                    </vxe-table-colgroup>
                    <vxe-table-colgroup title="谐波电流" field="rowName" align="center">
                        <vxe-table-column title="累计" min-width="60" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].iaccrued }}
                                </span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column title="日均" min-width="60" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].iaverage }}
                                </span>
                            </template>
                        </vxe-table-column>
                    </vxe-table-colgroup>
                    <vxe-table-colgroup title="三相电压不平衡" field="rowName" align="center">
                        <vxe-table-column title="累计" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].unbalanceAccrued }}
                                </span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column title="日均" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].unbalanceAverage }}
                                </span>
                            </template>
                        </vxe-table-column>
                    </vxe-table-colgroup>
                    <vxe-table-colgroup title="负序电流" field="rowName" align="center">
                        <vxe-table-column title="累计" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].inegAccrued }}
                                </span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column title="日均" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].inegAverage }}
                                </span>
                            </template>
                        </vxe-table-column>
                    </vxe-table-colgroup>
                    <vxe-table-colgroup title="长时闪变" field="rowName" align="center">
                        <vxe-table-column title="累计" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].flickerAccrued }}
                                </span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column title="日均" min-width="80" align="center">
                            <template slot-scope="scope">
                                <span>
                                    {{ scope.row.columns[index].flickerAverage }}
                                </span>
                            </template>
                        </vxe-table-column>
                    </vxe-table-colgroup>
                </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="total"
            class="mt10"
        ></el-pagination>
    </div>
</template>

<script>
import { getRStatLoadType } from '@/api/Statistical-analysis/steadyStateIndicators/steadyStateIndicators'
import Timeinterval from '@/views/components/Timeinterval.vue'
import Area from '@/views/components/Area/Area.vue'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            // kai: true,
            // start: "",
            // end: "",
            // type: "",
            vh: undefined,
            date: '',
            input: '',
            height: null,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: 0
            },
            isLoading1: false,
            //区域超标统计
            // tableHeaderTotal: [
            //   { prop: "company", label: "单位",},
            //   { label: "风电-超标点占比", children: [
            //       { prop: "monthVoltage", label: "电压", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "谐波电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "三相电压不平衡", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "负序电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "闪变", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "flickerAccrued", label: "累计" }
            //       ] },
            //   ]},
            //   { label: "光伏-超标点占比", children: [
            //         { prop: "monthVoltage", label: "超标点占比", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "谐波电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "三相电压不平衡", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "负序电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "闪变", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //   ]},
            //   { label: "电铁-超标点占比", children: [
            //       { prop: "monthVoltage", label: "电压", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "谐波电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "三相电压不平衡", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "负序电流", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //       { prop: "monthVoltage", label: "闪变", children:[
            //             { prop: "monthVoltage", label: "日均" },
            //             { prop: "onlineMonitoring", label: "累计" }
            //       ] },
            //   ]},
            // ],
            totalData: [{ columns: [] }],
            device: '',
            currentPage: 1, // 当前页码
            total: undefined, // 总条数
            pageSize: 20, // 每页的数据条数
            timeOptions: [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
            ]
        }
    },
    created() {},
    mounted() {
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
        this.onSubmit()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.onSubmit()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.onSubmit()
        },
        // transient() {},
        // 表格查询
        onSubmit() {
            // this.kai = false;
            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]
            // console.log(this.form,'===============================');
            //方法调用获取暂态事件统计数据接口
            getRStatLoadType(this.form).then(res => {
                if (res.data.length == 0) {
                    this.totalData = [{ columns: [] }]
                    this.total = 0
                    this.isLoading1 = false
                } else {
                    this.isLoading1 = false
                    this.totalData = res.data
                    this.total = this.totalData.length
                }
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //重置
        Reset() {
            this.$refs.Area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        //导出
        exportEvent() {
            this.$refs.Interferencestatistics.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');
::v-deep .vxe-table .cell {
    text-align: center;
}
::v-deep .el-tabs--border-card > .el-tabs__content {
    padding: 10px;
}

::v-deep .el-row {
    width: 100%;
}
::v-deep .el-table__body-wrapper {
    height: 546px !important;
}
</style>
