Your Name
2023-02-24 5a72942254d0a4cae77c2980b014a5cf55a52cf9
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
<template>
    <div class="system-menu-dialog-container">
        <el-dialog :title="planDialogState.title" v-model="planDialogState.planDialogVisible" width="600px">
            <el-form ref="planFormRef" :rules="planDialogState.planFormRules" :model="planDialogState.planForm" 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="riskUnitId">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.riskUnitId" style="width:100%" placeholder="风险分析单元" clearable>
                                <el-option v-for="item in planDialogState.riskUnitList" :key="item.id" :label="item.riskName" :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="assessPlanName">
                            <el-input :disabled="planDialogState.disabled" v-model="planDialogState.planForm.assessPlanName" placeholder="评估计划名称" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="计划制定人" prop="planUserId">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.planUserId" style="width:100%"  placeholder="计划制定人" clearable>
                                <el-option v-for="item in planDialogState.personList" :key="item.id" :label="item.realName" :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="assessPlanName">
                            <el-date-picker
                                :disabled="planDialogState.disabled"
                                type="datetimerange"
                                v-model="planDialogState.time"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                format="YYYY-MM-DD HH:mm:ss"
                                value-format="YYYY-MM-DD HH:mm:ss"
                                @change="formatTime">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="辨识方法" prop="identificationMethod">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.identificationMethod" style="width:100%" placeholder="辨识方法" clearable>
                                <el-option v-for="item in planDialogState.identificationMethodList" :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="identificationUserId">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.identificationUserId" style="width:100%"  placeholder="负责人" clearable>
                                <el-option v-for="item in planDialogState.personList" :key="item.id" :label="item.realName" :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="evaluateMethod">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.evaluateMethod" style="width:100%"  placeholder="推荐评价方法" clearable>
                                <el-option v-for="item in planDialogState.evaluateMethodList" :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="evaluateUserId">
                            <el-select :disabled="planDialogState.disabled" v-model="planDialogState.planForm.evaluateUserId" style="width:100%"  placeholder="评价专家" clearable>
                                <el-option v-for="item in planDialogState.personList" :key="item.id" :label="item.realName" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="planDialogState.planDialogVisible = !planDialogState.planDialogVisible" size="default">取 消</el-button>
                    <el-button v-if="!planDialogState.disabled" type="primary" @click="onSubmitPlan" size="default">确定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import { reactive, ref } from "vue";
import {ElMessage} from "element-plus";
import {planApi} from "/@/api/analyse/plan";
import {isValidKey} from "/@/utils/methods";
 
const planFormRef = ref()
 
const planDialogState = reactive<PlanDialogType>({
    title: '',
    time:[],
    disabled: false,
    planDialogVisible: false,
    planForm: {
        riskUnitId: null,
        planUserId: null,
        assessPlanName: '',
        assessStartTime: '',
        assessEndTime: '',
        identificationMethod: null,
        identificationUserId: null,
        evaluateMethod: null,
        evaluateUserId: null,
    },
    planFormRules: {
        deviceCode: [{ required: true, message: '请填写设备编号', trigger: 'blur' }],
        deviceName: [{ required: true, message: '请填写设备名称', trigger: 'blur' }],
        devicePower: [{ required: true, message: '请填写设备功率', trigger: 'blur' }],
        riskUnitId: [{ required: true, message: '请选择风险分析单元', trigger: 'change' }],
        planUserId: [{ required: true, message: '请选择计划制定人', trigger: 'change' }],
        identificationMethod: [{ required: true, message: '请选择辨识方法', trigger: 'change' }],
        identificationUserId: [{ required: true, message: '请选择负责人', trigger: 'change' }],
        evaluateMethod: [{ required: true, message: '请选择推荐评价方法', trigger: 'change' }],
        evaluateUserId: [{ required: true, message: '请选择评价专家', trigger: 'change' }],
    },
    riskUnitList: [],
    personList: [],
    identificationMethodList: [
        {id:1, name: 'PHA'},
        {id:2, name: 'JHA'},
        {id:3, name: 'SCL'},
        {id:4, name: 'HAZOP'},
        {id:5, name: '类比法'},
    ],
    evaluateMethodList: [
        {id:1, name: 'LEC'},
        {id:2, name: 'LS'},
        {id:3, name: 'MES'},
        {id:4, name: 'RS'},
    ]
})
 
const showPlanDialog = (title: string, value: PlanType, riskUnitList: RiskUnitType [], personList: SystemPersonType []) => {
    planDialogState.planDialogVisible = true;
    planDialogState.riskUnitList = riskUnitList;
    planDialogState.personList = personList;
    planDialogState.disabled = false
    setTimeout(() => {
        planFormRef.value.clearValidate();
    });
    if(title === '新增'){
        planDialogState.title = '新增';
        planDialogState.planForm = {
            riskUnitId: null,
            planUserId: null,
            assessPlanName: '',
            assessStartTime: '',
            assessEndTime: '',
            identificationMethod: null,
            identificationUserId: null,
            evaluateMethod: null,
            evaluateUserId: null,
        };
    }else if(title === '查看'){
        planDialogState.title = '查看';
        planDialogState.disabled = true
        planDialogState.time = [value.assessStartTime, value.assessEndTime]
        for(let i in planDialogState.planForm){
            if(isValidKey(i, planDialogState.planForm)){
                planDialogState.planForm[i] = value[i]
            }
        }
    }else{
        planDialogState.title = '编辑';
        planDialogState.planForm.id = value.id
        planDialogState.time = [value.assessStartTime, value.assessEndTime]
        for(let i in planDialogState.planForm){
            if(isValidKey(i, planDialogState.planForm)){
                planDialogState.planForm[i] = value[i]
            }
        }
    }
};
 
const formatTime = () => {
    planDialogState.planForm.assessStartTime = planDialogState.time === null ? '' : planDialogState.time[0]
    planDialogState.planForm.assessEndTime = planDialogState.time === null ? '' : planDialogState.time[1]
};
 
const onSubmitPlan = () => {
    planFormRef.value.validate(async(valid: boolean) => {
        if(valid){
            if(planDialogState.title === '新增'){
                let res = await planApi().addPlan(planDialogState.planForm);
                if(res.data.code === 100){
                    emit('refresh')
                    planDialogState.planDialogVisible = false;
                    ElMessage({
                        type: 'success',
                        message: '新增成功'
                    })
                }else{
                    ElMessage({
                        type: 'warning',
                        message: res.data.msg,
                    });
                }
            }else{
                let res = await planApi().modPlan(planDialogState.planForm)
                if(res.data.code === 100){
                    emit('refresh')
                    planDialogState.planDialogVisible = false;
                    ElMessage({
                        type: 'success',
                        message: '编辑成功'
                    })
                }else{
                    ElMessage({
                        type: 'warning',
                        message: res.data.msg,
                    });
                }
            }
        }else{
            ElMessage({
                type: 'warning',
                message: '请完善基本信息',
            });
        }
    })
}
 
const emit = defineEmits(['refresh'])
 
defineExpose({
    showPlanDialog
})
</script>
 
<style scoped>
 
</style>