<template>
    <div>
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="故障类型:">
                <el-select v-model="manufacture" placeholder="请选择故障类型">
                    <el-option
                        v-for="item in manufactureId"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <Timeinterval @time="time"></Timeinterval>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" class="ml10" icon="el-icon-search" @click="researchFn">查询</el-button>
            </el-form-item>
        </el-form>

        <el-row>
            <el-col :span="24">
                <el-table
                    stripe
                    :data="companyData.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 tableHeaderCompany">
                        <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="companyData.length"
                    class="mt10"
                ></el-pagination>
            </el-col>
            <el-col :span="24" :style="`height:${vh}`">
                <CompanyEcharts ref="CompanyEcharts" :fa-msg="companyData"></CompanyEcharts>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import { dicData } from '@/assets/commjs/dictypeData'
import Timeinterval from './Timeslot.vue'
import Area from '@/views/components/Area/Area.vue'
import CompanyEcharts from './echarts/FaulttypeEcharts.vue'
import { getTypeRMpDevSolveList } from '@/api/Management-operation/mochaITOM'
export default {
    components: { Area, Timeinterval, CompanyEcharts },
    data() {
        return {
            kai: true,
            start: '',
            end: '',
            id: JSON.parse(window.sessionStorage.getItem('Info')).deptId,
            vh: '',
            height: null,
            isLoading: false,
            tableHeaderCompany: [
                { prop: 'breakDownType', label: '故障类型' },
                { prop: 'dataDate', label: '时间' },

                { prop: 'terminalAbnormalCount', label: '终端异常数量' },
                { prop: 'solveCount', label: '已消缺异常数量' },
                { prop: 'solveRate', label: '消缺率' }
            ],
            companyData: [],
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18, // 每页的数据条数
            manufactureId: '',
            manufacture: ''
        }
    },
    created() {
        this.manufactureId = dicData('Break_Down_Type', [], 1)
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.height = (window.sessionStorage.getItem('appheight') - 280) / 2
            this.vh = window.sessionStorage.getItem('appheight') / 2 - 75 + 'px'
        },
        time(val) {
            ;(this.start = val[0]), (this.end = val[1])
            this.type = val[2]
            if (this.kai) {
                this.company()
            }
        },
        //获取主网运行指标统计数据
        company() {
            this.kai = false
            this.isLoading = true
            getTypeRMpDevSolveList({
                endTime: this.end,
                startTime: this.start,
                breakDownType: this.manufacture,
                id: this.id,
                manufactureIds: ''
            }).then(res => {
                this.isLoading = false
                res.data.forEach(e => {
                    this.manufactureId.forEach(i => {
                        if (i.id == e.breakDownType) {
                            e.breakDownType = i.name
                        }
                    })
                })
                this.companyData = res.data
            })
        },
        // 切换选项
        handleNodeClick(data) {
            this.id = data.id
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.company()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.company()
        },
        //查询
        researchFn() {
            this.company()
            this.$refs.CompanyEcharts.province()
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../../styles/comStyle.less');
</style>
