<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" :timeOptions="timeOptions"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" class="ml10" icon="el-icon-search" @click="qualitystatistics">查询</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="qualitystatisticsData"
                    :height="height"
                    border
                    :row-config="{ isCurrent: true, isHover: true }"
                    size="mini"
                    ref="qualitystatistics"
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                    :cell-style="cellStyle"
                >
                    <template v-for="(item, index) in tableHeaderQualitystatistics">
                        <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="qualitystatistics.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 { getMonitoringIndexDataQualityStat } from '@/api/Management-operation/mainnetwork/mainnetwork'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: ''
            },

            tableHeaderQualitystatistics: [
                { prop: 'orgName', label: '单位' },
                { prop: 'measurementCount', label: '在运监测点数量' },
                {
                    prop: 'effectiveAccessMeasurementCount',
                    label: '有效接入监测点数量'
                },
                { prop: 'effectiveAccessRate', label: '有效接入率(%)' },
                { prop: 'dataIntegrityRate', label: '数据完整率(%)' },
                { prop: 'indexIntegrityRate', label: '指标完整率(%)' },
                { prop: 'isUnusual', label: '异常监测点数' }
            ],
            qualitystatisticsData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18, // 每页的数据条数
            timeOptions : [
                { label: '年份', value: 1 },
                { label: '季度', value: 2 },
                { label: '月份', value: 3 }
    
            ]
        }
    },
    created() {
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.qualitystatistics()
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 215
        },
        //获取主网运行指标统计数据
        qualitystatistics() {
            this.isLoading = 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]
            getMonitoringIndexDataQualityStat(this.form).then(res => {
                this.isLoading = false
                this.qualitystatisticsData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.qualitystatistics()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.qualitystatistics()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        //判断数据是否异常
        cellStyle(row) {
            console.log(row)
            // if (row.columnIndex == 6) {
            //     if (row.row.isUnusual == 0) {
            //         row.row.isUnusual = '正常 '
            //     } else if (row.row.isUnusual == 1) {
            //         row.row.isUnusual = '异常'
            //     }
            // }
        },
        //导出
        exportEvent() {
            this.$refs.qualitystatistics.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>
