<template>
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="核查规则:">
                <el-select v-model="rule" placeholder="请选择">
                    <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" 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">
                <div class="button mb10">
                    <el-button type="primary" icon="el-icon-share">导出报表</el-button>
                </div>
                <el-table
                    stripe
                    :data="tractionstationData"
                    :height="height"
                    border
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                >
                    <template v-for="(item, index) in tableHeaderTractionstation">
                        <el-table-column
                            :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="tractionstationData.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 { getTractionstationgpointData } from '@/api/Management-operation/mainnetwork'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            rule: 0, //核查规则
            //核查规则数据
            ruleData: [
                {
                    id: 0,
                    value: '选项1',
                    label: '全部'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '规则1'
                },
                {
                    id: 2,
                    value: '选项3',
                    label: '规则2'
                },
                {
                    id: 3,
                    value: '选项4',
                    label: '规则3'
                }
            ],

            tableHeaderTractionstation: [
                { prop: 'rule', label: '核查规则' },
                { prop: 'substation', label: '供电变电站' },
                { prop: 'number', label: '牵引站编号' },
                { prop: 'name', label: '牵引站名称' },
                { prop: 'voltageLevel', label: '供电电压等级' },
                { prop: 'Name', label: '电铁线路名称' },
                { prop: 'type', label: '铁路类型' }
            ],
            tractionstationData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.tractionstation()
    },
    mounted() {
        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') - 265
        },
        //获取主网运行指标统计数据
        tractionstation() {
            this.isLoading = true
            getTractionstationgpointData().then(res => {
                this.isLoading = false
                this.tractionstationData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.tractionstation()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.tractionstation()
        },
        //查询
        researchFn() {
            this.tractionstation()
        },
        //重置
        Reset() {
            this.rule = 0
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../../styles/comStyle.less');
::v-deep .el-table .cell {
    text-align: center;
}
::v-deep .el-tabs--border-card > .el-tabs__content {
    padding: 10px;
}

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