<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 @time="time"></Timeinterval>
            </el-form-item>

            <el-form-item label="生产厂家:">
                <el-select v-model="manufacturer" placeholder="请选择生产厂家">
                    <el-option
                        v-for="item in manufacturerData"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </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="detailsData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                    :height="height"
                    border
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                    :cell-style="cellStyle"
                >
                    <template v-for="(item, index) in tableHeaderDetails">
                        <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="detailsData.length"
                    class="mt10"
                ></el-pagination>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import { dicData } from '@/assets/commjs/dictypeData'
import Area from '@/views/components/Area/Area.vue'
import Timeinterval from './Timeslot.vue'
import { getRMpDevSolveDetailList } from '@/api/Management-operation/mochaITOM'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            kai: true,
            start: '',
            end: '',
            id: JSON.parse(window.sessionStorage.getItem('Info')).deptId,
            vh: '',
            height: null,
            isLoading: false,
            name: '', //终端名称
            manufacturer: '', //生产厂家
            //生产厂家数据
            manufacturerData: [],

            tableHeaderDetails: [
                { prop: 'orgName', label: '单位' },
                { prop: 'powerName', label: '变电站' },
                { prop: 'deviceId', label: '终端编号' },

                { prop: 'breakDownDate', label: '故障时间' },
                { prop: 'breakDownType', label: '故障类型' },
                { prop: 'isSolve', label: '是否消缺' },
                { prop: 'solveDate', label: '消缺时间' }
            ],
            detailsData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.manufacturerData = dicData('Dev_Manufacturers', [], 1)
        this.manufacturerData1 = dicData('Break_Down_Type', [], 1)
    },
    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') - 215
        },
        time(val) {
            ;(this.start = val[0]), (this.end = val[1])
            this.type = val[2]
            if (this.kai) {
                this.details()
            }
        },
        //获取主网运行指标统计数据
        details() {
            this.kai = false
            this.isLoading = true
            getRMpDevSolveDetailList({
                endTime: this.end,
                id: this.id,
                manufactureIds: this.manufacturer,
                startTime: this.start,
                type: ''
            }).then(res => {
                this.isLoading = false
                this.detailsData = res.data
                res.data.forEach(e => {
                    if (e.isSolve == 0) {
                        e.isSolve = '未消缺'
                    } else {
                        e.isSolve = '已消缺'
                    }
                    this.manufacturerData1.forEach(i => {
                        if (i.id == e.breakDownType) {
                            e.breakDownType = i.name
                        }
                    })
                })
            })
        },
        // 切换选项
        handleNodeClick(data) {
            this.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.details()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.details()
        },
        //查询
        researchFn() {
            this.details()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
            this.manufacturer = 0
        },
        cellStyle(row) {
            // console.log(row);
            if (row.columnIndex == 6) {
                if (row.row.eliminateDefects == 0) {
                    row.row.eliminateDefects = '是'
                } else if (row.row.eliminateDefects == 1) {
                    row.row.eliminateDefects = '否'
                }
            }
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../../styles/comStyle.less');
</style>
