<template>
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="核查规则:" class="box">
                <el-select
                    v-model="form.checkRules"
                    placeholder="请选择"
                    multiple
                    collapse-tags
                    style="width: 250px"
                    clearable
                >
                    <el-option v-for="item in ruleData" :key="item.id" :label="item.label" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <Area @click="handleNodeClick" ref="area"></Area>
            </el-form-item>

            <el-form-item>
                <Timeinterval :interval="3" ref="interval"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="questionquery">查询</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>

        <el-row>
            <el-col :span="24">
                <!-- <div class="button mb10"><el-button type="primary" icon="el-icon-share">导出报表</el-button></div> -->
                <vxe-table
                    :data="questionqueryData"
                    :height="height"
                    border
                    :row-config="{ isCurrent: true, isHover: true }"
                    size="mini"
                    ref="Questionquery"
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                >
                    <template v-for="(item, index) in tableHeaderQuestionquery">
                        <vxe-table-column
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :key="index"
                            :min-width="item.width"
                            :formatter="formFilter"
                        ></vxe-table-column>
                    </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="questionqueryData.length"
                    class="mt10"
                ></el-pagination>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Area from '@/views/components/Area/Area.vue'
import Timeinterval from '../../../../components/Timeinterval.vue'
import { getPwRStatTargetDetail } from '@/api/Management-operation/distributionnetwork/distributionnetwork'
import { dicData } from '@/assets/commjs/dictypeData'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: '',
                checkRules: [] //核查规则
            },
            //核查规则数据
            ruleData: [],
            voltageLevel: [],

            tableHeaderQuestionquery: [
                { prop: 'checkRules', label: '核查规则' },
                { prop: 'cityCompany', label: '地市公司' },
                { prop: 'powerName', label: '变电站名称' },
                { prop: 'mediumVoltageLine', label: '中压线路' },
                { prop: 'platformAreaName', label: '台区名称' },
                { prop: 'monitorName', label: '监测点名称' },
                // { prop: "monitorId", label: "监测点编号", },
                { prop: 'monitorVoltageLevel', label: '监测点电压等级' }
            ],
            questionqueryData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.getclassificationData()
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)

        this.questionquery()
    },
    computed: {
        //计算表格高度
        // height(){
        //   return '100vh'- this.$refs.form.offsetHeight +259;
        // }
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },

        //获取类型
        getclassificationData() {
            //稳态指标核查规则
            var code = 'Steady_Rules'
            this.ruleData = dicData(code, [])
            this.ruleData.forEach(item => {
                this.form.checkRules.push(item.id)
            })
            //电压等级
            var code1 = 'Dev_Voltage'
            this.voltageLevel = dicData(code1, [])
        },
        //获取主网运行指标统计数据
        questionquery() {
            this.isLoading = true
            ;(this.$refs.interval.timeOptions = [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
                // { label: "周", value: 4 },
                // // { label: "自定义", value: 5 },
            ]),
                (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]
            getPwRStatTargetDetail(this.form).then(res => {
                this.isLoading = false
                this.questionqueryData = res.data
            })
        },
        // 数据过滤
        formFilter(row, column) {
            if (row.column.property == 'checkRules') {
                let title = ''
                this.ruleData.forEach(item => {
                    if (item.value == row.row.checkRules) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'monitorVoltageLevel') {
                let title = ''
                this.voltageLevel.forEach(item => {
                    if (item.value == row.row.monitorVoltageLevel) {
                        title = item.label
                    }
                })
                return title
            } else {
                return row.row[row.column.property]
            }
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.questionquery()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.questionquery()
        },
        //重置
        Reset() {
            this.checkRules = 0
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        //导出
        exportEvent() {
            this.$refs.Questionquery.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 .box {
    .el-input {
        width: 250px;
    }
}
</style>
