<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="researchFn">查询</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">
                <el-table
                    stripe
                    :data="mainnetworkData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                    :height="height"
                    border
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                >
                    <template v-for="(item, index) in tableHeadermainnetwork">
                        <el-table-column
                            align="center"
                            :prop="item.prop"
                            :label="item.label"
                            :key="index"
                            :min-width="item.width"
                        ></el-table-column>
                    </template>
                </el-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="mainnetworkData.length"
                    class="mt10"
                ></el-pagination>
            </el-col>
            <el-col :span="24" :style="`height:${vh}`">
                <MainnetworkEcharts ref="MainnetworkEcharts" :mainnetworkData="mainnetworkData"></MainnetworkEcharts>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Timeinterval from '../../../components/Timeinterval.vue'
import Area from '@/views/components/Area/Area.vue'
import MainnetworkEcharts from './echarts/MainnetworkEcharts.vue'
import { getOperatingList } from '@/api/Management-operation/operationIndex/operationIndex'
export default {
    components: { Area, Timeinterval, MainnetworkEcharts },
    data() {
        return {
            vh: '',
            height: null,
            item: ['', ''],
            form: {
                endTime: '',
                startTime: '',
                id: '',
                type: ''
            },
            isLoading: false,
            //全网水平评价表头
            tableHeadermainnetwork: [
                { prop: 'orgName', label: '单位', width: 160 },
                //{ prop: 'dataDate', label: '时间', width: 160 },
                { prop: 'measurementRunPoints', label: '在运监测点数(个)', width: 140 },
                { prop: 'transitMeasurementPoints', label: '在线监测点数(个)', width: 160 },
                {
                    prop: 'onlineMeasurementPoints',
                    label: '在运监测终端数(台)',
                    width: 140
                },
                { prop: 'onlineMeasurementCount', label: '在线终端数(个)', width: 140 },
                { prop: 'transitMeasurementRate', label: '在线监测率(%)', width: 140 },
                { prop: 'dataIntegrityRate', label: '数据完整率(%)', width: 140 },
                { prop: 'dataRightRate', label: '数据准确率(%)', width: 140 },
                { prop: 'indexIntegrityRate', label: '应设点覆盖率(%)', width: 140 }
            ],
            mainnetworkData: [],
            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.mainnetwork()
    },

    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.height = (window.sessionStorage.getItem('appheight') - 210) / 2
            this.vh = window.sessionStorage.getItem('appheight') / 2 - 65 + 'px'
        },

        //获取主网运行指标统计数据
        mainnetwork() {
            this.isLoading = true
            ;(this.$refs.interval.timeOptions = [
                { label: '年份', value: 1 },
                { label: '月份', value: 3 }
            ]),
                (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]
            getOperatingList(this.form).then(res => {
                this.isLoading = false
                this.mainnetworkData = res.data
                setTimeout(() => {
                    this.$refs.MainnetworkEcharts.province()
                }, 100)
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.mainnetwork()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.mainnetwork()
        },
        //查询
        researchFn() {
            this.mainnetwork()
            this.$refs.MainnetworkEcharts.province()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../styles/comStyle.less');
</style>
