<template>
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <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" class="ml10" icon="el-icon-search" @click="summarystatistics">查询</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="summarystatisticsData"
                    :height="height"
                    border
                    :row-config="{ isCurrent: true, isHover: true }"
                    size="mini"
                    ref="summarystatistics"
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                    :cell-style="cellStyle"
                >
                    <template v-for="(item, index) in tableHeaderSummarystatistics">
                        <vxe-table-column
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :key="index"
                            :min-width="item.width"
                        ></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="summarystatisticsData.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 { getSummaryStatOfMonitoringIndexDataQualityProblems } from '@/api/Management-operation/mainnetwork/mainnetwork'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: ''
            },

            tableHeaderSummarystatistics: [
                { prop: 'orgName', label: '单位' },
                {
                    prop: 'effectiveAccessMeasurementCount',
                    label: '有效接入监测点数量'
                },
                { prop: 'problem', label: '存在数据质量问题监测点数' },
                { prop: 'problemProportion', label: '存在数据质量问题监测点数占比(%)' },
                { prop: 'problemYearOnYear', label: '存在数据质量问题监测点数同比(%)' }
            ],
            summarystatisticsData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)

        this.summarystatistics()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },
        //获取主网运行指标统计数据
        summarystatistics() {
            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]
            getSummaryStatOfMonitoringIndexDataQualityProblems(this.form).then(res => {
                this.isLoading = false
                this.summarystatisticsData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            //console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.summarystatistics()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.summarystatistics()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        cellStyle(row) {
            if (row.columnIndex == 4) {
                if (row.row.problemYearOnYear == 3.14159) {
                    row.row.problemYearOnYear = '暂无数据 '
                }
            }
        },
        //导出
        exportEvent() {
            this.$refs.summarystatistics.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;
}

.button {
    float: right;
    margin-right: 5px;
}
</style>
