<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-refresh-right"
          @click="resetForm"
          >重置</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.monitorSort"
                        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 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
                        style="width: 225px"
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in VoltageList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="监测点名称:" class="box">
                    <el-input v-model="form.monitorName" clearable placeholder="请填写内容"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <vxe-table
            :data="totalData"
            :height="vh"
            border
            stripe
            :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"
                    :formatter="formFilter"
                >
                    <!-- <template v-for="(item, index) in item.children">
              <vxe-table-column
                :prop="item.prop"
                :label="item.label"
                :min-width="item.width"
                :key="index"
              >
                <template v-for="(item, index) in item.children">
                  <vxe-table-column
                    :prop="item.prop"
                    :label="item.label"
                    :key="index"
                  ></vxe-table-column>
                </template>
              </vxe-table-column>
            </template> -->
                </vxe-table-column>
            </template>
        </vxe-table>
        <el-pagination
            background
            align="right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="form.pageNum"
            :page-sizes="[20, 30, 40, 50, 100]"
            :page-size="form.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            class="mt10"
        ></el-pagination>
    </div>
</template>

<script>
import { getPwRMpPassRateInfo } from '@/api/Distributionnetwork/steady-state/steady-state'
import { getPmsPowerrInfoWithInOrg } from '@/api/Statistical-analysis/steadyStateIndicators/steadyStateIndicators'
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,
            view: false,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                monitorName: '',
                monitorSort: [],
                powerrIds: [],
                startTime: '',
                type: 0,
                pageNum: 1,
                pageSize: 20,
                voltageLevels: []
            },
            formData: {
                deptIndex: '',
                manufacturer: [],
                monitorObjectType: [],
                monitorState: [],
                statisticalType: {},
                voltageLevel: [],
                upToGrid: ''
            },
            //监测点类别数据
            typeList: [],
            VoltageList: [], //电压等级数据
            substationData: [], //所属变电站
            isLoading1: false,
            //暂态事件统计
            tableHeaderTotal: [
                { prop: 'measurementPointName', label: '监测点名称', width: 150 },
                { prop: 'monitorSort', label: '监测点类型', width: 100 },
                // { prop: "onlineMonitoring", label: "监测点编号" },
                { prop: 'monitorVoltageName', label: '监测点电压等级', width: 120 },
                { prop: 'orgName', label: '所属单位', width: 100 },
                { prop: 'powerName', label: '所属电站', width: 100 },
                { prop: 'freqPassRate', label: '频率合格率', width: 100 },
                { prop: 'vdevPassRate', label: '电压合格率', width: 100 },
                { prop: 'flickerPassRate', label: '长时闪变合格率', width: 100 }
            ],
            totalData: [],
            device: '',
            total: undefined, // 总条数
            timeOptions: [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
            ]
        }
    },
    created() {
        this.getclassificationData()
        this.formData.deptIndex = JSON.parse(window.sessionStorage.getItem('Info')).deptId
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
        this.Obtain()
    },
    mounted() {
        this.device = window.devicePixelRatio

        this.setHeight()
        window.addEventListener('resize', this.setHeight)
        this.onSubmit()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.vh = window.sessionStorage.getItem('appheight') - 215
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.onSubmit()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.onSubmit()
        },
        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'
            }
        },
        // 表格查询
        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]
            getPwRMpPassRateInfo(this.form).then(res => {
                this.totalData = res.data.records
                this.total = res.data.total
                this.isLoading1 = false
            })
        },
        // 数据过滤
        formFilter(row, column) {
            if (row.column.property == 'monitorSort') {
                let title = ''
                this.typeList.forEach(item => {
                    if (item.value == row.row.monitorSort) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'monitorVoltageName') {
                let title = ''
                this.VoltageList.forEach(item => {
                    if (item.value == row.row.monitorVoltageName) {
                        title = item.label
                    }
                })
                return title
            } else {
                return row.row[row.column.property]
            }
        },
        // 重置
        resetForm() {
            this.form = {}
            this.$refs.interval.intervald = 1
        },
        //获取类型
        getclassificationData() {
            // 监测点类别
            var Monitoring = 'Line_Sort'
            this.typeList = dicData(Monitoring, ['Load_Type'])
            this.typeList.forEach(item => {
                this.form.monitorSort.push(item.id)
            })
            //电压等级
            var Voltage = 'Dev_Voltage'
            this.VoltageList = dicData(Voltage, ['Load_Type'])
            this.VoltageList.forEach(item => {
                this.form.voltageLevels.push(item.id)
            })
        },
        // 切换选项
        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 = {}
                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)
                })
            })
        },
        //导出
        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是复选框 不导出 // }
            })
        }
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../../styles/comStyle.less');
.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>
