<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 style="margin-bottom: 10px">
                <el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
                <!-- <el-button type="primary" icon="el-icon-refresh">重置</el-button> -->
                <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>
            </el-form-item>

            <el-form-item>
                <el-button type="text" @click="closeHandle">
                    条件筛选
                    <i :class="!view ? 'el-icon-arrow-down' : 'el-icon-arrow-right'"></i>
                </el-button>
            </el-form-item>
        </el-form>
        <div class="container" id="container">
            <i @click="closeHandle" class="el-icon-circle-close coles"></i>
            <el-form :inline="true" label-width="110px">
                <el-form-item label="所属变电站:">
                    <el-select v-model="form.powerrIds" clearable multiple collapse-tags placeholder="请选择">
                        <el-option
                            v-for="item in substationData"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="监测点电压等级:">
                    <el-select
                        v-model="form.voltageLevels"
                        clearable
                        multiple
                        collapse-tags
                        placeholder="请选择"
                        style="width: 225px"
                    >
                        <el-option
                            v-for="item in voltageLevel"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="监测点名称:">
                    <el-input v-model="form.monitorName" clearable placeholder="请填写内容"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <!-- :data="tableData.slice((pageNum - 1) * pageSize, pageNum * pageSize)" -->
        <vxe-table
            :data="totalData.slice((pageNum - 1) * pageSize, pageNum * pageSize)"
            :height="vh"
            stripe
            border
            :row-config="{ isCurrent: true, isHover: true }"
            size="mini"
            ref="PartsList"
            v-loading="isLoading1"
            style="width: 100%"
            header-cell-class-name="table_header"
        >
            <template v-for="(item, index) in tableHeaderTotal">
                <vxe-table-column
                    align="center"
                    :field="item.prop"
                    :title="item.label"
                    :min-width="item.width"
                    :key="index"
                    show-overflow
                >
                    <!-- <template v-for="(item, index) in item.children">
                <el-table-column :prop="item.prop" :label="item.label" :min-width="item.width" :key="index" >
                  <template v-for="(item, index) in item.children">
                    <el-table-column :prop="item.prop" :label="item.label" :key="index" ></el-table-column>
                  </template>
                </el-table-column>
              </template> -->
                </vxe-table-column>
            </template>
        </vxe-table>
        <el-pagination
            class="mt10"
            background
            align="right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[20, 30, 40, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalData.length"
        ></el-pagination>
    </div>
</template>

<script>
import {
    getRMpPassRateInfo,
    getPmsPowerrInfoWithInOrg
} from '@/api/Statistical-analysis/steadyStateIndicators/steadyStateIndicators'
import Timeinterval from '@/views/components/Timeinterval.vue'
import Area from '@/views/components/Area/Area.vue'
import { dicData } from '@/assets/commjs/dictypeData'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: undefined,
            fvh: '',
            date: '',
            pageNum: 1,
            pageSize: 20,
            input: '',

            height: null,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                monitorName: '',
                voltageLevels: [],
                powerrIds: [],
                type: 0
            },
            view:false,
            formData: {
                deptIndex: '',
                manufacturer: [],
                monitorObjectType: [],
                monitorState: [],
                statisticalType: {},
                voltageLevel: [],
                upToGrid: ''
            },
            voltageLevel: [], //电压等级
            substationData: [], //所属变电站
            isLoading1: false,
            //区域超标统计
            tableHeaderTotal: [
                { prop: 'measurementPointName', label: '监测点名称', width: 200 },
                // { prop: 'measurementPointId', label: '监测点编号', width: 100 },
                { prop: 'monitorVoltageName', label: '监测点电压等级', width: 100 },
                { prop: 'orgName', label: '所属单位', width: 100 },
                { prop: 'powerrName', label: '所属电站', width: 100 },
                { prop: 'freqPassRate', label: '频率合格率(%)', width: 100 },
                { prop: 'vdevPassRate', label: '电压合格率(%)', width: 100 },
                { prop: 'flickerPassRate', label: '长时闪变合格率(%)', width: 100 }
            ],
            totalData: [],
            timeOptions: [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
            ]
        }
    },
    created() {},
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
        this.formData.deptIndex = JSON.parse(window.sessionStorage.getItem('Info')).deptId
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
        this.getclassificationData()
        this.Obtain()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.vh = window.sessionStorage.getItem('appheight') - 215
        },
        //获取类型
        getclassificationData() {
            //电压等级
            var code = 'Dev_Voltage'
            this.voltageLevel = dicData(code, [])
            this.voltageLevel.forEach(item => {
                this.form.voltageLevels.push(item.id)
            })
        },
        // 表格查询
        onSubmit() {
            this.isLoading1 = true
            ;(this.pageNum = 1), (this.pageSize = 20), (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]
            getRMpPassRateInfo(this.form).then(res => {
                this.isLoading1 = false
                this.totalData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
            this.formData.deptIndex = data.id
        },
        //获取变电站
        Obtain() {
            this.form.powerrIds = []
            getPmsPowerrInfoWithInOrg(this.formData).then(res => {
                let obj = {}
                setTimeout(() => {
                    for (var i = 0; i < res.data.length; i++) {
                        if (!obj[res.data[i].id]) {
                            this.substationData.push(res.data[i])
                            obj[res.data[i].id] = true
                        }
                    }
                    this.substationData.forEach(item => {
                        this.form.powerrIds.push(item.id)
                    })
                }, 0)
                setTimeout(() => {
                    this.onSubmit()
                }, 10)
            })
        },
        //导出
        exportEvent() {
            this.$refs.PartsList.exportData({
                filename: 'export', // 文件名字
                sheetName: 'Sheet1',
                type: 'xlsx', //导出文件类型 xlsx 和 csv
                useStyle: true,
                data: this.totalData // 数据源 // 过滤那个字段导出 // columnFilterMethod: function(column, $columnIndex) { //   return !(column.$columnIndex === 0 ) //   // 0是复选框 不导出 // }
            })
        },
        handleSizeChange(val) {
            this.pageSize = val
        },
        handleCurrentChange(val) {
            this.pageNum = val
        },
        closeHandle() {
            if (this.view) {
                this.view = false
            } else {
                this.view = true
            }
            //console.log('关闭和展开');
            const dom = document.getElementById('container')
            const closeDom = document.getElementsByClassName('close')[0]
            if (!dom.className.match(/(?:^|\s)expend(?!\S)/)) {
                dom.className = 'container expend'
            } else {
                dom.className = 'container close-container'
            }
        }
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../styles/comStyle.less');
::v-deep .el-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%;
            }
        }
    }
}
.container {
    /* margin: auto; */
    top: 0px;
    right: 0;
    width: 40%;
    height: 0px;
    z-index: 2000;
    position: absolute;
    background-color: #e4e7ebb9;
    overflow: auto;
    scroll-behavior: smooth;
    -radius: 20px;
}
/* 隐藏滚动条 */
::-webkit-scrollbar {
    display: block;
}
.expend {
    animation: expend ease 5s forwards;
}
.close-container {
    animation: no-expend ease 1s forwards;
}
@keyframes expend {
    from {
        top: 0px;
        height: auto;
    }
    to {
        height: auto;
        top: 0px;
    }
}
@keyframes no-expend {
    from {
        height: 20%;
        top: 0px;
    }
    to {
        top: 0px;
        height: 0px;
    }
}
.coles {
    position: absolute;
    right: 0;
    font-size: 20px;
    cursor: pointer;
}
</style>
