<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="ledgerdata">查询</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="ledgerdataData"
                    :height="height"
                    border
                    :row-config="{ isCurrent: true, isHover: true }"
                    size="mini"
                    ref="Ledgerdata"
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                >
                    <template v-for="(item, index) in tableHeaderLedgerdata">
                        <vxe-table-colgroup
                            align="center"
                            :field="item.prop"
                            :title="item.label"
                            :key="index"
                            :min-width="item.width"
                        >
                            <template v-for="(item, index) in item.children">
                                <vxe-table-column
                                    align="center"
                                    :field="item.prop"
                                    :title="item.label"
                                    :key="index"
                                    :min-width="item.width"
                                ></vxe-table-column>
                            </template>
                        </vxe-table-colgroup>
                    </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="ledgerdataData.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 { getPwQualityCheckOfAccountData } from '@/api/Management-operation/distributionnetwork/distributionnetwork'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            item: ['', ''],
            form: {
                endTime: '',
                id: '',
                startTime: '',
                type: ''
            },

            tableHeaderLedgerdata: [
                { prop: 'orgName', label: '单位', width: 150 },
                {
                    prop: 'question',
                    label: '终端有问题数量',
                    children: [
                        { prop: 'devFieldNull', label: '必填字段为空', width: 120 },
                        { prop: 'devRunTimeAbnormal', label: '投运日期不规范', width: 120 },
                        { prop: 'devTypeError', label: '终端类型不正确', width: 120 },
                        {
                            prop: 'devCheckTimeAbnormal',
                            label: '上次检定日期不合理',
                            width: 150
                        },
                        { prop: 'devIpError', label: 'IP地址不规范', width: 120 }
                    ]
                },
                {
                    prop: 'question1',
                    label: '监测点有问题数量',
                    children: [
                        { prop: 'measurementFieldNull', label: '必填字段为空', width: 120 },
                        {
                            prop: 'measurementNameAbnormal',
                            label: '名称不规范',
                            width: 120
                        },
                        {
                            prop: 'measurementTypeAbnormal',
                            label: '监测对象名称不规范',
                            width: 150
                        },
                        {
                            prop: 'measurementCapacityError',
                            label: '填写容量不正确',
                            width: 120
                        },
                        {
                            prop: 'measurementDevNotMatch',
                            label: '监测点与终端不匹配',
                            width: 150
                        },
                        {
                            prop: 'measurementTypeError',
                            label: '监测点监测对象类型不准确',
                            width: 190
                        },
                        {
                            prop: 'tractionStationMeasurementRedundancy',
                            label: '牵引站监测点冗余',
                            width: 140
                        },
                        {
                            prop: 'tractionStationMeasurementMissing',
                            label: '牵引站信息缺失',
                            width: 120
                        }, //
                        {
                            prop: 'railwayCapacityError',
                            label: '电气化铁路监测点容量填写不正确',
                            width: 240
                        }
                    ]
                }
            ],
            ledgerdataData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.form.id = JSON.parse(window.sessionStorage.getItem('Info')).deptId
    },
    mounted() {
        this.ledgerdata()
        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
        },
        //获取主网运行指标统计数据
        ledgerdata() {
            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]
            getPwQualityCheckOfAccountData(this.form).then(res => {
                this.isLoading = false
                this.ledgerdataData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            //console.log(data);
            this.form.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.ledgerdata()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.ledgerdata()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
        },
        //导出
        exportEvent() {
            this.$refs.Ledgerdata.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>
