lct
Your Name
2022-08-12 965f7a2479a2cf7c1c56fb298e7fbb855c89e212
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<template>
    <div class="system-add-menu-container">
        <el-dialog :title="title" v-model="isShowCheckUnitDialog" append-to-body :close-on-click-modal="false" width="50%">
            <el-divider></el-divider>
            <div class="checkUnit-form">
                <el-form :model="checkUnitForm" :rules="checkUnitFormRules" ref="checkUnitFormRef" size="default" label-width="120px">
                    <el-row :gutter="35">
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20">
                            <el-form-item label="任务单元名称" prop="taskUnitName">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.taskUnitName" placeholder="请输入任务单元名称" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20">
                            <el-form-item label="任务单元说明" prop="note">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.note" placeholder="请输入任务单元说明" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20" v-show="personTime">
                            <el-form-item label="创建人" prop="location">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.createByUserName" placeholder="请输入区域位置"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20" v-show="personTime">
                            <el-form-item label="创建时间" prop="location">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.gmtCreate" placeholder="请输入区域位置"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20" v-show="personTime">
                            <el-form-item label="最后修改人" prop="location">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.lastEditUserName" placeholder="请输入区域位置"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="12" class="mb20" v-show="personTime">
                            <el-form-item label="最后修改时间" prop="location">
                                <el-input class="input-add" :disabled="!disabled" v-model.trim="checkUnitForm.gmtModitify" placeholder="请输入区域位置"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
 
            <div class="checkUnit-point">
                <el-tabs class="active" v-model="activeName">
                    <el-tab-pane label="检查项信息" name="checkUnit">
                        <div class="filter-container">
                            <el-button size="default" :disabled="!disabled" type="success" @click="onOpenDialogRef('新增', '')">
                                <el-icon>
                                    <ele-FolderAdd />
                                </el-icon>
                                选择风险管控措施
                            </el-button>
                        </div>
 
                        <el-table :data="measureData" border fit highlight-current-row style="width: 100%">
                            <el-table-column type="index" label="序号" width="60" />
                            <el-table-column prop="checkContent" label="管控内容" show-overflow-tooltip align="center"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template #default="scope">
                                    <el-button size="small" text :disabled="!disabled" type="danger" @click="onDelCheckUnit(scope.$index, scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                </el-tabs>
            </div>
 
            <template #footer>
                <span class="dialog-footer" v-show="disabled">
                    <el-button @click="isShowCheckUnitDialog = !isShowCheckUnitDialog" size="default">取 消</el-button>
                    <el-button type="primary" @click="submitCheckUnit" v-throttle size="default">确 定</el-button>
                </span>
            </template>
        </el-dialog>
        <el-dialog title="选择风险管控措施" v-model="isShowSelectMeasureControlDialog" append-to-body :close-on-click-modal="false" width="70%">
            <select-measure-control-dialog ref="SelectMeasureControlDialogRef" @receiveRiskControlId="receiveRiskControlId"></select-measure-control-dialog>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
import SelectMeasureControlDialog from '/@/views/doublePrevent/riskLevel/riskCheckUnit/components/selectMeasureControlDialog.vue';
import { reactive, toRefs, ref } from 'vue';
import { checkUnitApi } from '/@/api/doublePreventSystem/checkUnit';
import { ElMessage } from 'element-plus';
interface stateType {
    isShowCheckUnitDialog: Boolean;
    disabled: Boolean;
    personTime: Boolean;
    isShowSelectMeasureControlDialog: Boolean;
    checkUnitForm: {
        taskUnitName: string | null;
        note: string | null;
        measureList: [];
    };
    title: string;
    activeName: string;
    measureData: [];
    checkUnitData: [];
    checkUnitFormRules: {};
}
 
export default {
    name: 'checkUnitDialog',
    components: { SelectMeasureControlDialog },
    setup(props: any, context: any) {
        const checkUnitFormRef = ref();
        const riskControlMeasureDialogRef = ref();
        const state = reactive<stateType>({
            title: '',
            disabled: false,
            personTime: false,
            activeName: 'checkUnit',
            measureData: [],
            checkUnitData: [],
            isShowCheckUnitDialog: false,
            isShowSelectMeasureControlDialog: false,
            checkUnitForm: {
                taskUnitName: null,
                note: null,
                measureList: []
            },
            checkUnitFormRules: {
                taskUnitName: [{ required: true, message: '请填写任务单元名称', trigger: 'blur' }],
                note: [{ required: true, message: '请填写任务单元说明', trigger: 'change' }]
            }
        });
 
        //打开模态框
        const openCheckUnitDialog = (type: string, value: object) => {
            state.isShowCheckUnitDialog = true;
            setTimeout(() => {
                checkUnitFormRef.value.clearValidate();
            });
            if (type === '新增') {
                state.disabled = true;
                state.personTime = false;
                state.title = '新增隐患排查单元';
                state.measureData = [];
                state.checkUnitForm = {
                    taskUnitName: null,
                    note: null,
                    measureList: []
                };
            } else if (type === '查看') {
                state.disabled = false;
                state.personTime = true;
                state.title = '查看隐患排查单元';
                state.checkUnitForm = JSON.parse(JSON.stringify(value));
                state.measureData = state.checkUnitForm.measureList;
            } else {
                state.disabled = true;
                state.personTime = false;
                state.title = '修改隐患排查单元';
                state.checkUnitForm = JSON.parse(JSON.stringify(value));
                state.measureData = state.checkUnitForm.measureList;
            }
        };
 
        const onOpenDialogRef = () => {
            state.isShowSelectMeasureControlDialog = true;
        };
 
        const onDelCheckUnit = (value: number, scope: object) => {
            state.measureData.splice(value, 1);
        };
 
        const receiveRiskControlId = (value: []) => {
            state.isShowSelectMeasureControlDialog = false;
            state.measureData = value;
            state.checkUnitForm.measureList = JSON.parse(
                JSON.stringify(
                    value.map((item: { id: number }) => {
                        return item.id;
                    })
                )
            );
        };
 
        //新增修改提交
        const submitCheckUnit = async () => {
            checkUnitFormRef.value.validate(async (valid: Boolean) => {
                if (valid) {
                    if (state.title === '新增隐患排查单元') {
                        let res = await checkUnitApi().addCheckUnit(state.checkUnitForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '隐患排查单元新增成功',
                                duration: 2000
                            });
                            state.isShowCheckUnitDialog = false;
                            context.emit('refreshCheckUnit');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    } else {
                        let res = await checkUnitApi().modCheckUnit(state.checkUnitForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '隐患排查单元修改成功',
                                duration: 2000
                            });
                            state.isShowCheckUnitDialog = false;
                            context.emit('refreshCheckUnit');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    }
                } else {
                    ElMessage({
                        type: 'warning',
                        message: '请完善基本信息'
                    });
                }
            });
        };
 
        return {
            ...toRefs(state),
            checkUnitFormRef,
            submitCheckUnit,
            onDelCheckUnit,
            onOpenDialogRef,
            openCheckUnitDialog,
            receiveRiskControlId,
            riskControlMeasureDialogRef
        };
    }
};
</script>
 
<style scoped>
::v-deep.el-divider--horizontal {
    margin-top: 0px !important;
}
 
::v-deep.el-dialog__body {
    padding-top: 10px !important;
}
.filter-container {
    padding: 10px 0px;
}
:deep(.el-textarea.is-disabled .el-textarea__inner) {
    background-color: var(--el-card-bg-color);
    color: var(--el-input-text-color, var(--el-text-color-regular));
}
:deep(.el-input.is-disabled .el-input__inner) {
    color: var(--el-input-text-color, var(--el-text-color-regular));
}
:deep(.el-input.is-disabled .el-input__wrapper) {
    background-color: var(--el-card-bg-color);
}
</style>