<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 label="终端名称:" class="name">
                <el-input v-model="name" placeholder="请输入内容"></el-input>
            </el-form-item>

            <el-form-item label="设备状态:" class="status">
                <el-select v-model="equipmentStatus" placeholder="请选择">
                    <el-option
                        v-for="item in equipmentStatusData"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="运行状态:" class="state">
                <el-select v-model="runningState" placeholder="请选择">
                    <el-option
                        v-for="item in runningStateData"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="缺陷类型:" class="type">
                <el-select v-model="defectType" placeholder="请选择">
                    <el-option
                        v-for="item in defectTypeData"
                        :key="item.id"
                        :label="item.label"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </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" @click="registerFn">缺陷登记</el-button>
                </div>
                <el-table
                    stripe
                    :data="exceptionlistData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                    :height="height"
                    border
                    style="width: 100%"
                    v-loading="isLoading"
                    header-cell-class-name="table_header"
                    :row-class-name="rowClassName"
                >
                    <template v-for="(item, index) in tableHeaderExceptionlist">
                        <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="exceptionlistData.length"
                    class="mt10"
                ></el-pagination>

                <el-dialog
                    :close-on-click-modal="false"
                    title="缺陷登记"
                    v-if="register"
                    :visible.sync="register"
                    width="40%"
                    height="80%"
                >
                    <el-form :inline="true" :model="dataForm" class="demo-form-inline form" label-width="110px">
                        <el-form-item label="单位:" style="margin-top: 15px">
                            <el-input v-model="dataForm.company" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="终端编号:" style="margin-top: 15px">
                            <el-input v-model="dataForm.terminalNo" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="终端名称:" style="margin-top: 15px">
                            <el-input v-model="dataForm.name" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="缺陷类型:" style="margin-top: 15px">
                            <el-input v-model="dataForm.type" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="缺陷处理时间:" style="margin-top: 15px">
                            <el-date-picker v-model="dataForm.time" type="date" placeholder="选择日期"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="异常处理人:" style="margin-top: 15px">
                            <el-input v-model="dataForm.handler" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="缺陷登记时间:" style="margin-top: 15px">
                            <el-date-picker
                                v-model="dataForm.time1"
                                type="date"
                                placeholder="选择日期"
                            ></el-date-picker>
                        </el-form-item>
                        <el-form-item label="异常原因:" style="margin-top: 15px">
                            <el-input
                                type="textarea"
                                v-model="dataForm.cause"
                                placeholder=""
                                maxlength="100"
                                show-word-limit
                            ></el-input>
                        </el-form-item>
                    </el-form>
                    <span slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="register = false">取 消</el-button>
                        <el-button type="primary" @click="determineFn">确 定</el-button>
                    </span>
                </el-dialog>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Area from '@/views/components/Area/Area.vue'
import Timeinterval from '../../../components/Timeinterval.vue'
import { getExceptionlistData } from '@/api/Management-operation/mochaITOM'
export default {
    components: { Area, Timeinterval },
    data() {
        return {
            vh: '',
            height: null,
            isLoading: false,
            register: false,
            name: '', //终端名称
            equipmentStatus: 1, //设备状态
            runningState: 1, //运行状态
            defectType: 0, //缺陷类型
            //设备状态数据
            equipmentStatusData: [
                {
                    id: 0,
                    value: '选项1',
                    label: '全部'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '在运设备'
                },
                {
                    id: 2,
                    value: '选项3',
                    label: '停运设备'
                },
                {
                    id: 3,
                    value: '选项4',
                    label: '热备用'
                }
            ],
            //在线状态数据
            runningStateData: [
                {
                    id: 0,
                    value: '选项1',
                    label: '全部'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '在线'
                },
                {
                    id: 2,
                    value: '选项3',
                    label: '离线'
                }
            ],
            //缺陷类型数据
            defectTypeData: [
                {
                    id: 0,
                    value: '选项1',
                    label: '全部'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '缺陷一'
                },
                {
                    id: 2,
                    value: '选项3',
                    label: '缺陷二'
                }
            ],

            tableHeaderExceptionlist: [
                { prop: 'number', label: '序号' },
                { prop: 'company', label: '单位' },
                { prop: 'terminalNo', label: '终端编号', width: 180 },
                { prop: 'equipmentStatus', label: '设备状态' },
                { prop: 'runningState', label: '运行状态' },
                { prop: 'name', label: '终端名称' },
                { prop: 'type', label: '缺陷类型' },
                { prop: 'occurrenceTime', label: '缺陷发生时间' },
                { prop: 'processingTime', label: '缺陷处理时间' },
                { prop: 'handler', label: '缺陷处理人' },
                { prop: 'cause', label: '异常原因' }
            ],
            exceptionlistData: [],
            dataForm: {
                company: '',
                terminalNo: '',
                name: '',
                type: '',
                time: '',
                handler: '',
                time1: '',
                cause: ''
            },
            device: '',
            currentPage: 1, // 当前页码
            total: 20, // 总条数
            pageSize: 18 // 每页的数据条数
        }
    },
    created() {
        this.exceptionlist()
    },
    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') - 205
        },
        rowClassName({ row, rowIndex }) {
            row.number = rowIndex + 1
        },
        //获取主网运行指标统计数据
        exceptionlist() {
            this.isLoading = true
            getExceptionlistData().then(res => {
                this.isLoading = false
                this.exceptionlistData = res.data
            })
        },
        //缺陷登记
        registerFn() {
            this.register = true
        },
        //确定
        determineFn() {
            this.register = false
        },
        // 切换选项
        handleNodeClick(data) {
            // console.log(data);
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val
            this.exceptionlist()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.currentPage = val
            this.exceptionlist()
        },
        //查询
        researchFn() {
            this.exceptionlist()
        },
        //重置
        Reset() {
            this.$refs.area.form.valueTitle = '全国'
            this.$refs.interval.intervald = 1
            this.name = ''
            this.equipmentStatus = 1
            this.runningState = 1
            this.defectType = 0
        }
    }
}
</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;
}

::v-deep .area {
    .el-input {
        width: 120px;
    }
}
::v-deep .status {
    .el-input {
        width: 110px;
    }
}
::v-deep .name {
    .el-input {
        width: 100px;
    }
}
::v-deep .state,
::v-deep .type {
    .el-input {
        width: 80px;
    }
}
::v-deep .form {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-form-item {
        display: flex;
        width: 48%;
        .el-form-item__content {
            flex: 1 !important;
            .el-select {
                width: 100%;
            }
            .el-input__inner {
                width: 100% !important;
            }
            .el-date-editor {
                width: 100%;
            }
        }
    }
}
.button {
    float: right;
    margin-right: 5px;
}
</style>
