Form.vue
17.3 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<template>
<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px">
<el-row :gutter="15" class="" >
<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
<el-col :span="24" v-if="false" >
<el-form-item label="编号" prop="id">
<el-input v-model="dataForm.id" placeholder="请输入" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="关联产品" prop="dysb">
<el-select v-model="dysbValue" placeholder="请选择关联产品" clearable filterable :style='{"width":"100%"}' @change="handleDysbChange">
<el-option v-for="item in cpglOptions" :key="item.id" :label="item.cpmc + ' (' + (item.cpid || item.id) + ')'" :value="item.id" ></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="关联产品编号" prop="dysbbh">
<el-input v-model="dataForm.dysbbh" placeholder="自动填充" clearable :style='{"width":"100%"}' :disabled="true" >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备名称" prop="sbmc">
<el-input v-model="dataForm.sbmc" placeholder="自动填充" clearable :style='{"width":"100%"}' :disabled="true" >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="出厂编号" prop="ccbh">
<el-input v-model="dataForm.ccbh" placeholder="请输入出厂编号" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="生产厂家" prop="sccj">
<el-input v-model="dataForm.sccj" placeholder="请输入生产厂家" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="所属钻机编号" prop="sszjbh">
<el-input v-model="dataForm.sszjbh" placeholder="请输入所属钻机编号" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="所属井队编号" prop="ssjdbh">
<el-input v-model="dataForm.ssjdbh" placeholder="请输入所属井队编号" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="所属钻机型号" prop="sszjxh">
<el-input v-model="dataForm.sszjxh" placeholder="请输入所属钻机型号" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="购入时间" prop="gmsj">
<el-date-picker v-model="dataForm.gmsj" 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="设备状态" prop="sbzt">
<el-select v-model="dataForm.sbzt" placeholder="请选择设备状态" clearable :style='{"width":"100%"}' >
<el-option label="运行中" value="运行中"></el-option>
<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="whls">
<el-date-picker v-model="dataForm.whls" placeholder="请选择维护历史" clearable :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
</el-date-picker>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="维护周期" prop="whzq">
<el-select v-model="dataForm.whzq" placeholder="请选择维护周期" clearable :style='{"width":"100%"}' >
<el-option v-for="item in whzqOptions" :key="item.value" :label="item.label" :value="item.value" ></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="维护计划" prop="whjh">
<el-date-picker v-model="dataForm.whjh" placeholder="请选择维护计划" clearable :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
</el-date-picker>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="备件信息" prop="bjxx">
<el-select v-model="bjxxValue" placeholder="请选择备件信息" multiple clearable filterable :style='{"width":"100%"}' @change="handleBjxxChange">
<el-option v-for="item in bjxxOptions" :key="item.id" :label="item.mc + ' (' + item.bh + ')'" :value="item.id" ></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="历史故障" prop="lsgz">
<NCC-Quill v-model="dataForm.lsgz" placeholder="请输入历史故障内容..." >
</NCC-Quill>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备图片" prop="sbtp">
<NCC-UploadImg v-model="dataForm.sbtp" :fileSize="1" sizeUnit="GB" :limit="9" >
</NCC-UploadImg>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备资料" prop="sbzl">
<NCC-UploadFz v-model="dataForm.sbzl" :fileSize="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
</NCC-UploadFz>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="所属客户" prop="sskh">
<NCC-TreeSelect
v-model="sskhValue"
:options="userTreeData"
placeholder="请选择所属客户"
clearable
:style='{"width":"100%"}'
lastLevel
lastLevelKey='type'
lastLevelValue='user'
@change="handleSskhChange">
</NCC-TreeSelect>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="所属客户编号" prop="sskhbh">
<el-input v-model="dataForm.sskhbh" placeholder="自动填充" clearable :style='{"width":"100%"}' :disabled="true" >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="客户销售人员" prop="khxsry">
<NCC-TreeSelect
v-model="khxsryValue"
:options="userTreeData"
placeholder="请选择客户销售人员"
clearable
:style='{"width":"100%"}'
lastLevel
lastLevelKey='type'
lastLevelValue='user'
@change="handleKhxsryChange">
</NCC-TreeSelect>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="客户销售人员编号" prop="khxsrybh">
<el-input v-model="dataForm.khxsrybh" placeholder="自动填充" clearable :style='{"width":"100%"}' :disabled="true" >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="下次维护时间" prop="xcwhsj">
<el-date-picker v-model="dataForm.xcwhsj" placeholder="请选择下次维护时间" clearable :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
</el-date-picker>
</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 { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { previewDataInterface } from '@/api/systemData/dataInterface'
import { getUserSelector } from '@/api/permission/user'
export default {
components: {},
props: [],
data() {
return {
loading: false,
visible: false,
isDetail: false,
dataForm: {
id:'',
id:undefined,
sskh:undefined,
sskhbh:undefined,
dysb:undefined,
dysbbh:undefined,
khxsry:undefined,
khxsrybh:undefined,
gmsj:undefined,
sbmc:undefined,
ccbh:undefined,
sccj:undefined,
sszjbh:undefined,
ssjdbh:undefined,
sszjxh:undefined,
sbzt:undefined,
whls:undefined,
xcwhsj:undefined,
whzq:undefined,
whjh:undefined,
bjxx:'', // 存储为字符串格式(逗号分隔)
lsgz:undefined,
sbtp:[], // 设备图片数组
sbzl:[], // 设备资料数组
},
rules: {
},
userTreeData: [],
cpglOptions: [], // 产品管理选项
bjxxOptions: [], // 备件信息选项
sskhValue: '', // 所属客户选择值
dysbValue: '', // 关联产品选择值
khxsryValue: '', // 客户销售人员选择值
bjxxValue: [], // 备件信息选择值(数组)
whzqOptions: [ // 维护周期选项
{ label: '1天', value: '1天' },
{ label: '3天', value: '3天' },
{ label: '1周', value: '1周' },
{ label: '2周', value: '2周' },
{ label: '1月', value: '1月' },
{ label: '2月', value: '2月' },
{ label: '3月', value: '3月' },
{ label: '6月', value: '6月' },
{ label: '1年', value: '1年' },
],
}
},
computed: {},
watch: {},
created() {
this.getUserTreeData();
this.getCpglOptions();
this.getBjxxOptions();
},
mounted() {
},
methods: {
getUserTreeData() {
getUserSelector().then(res => {
this.userTreeData = res.data.list || []
}).catch(err => {
console.error('获取用户列表失败:', err)
this.userTreeData = []
})
},
getCpglOptions() {
return request({
url: '/api/Extend/Cpgl',
method: 'GET',
data: { currentPage: 1, pageSize: 1000 }
}).then(res => {
this.cpglOptions = res.data.list || []
return Promise.resolve()
}).catch(err => {
console.error('获取产品管理列表失败:', err)
this.cpglOptions = []
return Promise.reject(err)
})
},
getBjxxOptions() {
return request({
url: '/api/Extend/Bjxx',
method: 'GET',
data: { currentPage: 1, pageSize: 1000 }
}).then(res => {
this.bjxxOptions = res.data.list || []
return Promise.resolve()
}).catch(err => {
console.error('获取备件信息列表失败:', err)
this.bjxxOptions = []
return Promise.reject(err)
})
},
handleBjxxChange(val) {
// 将数组转换为逗号分隔的字符串存储到 dataForm
this.dataForm.bjxx = val ? val.join(',') : '';
},
handleSskhChange(val) {
// 选择用户后,自动填充用户编号和用户名称
if (val) {
this.dataForm.sskhbh = val;
// 从树形数据中查找用户名称
const user = this.findUserInTree(this.userTreeData, val);
if (user) {
this.dataForm.sskh = user.fullName;
}
} else {
this.dataForm.sskh = '';
this.dataForm.sskhbh = '';
}
},
handleDysbChange(val) {
// 选择产品后,自动填充产品编号、产品名称和设备名称字段
if (val) {
const product = this.cpglOptions.find(item => item.id === val);
if (product) {
this.dataForm.dysbbh = product.cpid || product.id || '';
this.dataForm.dysb = product.cpmc || '';
// 自动填充设备名称(从产品名称获取)
this.dataForm.sbmc = product.cpmc || '';
}
} else {
this.dataForm.dysb = '';
this.dataForm.dysbbh = '';
this.dataForm.sbmc = '';
}
},
handleKhxsryChange(val) {
// 选择销售人员后,自动填充销售人员编号和销售人员名称
if (val) {
this.dataForm.khxsrybh = val;
// 从树形数据中查找用户名称
const user = this.findUserInTree(this.userTreeData, val);
if (user) {
this.dataForm.khxsry = user.fullName;
}
} else {
this.dataForm.khxsry = '';
this.dataForm.khxsrybh = '';
}
},
findUserInTree(tree, id) {
// 递归查找树形数据中的用户
for (let item of tree) {
if (item.id === id && item.type === 'user') {
return item;
}
if (item.children && item.children.length > 0) {
const found = this.findUserInTree(item.children, id);
if (found) return found;
}
}
return null;
},
goBack() {
this.$emit('refresh')
},
init(id, isDetail) {
this.dataForm.id = id || 0;
this.visible = true;
this.isDetail = isDetail || false;
// 初始化选择值
this.sskhValue = '';
this.dysbValue = '';
this.khxsryValue = '';
this.bjxxValue = [];
this.$nextTick(() => {
this.$refs['elForm'].resetFields();
if (this.dataForm.id) {
request({
url: '/api/Extend/Khsb/' + this.dataForm.id,
method: 'get'
}).then(res =>{
this.dataForm = res.data;
// 处理数组字段
if (!this.dataForm.sbtp) this.dataForm.sbtp = [];
if (!this.dataForm.sbzl) this.dataForm.sbzl = [];
// 根据编号设置选择值
if (this.dataForm.sskhbh) {
this.sskhValue = this.dataForm.sskhbh;
}
if (this.dataForm.dysbbh) {
// 根据产品编号查找对应的产品ID
// 如果 cpglOptions 还未加载,等待加载完成
if (this.cpglOptions.length === 0) {
this.getCpglOptions().then(() => {
const product = this.cpglOptions.find(item => (item.cpid || item.id) === this.dataForm.dysbbh);
if (product) {
this.dysbValue = product.id;
// 如果设备名称为空,自动填充
if (!this.dataForm.sbmc) {
this.dataForm.sbmc = product.cpmc || '';
}
}
});
} else {
const product = this.cpglOptions.find(item => (item.cpid || item.id) === this.dataForm.dysbbh);
if (product) {
this.dysbValue = product.id;
// 如果设备名称为空,自动填充
if (!this.dataForm.sbmc) {
this.dataForm.sbmc = product.cpmc || '';
}
}
}
}
if (this.dataForm.khxsrybh) {
this.khxsryValue = this.dataForm.khxsrybh;
}
// 处理备件信息(从逗号分隔的字符串转换为数组)
if (this.dataForm.bjxx && typeof this.dataForm.bjxx === 'string') {
this.bjxxValue = this.dataForm.bjxx.split(',').filter(item => item);
} else {
this.bjxxValue = [];
}
})
} else {
// 新建时清空所有字段
this.dataForm.sskh = '';
this.dataForm.sskhbh = '';
this.dataForm.dysb = '';
this.dataForm.dysbbh = '';
this.dataForm.khxsry = '';
this.dataForm.khxsrybh = '';
this.dataForm.sbmc = '';
this.dataForm.ccbh = '';
this.dataForm.sccj = '';
this.dataForm.sszjbh = '';
this.dataForm.ssjdbh = '';
this.dataForm.sszjxh = '';
this.dataForm.sbzt = '';
this.dataForm.whls = undefined;
this.dataForm.xcwhsj = undefined;
this.dataForm.whzq = '';
this.dataForm.whjh = undefined;
this.dataForm.bjxx = '';
this.dataForm.lsgz = '';
this.dataForm.sbtp = [];
this.dataForm.sbzl = [];
this.bjxxValue = [];
}
})
},
dataFormSubmit() {
this.$refs['elForm'].validate((valid) => {
if (valid) {
// 确保 bjxx 是字符串格式(从 bjxxValue 同步)
if (Array.isArray(this.bjxxValue) && this.bjxxValue.length > 0) {
this.dataForm.bjxx = this.bjxxValue.join(',');
} else {
this.dataForm.bjxx = '';
}
if (!this.dataForm.id) {
request({
url: `/api/Extend/Khsb`,
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/Khsb/' + 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>