<template>
    <div>
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <Area @click="handleNodeClick" ref="area" @sendMessage="send"></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="Passrate"
            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"
                    :formatter="formFilter"
                >
                    <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 v-for="(item, index) in item.children">
                                <vxe-table-column
                                    align="center"
                                    :field="item.prop"
                                    :title="item.label"
                                    :min-width="item.width"
                                    :key="index"
                                ></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="total"
            class="mt10"
        ></el-pagination>
    </div>
</template>

<script>
import { getPwRStatOrgIndex } 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: 150 },
                { prop: 'monitorSort', label: '监测点类别', width: 100 },

                { prop: 'allCount', label: '累计有效接入监测点数', width: 160 },
                { prop: 'freqPassRate', label: '频率合格率', width: 100 },
                { prop: 'vdevPassRate', label: '电压偏差合格率', width: 120 },
                { prop: 'flickerPassRate', label: '闪变合格率', width: 100 }
            ],
            totalData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: undefined, // 总条数
            pageSize: 20, // 每页的数据条数
            timeOptions: [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
            ]
        }
    },
    created() {
        this.getclassificationData()
        // this.form.id = JSON.parse(window.sessionStorage.getItem("Info")).deptId;
    },
    mounted() {
        // this.onSubmit();
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.vh = window.sessionStorage.getItem('appheight') - 215
        },
        send(data) {
            this.form.id = data
            this.onSubmit()
            // console.log(this.form.id,'11111111111');
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.onSubmit()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.onSubmit()
        },
        // 表格查询
        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]
            getPwRStatOrgIndex(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
                }
            })
        },
        // 数据过滤
        formFilter(row) {
            if (row.column.property == 'monitorSort') {
                let title = ''
                this.typeList.forEach(item => {
                    if (item.value == row.row.monitorSort) {
                        title = item.label
                    }
                })
                return title
            } else {
                return row.row[row.column.property]
            }
        },
        //获取类型
        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
        },
        //导出
        exportEvent() {
            this.$refs.Passrate.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>
