Form.vue
12 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<template>
<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll append-to-body width="600px">
<!-- 调试信息:isDetail = {{ isDetail }}, disabled = {{ isDetail === true }} -->
<el-row :gutter="15" class="" >
<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="formDisabled" :rules="rules">
<el-col :span="24">
<el-form-item label="设备名称" prop="keyword">
<el-input v-model="dataForm.keyword" placeholder="自动填充" clearable :disabled="true" :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="故障代码" prop="code">
<el-input v-model="dataForm.code" placeholder="请输入" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="报警文本" prop="zwbjwb">
<el-input v-model="dataForm.zwbjwb" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="故障描述" prop="description">
<el-input v-model="dataForm.description" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发布时间" prop="fbsj">
<el-date-picker v-model="dataForm.fbsj" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
</el-date-picker>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备id" prop="sssb">
<el-select v-model="sssbValue" placeholder="请选择设备(设备编号)" clearable filterable :style='{"width":"100%"}' @change="handleSssbChange">
<el-option v-for="item in zlglOptions" :key="item.id" :label="(item.sbbh || '') + (item.zlm ? ' - ' + item.zlm : '')" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="故障图片" prop="gztp">
<NCC-UploadImg v-model="dataForm.gztp" :fileSize="1" sizeUnit="GB" :limit="9" >
</NCC-UploadImg>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="相关附件" prop="attachements">
<NCC-UploadFz v-model="dataForm.attachements" :fileSize="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
</NCC-UploadFz>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="严重程度" prop="yzdcd">
<el-select v-model="dataForm.yzdcd" placeholder="请选择严重程度" clearable :style='{"width":"100%"}' >
<el-option label="轻微" value="轻微" ></el-option>
<el-option label="一般" value="一般" ></el-option>
<el-option label="严重" value="严重" ></el-option>
</el-select>
</el-form-item>
</el-col>
<!-- 隐藏故障核对字段 -->
<!-- <el-col :span="24">
<el-form-item label="故障核对" prop="gzhd">
<el-input v-model="dataForm.gzhd" placeholder="请输入故障核对" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":6}' >
</el-input>
</el-form-item>
</el-col> -->
<el-col :span="24">
<el-form-item label="外部简单描述" prop="wbjdm">
<el-input v-model="dataForm.wbjdm" placeholder="请输入外部简单描述" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":6}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="故障原因" prop="gzyy">
<el-input v-model="dataForm.gzyy" placeholder="请输入故障原因" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":6}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="解决办法" prop="jjbf">
<el-input v-model="dataForm.jjbf" placeholder="请输入解决办法" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":6}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="分类" prop="fl">
<el-select v-model="dataForm.fl" placeholder="请选择" clearable :style='{"width":"100%"}' >
<el-option v-for="(item, index) in flOptions" :key="index" :label="item.label" :value="item.value" ></el-option>
</el-select>
</el-form-item>
</el-col>
<!-- 隐藏规格字段 -->
<!-- <el-col :span="24">
<el-form-item label="规格" prop="gg">
<el-input v-model="dataForm.gg" placeholder="请输入" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col> -->
<!-- 隐藏“图片”字段,仅保留“故障图片” -->
<!-- <el-col :span="24">
<el-form-item label="图片" prop="fj1">
<NCC-UploadImg v-model="dataForm.fj1" :fileSize="1" sizeUnit="GB" :limit="9" >
</NCC-UploadImg>
</el-form-item>
</el-col> -->
</el-form>
</el-row>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
import { previewDataInterface } from '@/api/systemData/dataInterface'
// 故障分类固定选项(与后端一致)
const GZCX_FL_OPTIONS = [
'机械故障', '电气故障', '液压故障', '气控故障', '操作不当', '维护不当', '意外事故', '安装相关', '其他原因'
].map(t => ({ label: t, value: t }))
export default {
components: {},
props: [],
data() {
return {
loading: false,
visible: false,
isDetail: false,
dataForm: {
id:'',
code:undefined,
keyword:undefined,
zwbjwb:undefined,
description:undefined,
fbsj:undefined,
fl:undefined,
gg:undefined,
fj1:[],
attachements:[],
gztp:[],
sssb:undefined,
sbmc:undefined,
yzdcd:undefined,
gzhd:undefined,
wbjdm:undefined,
gzyy:undefined,
jjbf:undefined,
},
rules: {
},
flOptions: GZCX_FL_OPTIONS,
zlglOptions: [], // 资料管理(设备)选项,用于设备id/设备名
sssbValue: '', // 设备选择值(zlgl.id)
}
},
computed: {
formDisabled() {
// 明确返回布尔值,确保表单禁用状态正确
const disabled = this.isDetail === true;
console.log('Gzcx Form computed formDisabled - isDetail:', this.isDetail, 'disabled:', disabled);
return disabled;
}
},
watch: {
visible(val) {
if (val) {
// 对话框打开时,强制确保 isDetail 为 false(除非是详情模式)
console.log('Gzcx Form visible changed to true, current isDetail:', this.isDetail);
if (this.isDetail !== true) {
this.isDetail = false;
}
} else {
// 对话框关闭时,重置 isDetail 为 false
this.isDetail = false;
console.log('Gzcx Form visible changed to false, reset isDetail to false');
}
}
},
created() {
this.getZlglOptions();
},
mounted() {
},
methods: {
getZlglOptions() {
return request({
url: '/api/Extend/Zlgl',
method: 'GET',
data: { currentPage: 1, pageSize: 1000 }
}).then(res => {
this.zlglOptions = res.data.list || []
return Promise.resolve()
}).catch(err => {
console.error('获取资料管理(设备)列表失败:', err)
this.zlglOptions = []
return Promise.reject(err)
})
},
handleSssbChange(val) {
// 选择设备后,自动填充设备名称(资料名)
if (val) {
const zl = this.zlglOptions.find(item => item.id === val)
if (zl) {
this.dataForm.sssb = zl.id
this.dataForm.keyword = zl.zlm || zl.sbbh || ''
this.dataForm.sbmc = zl.zlm || ''
}
} else {
this.dataForm.sssb = ''
this.dataForm.keyword = ''
this.dataForm.sbmc = ''
}
},
goBack() {
this.$emit('refresh')
},
init(id, isDetail) {
console.log('Gzcx Form init called - id:', id, 'isDetail param:', isDetail);
// 强制重置 isDetail,确保表单可编辑
this.isDetail = false;
// 如果明确传入 isDetail 为 true,才设置为详情模式
if (isDetail === true) {
this.isDetail = true;
}
this.dataForm.id = id || 0;
console.log('Gzcx Form init - after setting, isDetail:', this.isDetail, 'type:', typeof this.isDetail);
// 直接设置 visible,不使用 $nextTick,避免时序问题
this.visible = true;
console.log('Gzcx Form visible set to true, isDetail:', this.isDetail);
// 初始化选择值
this.sssbValue = '';
this.$nextTick(() => {
this.$refs['elForm'].resetFields();
if (this.dataForm.id) {
request({
url: '/api/Extend/Gzcx/' + this.dataForm.id,
method: 'get'
}).then(res =>{
this.dataForm = res.data;
if(!this.dataForm.fj1)this.dataForm.fj1=[];
if(!this.dataForm.attachements)this.dataForm.attachements=[];
if(!this.dataForm.gztp)this.dataForm.gztp=[];
// 根据设备(资料管理)ID 回显选择
if (this.dataForm.sssb) {
if (this.zlglOptions.length === 0) {
this.getZlglOptions().then(() => {
const zl = this.zlglOptions.find(item => item.id === this.dataForm.sssb);
if (zl) this.sssbValue = zl.id;
});
} else {
const zl = this.zlglOptions.find(item => item.id === this.dataForm.sssb);
if (zl) this.sssbValue = zl.id;
}
}
})
} else {
// 新建时清空新字段
this.dataForm.sssb = '';
this.dataForm.sbmc = '';
this.dataForm.yzdcd = '';
this.dataForm.gzhd = '';
this.dataForm.wbjdm = '';
this.dataForm.zwbjwb = '';
this.dataForm.gzyy = '';
this.dataForm.jjbf = '';
}
})
},
dataFormSubmit() {
this.$refs['elForm'].validate((valid) => {
if (valid) {
if (!this.dataForm.id) {
request({
url: `/api/Extend/Gzcx`,
method: 'post',
data: this.dataForm,
}).then((res) => {
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false,
this.$emit('refresh', true)
}
})
})
} else {
request({
url: '/api/Extend/Gzcx/' + this.dataForm.id,
method: 'PUT',
data: this.dataForm
}).then((res) => {
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false
this.$emit('refresh', true)
}
})
})
}
}
})
},
}
}
</script>