<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-form-item>
        </el-form>
        <vxe-table
            :data="totalData"
            :height="vh"
            border
            stripe
            :row-config="{ isCurrent: true, isHover: true }"
            size="mini"
            ref="Statisticaltable"
            v-loading="isLoading1"
            style="width: 100%"
            header-cell-class-name="table_header"
        >
            <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-column
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :min-width="item.width"
                            :key="index"
                        >
                            <!-- <template v-for="(item, index) in item.children">
                    <vxe-table-column :field="item.prop" :title="item.label" :key="index" ></vxe-table-column>
                  </template> -->
                        </vxe-table-column>
                    </template>
                </vxe-table-colgroup>
            </template>
        </vxe-table>
    </div>
</template>

<script>
import { getRStatOrgIndex } 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 {
            vh: undefined,
            date: '',
            input: '',
            height: null,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: 0
            },
            isLoading1: false,
            //区域超标统计
            tableHeaderTotal: [
                { prop: 'orgName', label: '所属单位', width: 100 },
                { prop: 'allCount', label: '当月在线监测点数量(个)', width: 140 },
                { label: '频率合格率(%)', prop: 'freqPassRate', width: 100 },
                {
                    label: '电压合格率(%)',
                    prop: 'vdevPassRate',
                    width: 100
                },
                {
                    label: '长时闪变合格率(%)',
                    prop: 'flickerPassRate',
                    width: 100
                }
            ],
            totalData: [],
            device: '',
            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.vh = window.sessionStorage.getItem('appheight') - 175
        },
        // 表格查询
        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]
            getRStatOrgIndex(this.form).then(res => {
                this.isLoading1 = false
                this.totalData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //导出
        exportEvent() {
            this.$refs.Statisticaltable.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 .form {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-form-item {
        display: flex;
        width: 48%;
        .el-form-item__content {
            flex: 1 !important;
            .el-select {
                width: 100%;
            }
            .el-input__inner {
                width: 100% !important;
            }
            .el-date-editor {
                width: 100%;
            }
        }
    }
}
</style>
