lct
Your Name
2022-08-17 3c5ca2f8ce690f2c8808548e5ce5f69da296de10
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
<template>
    <div class="system-add-menu-container">
        <el-dialog :title="title" v-model="isShowSafetyActionDialog" width="600px" :close-on-click-modal="false">
            <el-form :model="safetyActionForm" :rules="safetyActionFormRules" ref="safetyActionFormRef" size="default" label-width="120px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="作业类型" prop="workType">
                            <el-select class="input-add" :disabled="!disabled" v-model="safetyActionForm.workType" placeholder="请选择作业类型" filterable clearable>
                                <el-option v-for="item in workTypeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="措施类型" prop="type">
                            <el-select class="input-add" :disabled="!disabled" v-model="safetyActionForm.type" placeholder="请选择措施类型" clearable filterable>
                                <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col v-if="safetyActionForm.type === 1" :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="正确值" prop="correctVal">
                            <el-select class="input-add" :disabled="!disabled" v-model="safetyActionForm.correctVal" placeholder="请选择正确值" clearable filterable>
                                <el-option v-for="item in typeTwoList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="措施内容" prop="context">
                            <el-input class="input-add" :rows="3" v-model.trim="safetyActionForm.context" type="textarea" placeholder="请输入描述"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-show="personTime">
                        <el-form-item label="创建人" prop="location">
                            <el-input class="input-add" :disabled="!disabled" v-model.trim="safetyActionForm.createUname"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-show="personTime">
                        <el-form-item label="创建时间" prop="location">
                            <el-input class="input-add" :disabled="!disabled" v-model.trim="safetyActionForm.gmtCreate"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-show="personTime">
                        <el-form-item label="最后修改人" prop="location">
                            <el-input class="input-add" :disabled="!disabled" v-model.trim="safetyActionForm.modifiedUname"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-show="personTime">
                        <el-form-item label="最后修改时间" prop="location">
                            <el-input class="input-add" :disabled="!disabled" v-model.trim="safetyActionForm.gmtModified"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer" v-show="disabled">
                    <el-button @click="isShowSafetyActionDialog = !isShowSafetyActionDialog" size="default">取 消</el-button>
                    <el-button type="primary" @click="submitSafetyAction" v-throttle size="default">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
interface stateType {
    isShowSafetyActionDialog: Boolean;
    disabled: Boolean;
    personTime: Boolean;
    safetyActionForm: {
        workType: number | null;
        type: number | null;
        correctVal: number | null;
        context: string | null;
    };
    title: string;
    departmentList: [];
    workTypeList: Array<levelListState>;
    typeList: Array<levelListState>;
    typeTwoList: Array<levelListState>;
    safetyActionFormRules: {};
}
interface levelListState {
    id: number;
    name: string;
}
 
import { reactive, toRefs, ref } from 'vue';
import { safetyActionApi } from '/@/api/specialWorkSystem/safetyAction';
import { ElMessage } from 'element-plus';
export default {
    name: 'SafetyActionDialog',
    setup(props: any, context: any) {
        const safetyActionFormRef = ref();
        const state = reactive<stateType>({
            title: '',
            disabled: false,
            personTime: false,
            departmentList: [],
            isShowSafetyActionDialog: false,
            workTypeList: [
                { id: 1, name: '动火作业' },
                { id: 2, name: '受限空间作业' },
                { id: 3, name: '吊装作业' },
                { id: 4, name: '动土作业' },
                { id: 5, name: '断路作业' },
                { id: 6, name: '高处作业' },
                { id: 7, name: '临时用电作业' },
                { id: 8, name: '盲板抽堵作业' }
            ],
            typeList: [
                { id: 1, name: '选择' },
                { id: 2, name: '填空' }
            ],
            typeTwoList: [
                { id: 1, name: '是' },
                { id: 2, name: '否' }
            ],
            safetyActionForm: {
                workType: null,
                type: null,
                correctVal: null,
                context: null
            },
            safetyActionFormRules: {
                workType: [{ required: true, message: '请选择作业类型', trigger: 'change' }],
                type: [{ required: true, message: '请选择措施类型', trigger: 'change' }],
                correctVal: [{ required: true, message: '请选择正确值', trigger: 'change' }],
                context: [{ required: true, message: '请填写措施内容', trigger: 'blur' }]
            }
        });
 
        //打开模态框
        const showSafetyActionDialog = (type: string, value: object, department: []) => {
            state.isShowSafetyActionDialog = true;
            state.departmentList = department;
            setTimeout(() => {
                safetyActionFormRef.value.clearValidate();
            });
            if (type === '新增') {
                state.disabled = true;
                state.personTime = false;
                state.title = '新增安全措施';
                state.safetyActionForm = {
                    workType: null,
                    type: null,
                    correctVal: null,
                    context: null
                };
            } else if (type === '查看') {
                state.disabled = false;
                state.personTime = true;
                state.title = '查看安全措施';
                state.safetyActionForm = JSON.parse(JSON.stringify(value));
            } else {
                state.disabled = true;
                state.personTime = false;
                state.title = '修改安全措施';
                state.safetyActionForm = JSON.parse(JSON.stringify(value));
                // for (let i in state.SafetyActionForm) {
                //     state.SafetyActionForm[i] = SafetyActionForm[i];
                // }
            }
        };
 
        //新增修改提交
        const submitSafetyAction = async () => {
            safetyActionFormRef.value.validate(async (valid: Boolean) => {
                if (valid) {
                    if (state.title === '新增安全措施') {
                        let res = await safetyActionApi().addSafetyAction(state.safetyActionForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '安全措施新增成功',
                                duration: 2000
                            });
                            state.isShowSafetyActionDialog = false;
                            context.emit('refreshSafetyAction');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    } else {
                        let res = await safetyActionApi().modSafetyAction(state.safetyActionForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '安全措施改成功',
                                duration: 2000
                            });
                            state.isShowSafetyActionDialog = false;
                            context.emit('refreshSafetyAction');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    }
                } else {
                    ElMessage({
                        type: 'warning',
                        message: '请完善基本信息'
                    });
                }
            });
        };
 
        return {
            ...toRefs(state),
            safetyActionFormRef,
            submitSafetyAction,
            showSafetyActionDialog
        };
    }
};
</script>
 
<style scoped></style>