<template>
    <div class='container'>
        <div class='handle-box'>
            <el-form :inline='true'>
                <el-form-item>
                    <el-input
                        v-model='searchForm.title'
                        placeholder='请输入故障标题'
                        clearable>
                    </el-input>
                </el-form-item>

                <el-form-item>
                    <el-button @click='loadData'>搜索</el-button>
                </el-form-item>

                <el-form-item>
                    <el-button type='primary' @click='dialogVisible = true' v-if="hasAuth('sys:user:save')">新增
                    </el-button>
                </el-form-item>
            </el-form>
        </div>

        <el-table
            ref='noticeTable'
            :data='tableData'
            tooltip-effect='dark'
            style='width: 100%'
            border
            stripe>

            <el-table-column
                type='index'
                label='序号'
                width='50'>
            </el-table-column>

            <el-table-column
                prop='title'
                label='故障标题'
                :show-overflow-tooltip='true'>
            </el-table-column>

            <el-table-column
                prop='content'
                label='故障内容'
                :show-overflow-tooltip='true'>
            </el-table-column>

            <el-table-column
                prop='status'
                align='center'
                label='故障状态'>
                <template slot-scope='scope'>
                    <el-tag size='small' v-if='scope.row.status == 10' type='info'>未处理</el-tag>
                    <el-tag size='small' v-else-if='scope.row.status == 20' type='success'>已处理</el-tag>
                </template>
            </el-table-column>

            <el-table-column
                prop='proposePersonnel'
                align='center'
                label='提出人员'>
            </el-table-column>

            <el-table-column
                prop='treatmentMethod'
                label='处理方式'
                :show-overflow-tooltip='true'>
            </el-table-column>

            <el-table-column
                prop='treatmentPersonnel'
                align='center'
                label='处理人员'
                :show-overflow-tooltip='true'>
            </el-table-column>

            <el-table-column
                prop='createTime'
                width="150"
                label='提出时间'>
            </el-table-column>

            <el-table-column
                prop='updateTime'
                width="150"
                label='处理时间'>
            </el-table-column>

            <el-table-column
                prop='icon'
                width='180px'
                fixed='right'
                label='操作'>
                <template slot-scope='scope'>
                    <span v-if='scope.row.status==10'>
                        <el-button type='text' @click='editHandle(scope.row)'>处理</el-button>
                        <el-divider direction='vertical'></el-divider>
                    </span>
                    <template>
                        <el-popconfirm title='确定删除这条数据吗？' @confirm='delHandle(scope.row.id)'>
                            <el-button type='text' slot='reference'>删除</el-button>
                        </el-popconfirm>
                    </template>
                </template>
            </el-table-column>

        </el-table>

        <el-pagination
            @size-change='handleSizeChange'
            @current-change='handleCurrentChange'
            layout='total, sizes, prev, pager, next, jumper'
            :page-sizes='[10, 20, 50, 100]'
            :current-page='current'
            :page-size='size'
            :total='total'>
        </el-pagination>


        <!--新增对话框-->
        <el-dialog
            title='提示'
            :visible.sync='dialogVisible'
            width='60%'
            :before-close='handleClose'>

            <el-form :model='editForm' :rules='editFormRules' ref='editForm'>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item label='故障标题:' prop='title' label-width='100px'>
                            <el-input :disabled='editForm.id' v-model='editForm.title' autocomplete='off' placeholder='请输入故障标题'></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='提出人员:' prop='proposePersonnel' label-width='100px'>
                            <el-input :disabled='editForm.id' v-model='editForm.proposePersonnel' autocomplete='off'
                                      placeholder='请输入提出人员'></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='24'>
                        <el-form-item label='故障内容:' prop='content' label-width='100px'>
                            <el-input :disabled='editForm.id' type='textarea' rows='3' v-model='editForm.content' autocomplete='off'
                                      placeholder='请输入故障内容'></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='24'>
                        <el-form-item label='处理方式:' prop='treatmentMethod' label-width='100px'>
                            <el-input :disabled='!editForm.id' type='textarea' rows='3' v-model='editForm.treatmentMethod' autocomplete='off'
                                      placeholder='请输入处理方式'></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='12'>
                        <el-form-item label='处理人员:' prop='treatmentPersonnel' label-width='100px'>
                            <el-input :disabled='!editForm.id' v-model='editForm.treatmentPersonnel' autocomplete='off'
                                      placeholder='请输入处理人员'></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span='12'>
                        <el-form-item label='处理时间:' prop='updateTime' label-width='100px'>
                            <el-date-picker
                                :disabled='!editForm.id'
                                v-model='editForm.updateTime'
                                type='datetime'
                                value-format='yyyy-MM-dd HH:mm'
                                placeholder='请选择处理时间'>
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot='footer' class='dialog-footer'>
                <el-button @click="resetForm('editForm')">取 消</el-button>
                <el-button type='primary' @click="submitForm('editForm')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>

export default {
    name: 'faultHandlingManage',
    data() {
        return {
            searchForm: {
                title: ''
            },
            delBtlStatu: true,
            total: 0,
            size: 10,
            current: 1,
            dialogVisible: false,
            editForm: {
                title: '',
                content: ''
            },
            tableData: [],
            editFormRules: {
                title: [
                    { required: true, message: '请输入公告标题', trigger: 'blur' }
                ],
                content: [
                    { required: true, message: '请输入公告内容', trigger: 'blur' }
                ],
                proposePersonnel: [
                    { required: true, message: '请输入提出人员', trigger: 'blur' }
                ]
            }
        };
    },
    created() {
        this.loadData();
    },
    methods: {
        loadData() {
            this.$axios.get('/api/fault/handling/record/list', {
                params: {
                    title: this.searchForm.title,
                    current: this.current,
                    size: this.size
                }
            }).then(res => {
                this.tableData = res.data.data.records;
                this.size = res.data.data.size;
                this.current = res.data.data.current;
                this.total = res.data.data.total;
            });
        },
        handleClose() {
            this.resetForm('editForm');
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
            this.editForm = {};
        },
        submitForm(formName) {
            let _this = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    _this.$axios.post('/api/fault/handling/record/' + (_this.editForm.id ? 'updateBean' : 'addBean'), _this.editForm)
                        .then(res => {
                            _this.loadData();
                            _this.$notify({
                                showClose: true,
                                message: '恭喜你，操作成功',
                                type: 'success'
                            });
                            _this.resetForm(formName);
                        });
                } else {
                    return false;
                }
            });
        },
        editHandle(row) {
            this.editForm = JSON.parse(JSON.stringify(row));
            this.dialogVisible = true;
        },
        delHandle(id) {
            this.$axios.post('/api/fault/handling/record/deleteById?id=' + id).then(res => {
                this.$notify({
                    showClose: true,
                    message: '恭喜你，操作成功',
                    type: 'success'
                });
                this.loadData();
            });
        },
        handleSizeChange(val) {
            this.size = val;
            this.loadData();
        },
        handleCurrentChange(val) {
            this.current = val;
            this.loadData();
        }
    }
};
</script>

<style scoped>

</style>
