Blame view

机具(管理端)/src/views/khsb/Form.vue 18.1 KB
5a92a12b   “wangming”   项目初始化
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
  <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">
040963e1   “wangming”   等待一堆修改
97
  							<el-select v-model="bjxxValue" placeholder="请先选择关联产品后再选择备件" multiple clearable filterable :style='{"width":"100%"}' :disabled="!dysbValue" @change="handleBjxxChange">
5a92a12b   “wangming”   项目初始化
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
  								<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" 
d56bd957   “wangming”   修复问题,组建AI
125
  								placeholder="请选择所属客户(人员/部门/组织)" 
5a92a12b   “wangming”   项目初始化
126
127
  								clearable 
  								:style='{"width":"100%"}' 
5a92a12b   “wangming”   项目初始化
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
  								@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:'',
5a92a12b   “wangming”   项目初始化
188
189
190
191
  					sskh:undefined,
  					sskhbh:undefined,
  					dysb:undefined,
  					dysbbh:undefined,
d56bd957   “wangming”   修复问题,组建AI
192
  					fl:undefined, // 关联产品/设备ID(对应 Cpgl.id)
5a92a12b   “wangming”   项目初始化
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
  					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();
5a92a12b   “wangming”   项目初始化
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
  		},
  		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)
  				})
  			},
040963e1   “wangming”   等待一堆修改
265
266
267
268
269
270
  			// 按产品筛选备件,仅返回对应产品的备件(productId 为 cpgl.id)
  			getBjxxOptions(productId) {
  				if (!productId) {
  					this.bjxxOptions = []
  					return Promise.resolve()
  				}
5a92a12b   “wangming”   项目初始化
271
272
273
  				return request({
  					url: '/api/Extend/Bjxx',
  					method: 'GET',
040963e1   “wangming”   等待一堆修改
274
  					data: { currentPage: 1, pageSize: 2000, sssb: productId }
5a92a12b   “wangming”   项目初始化
275
276
277
278
279
280
281
282
283
284
285
286
287
288
  				}).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) {
d56bd957   “wangming”   修复问题,组建AI
289
  				// 选择人员/部门/组织后,自动填充编号和名称
5a92a12b   “wangming”   项目初始化
290
291
  				if (val) {
  					this.dataForm.sskhbh = val;
d56bd957   “wangming”   修复问题,组建AI
292
293
294
  					const node = this.findNodeInTree(this.userTreeData, val);
  					if (node) {
  						this.dataForm.sskh = node.fullName;
5a92a12b   “wangming”   项目初始化
295
296
297
298
299
300
301
  					}
  				} else {
  					this.dataForm.sskh = '';
  					this.dataForm.sskhbh = '';
  				}
  			},
  			handleDysbChange(val) {
040963e1   “wangming”   等待一堆修改
302
303
304
  				// 选择产品后,自动填充产品编号、产品名称、设备名称,并将设备id保存到fl字段;按产品加载备件列表
  				this.bjxxValue = [];
  				this.dataForm.bjxx = '';
5a92a12b   “wangming”   项目初始化
305
306
307
  				if (val) {
  					const product = this.cpglOptions.find(item => item.id === val);
  					if (product) {
d56bd957   “wangming”   修复问题,组建AI
308
  						this.dataForm.fl = val; // 保存关联产品/设备id到fl字段
5a92a12b   “wangming”   项目初始化
309
310
  						this.dataForm.dysbbh = product.cpid || product.id || '';
  						this.dataForm.dysb = product.cpmc || '';
5a92a12b   “wangming”   项目初始化
311
  						this.dataForm.sbmc = product.cpmc || '';
040963e1   “wangming”   等待一堆修改
312
  						this.getBjxxOptions(val);
5a92a12b   “wangming”   项目初始化
313
314
  					}
  				} else {
d56bd957   “wangming”   修复问题,组建AI
315
  					this.dataForm.fl = '';
040963e1   “wangming”   等待一堆修改
316
317
318
319
  					this.dataForm.dysb = '';
  					this.dataForm.dysbbh = '';
  					this.dataForm.sbmc = '';
  					this.bjxxOptions = [];
5a92a12b   “wangming”   项目初始化
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
  				}
  			},
  			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) {
d56bd957   “wangming”   修复问题,组建AI
337
  				// 递归查找树形数据中的用户(仅 type=user)
5a92a12b   “wangming”   项目初始化
338
339
340
341
342
343
344
345
346
347
348
  				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;
  			},
d56bd957   “wangming”   修复问题,组建AI
349
350
351
352
353
354
355
356
357
358
359
360
361
  			findNodeInTree(tree, id) {
  				// 递归查找树形数据中的节点(人员/部门/组织均可)
  				for (let item of tree) {
  					if (item.id === id) {
  						return item;
  					}
  					if (item.children && item.children.length > 0) {
  						const found = this.findNodeInTree(item.children, id);
  						if (found) return found;
  					}
  				}
  				return null;
  			},
5a92a12b   “wangming”   项目初始化
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
  			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;
  							}
040963e1   “wangming”   等待一堆修改
390
  							// 优先用 fl 还原关联产品选择,否则用 dysbbh 查找;再按产品加载备件
d56bd957   “wangming”   修复问题,组建AI
391
392
393
394
395
396
  							const resolveDysbValue = () => {
  								if (this.dataForm.fl) {
  									this.dysbValue = this.dataForm.fl;
  									return;
  								}
  								if (this.dataForm.dysbbh) {
5a92a12b   “wangming”   项目初始化
397
398
399
  									const product = this.cpglOptions.find(item => (item.cpid || item.id) === this.dataForm.dysbbh);
  									if (product) {
  										this.dysbValue = product.id;
d56bd957   “wangming”   修复问题,组建AI
400
401
  										this.dataForm.fl = product.id;
  										if (!this.dataForm.sbmc) this.dataForm.sbmc = product.cpmc || '';
5a92a12b   “wangming”   项目初始化
402
403
  									}
  								}
d56bd957   “wangming”   修复问题,组建AI
404
  							};
040963e1   “wangming”   等待一堆修改
405
406
407
408
409
410
411
412
413
414
415
416
417
418
  							const loadBjxxAndRestore = () => {
  								const productId = this.dataForm.fl || this.dysbValue;
  								if (productId) {
  									this.getBjxxOptions(productId).then(() => {
  										if (this.dataForm.bjxx && typeof this.dataForm.bjxx === 'string') {
  											this.bjxxValue = this.dataForm.bjxx.split(',').filter(item => item);
  										} else {
  											this.bjxxValue = [];
  										}
  									});
  								} else {
  									this.bjxxValue = [];
  								}
  							};
d56bd957   “wangming”   修复问题,组建AI
419
  							if (this.cpglOptions.length === 0) {
040963e1   “wangming”   等待一堆修改
420
421
422
423
  								this.getCpglOptions().then(() => {
  									resolveDysbValue();
  									loadBjxxAndRestore();
  								});
d56bd957   “wangming”   修复问题,组建AI
424
425
  							} else {
  								resolveDysbValue();
040963e1   “wangming”   等待一堆修改
426
  								loadBjxxAndRestore();
5a92a12b   “wangming”   项目初始化
427
428
429
430
  							}
  							if (this.dataForm.khxsrybh) {
  								this.khxsryValue = this.dataForm.khxsrybh;
  							}
5a92a12b   “wangming”   项目初始化
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  						})
  					} 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>