浏览代码

fix(equipLedger): 修复定检小组数据格式不匹配问题

1. 修正表格列绑定的prop和绑定值字段名,从inspectionTeamName/inspectionTeamIds改为inspectionTeamId
2. 在编辑和详情页处理中,将逗号分隔的定检小组ID字符串转为数字ID数组
3. 在提交表单时批量获取用户昵称,将ID数组转回逗号分隔字符串并拼接小组名称
4. 修复新增检查记录时的字段名错误
huoyi 4 周之前
父节点
当前提交
499e54eabc
共有 1 个文件被更改,包括 38 次插入4 次删除
  1. 38 4
      src/views/equipManage/equipLedger/index.vue

+ 38 - 4
src/views/equipManage/equipLedger/index.vue

@@ -230,9 +230,9 @@
230 230
                 @change="handleInspectionDateChange(scope.row, scope.$index)" />
231 231
             </template>
232 232
           </el-table-column>
233
-          <el-table-column label="定检小组" prop="inspectionTeamName">
233
+          <el-table-column label="定检小组" prop="inspectionTeamId">
234 234
             <template #default="scope">
235
-              <UserSelect v-model="scope.row.inspectionTeamIds" :multiple="true" :disabled="formDisabled" width="100%"
235
+              <UserSelect v-model="scope.row.inspectionTeamId" :multiple="true" :disabled="formDisabled" width="100%"
236 236
                 placeholder="请选择" />
237 237
             </template>
238 238
           </el-table-column>
@@ -435,6 +435,9 @@ function handleEdit(row) {
435 435
     form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || ''
436 436
     form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || ''
437 437
     form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || ''
438
+    form.equipmentInspectionRecordList.forEach(item => {
439
+      item.inspectionTeamId = item.inspectionTeamId ? item.inspectionTeamId.split(',').map(id => Number(id)).filter(id => !isNaN(id)) : []
440
+    })
438 441
     formDisabled.value = false
439 442
     dialog.title = '编辑设备'
440 443
     dialog.visible = true
@@ -465,6 +468,9 @@ function handleDetail(row) {
465 468
     form.inspectionTeamLeaderId = form.inspectionTeamLeaderId || ''
466 469
     form.inspectionTeamMember1Id = form.inspectionTeamMember1Id || ''
467 470
     form.inspectionTeamMember2Id = form.inspectionTeamMember2Id || ''
471
+    form.equipmentInspectionRecordList.forEach(item => {
472
+      item.inspectionTeamId = item.inspectionTeamId ? item.inspectionTeamId.split(',').map(id => Number(id)).filter(id => !isNaN(id)) : []
473
+    })
468 474
     formDisabled.value = true
469 475
     dialog.title = '设备详情'
470 476
     dialog.visible = true
@@ -550,7 +556,35 @@ async function submitForm() {
550 556
     if (valid) {
551 557
       const submitData = { ...form, ...form.installationLocation }
552 558
       submitData.baseAttachmentList = baseAttachmentListInternal.value
553
-
559
+      // 收集所有定检小组用户ID,批量获取名称
560
+      const allTeamIds = new Set()
561
+      form.equipmentInspectionRecordList.forEach(item => {
562
+        if (item.inspectionTeamId && Array.isArray(item.inspectionTeamId)) {
563
+          item.inspectionTeamId.forEach(id => allTeamIds.add(id))
564
+        }
565
+      })
566
+      const userMap = new Map()
567
+      if (allTeamIds.size > 0) {
568
+        const userPromises = Array.from(allTeamIds).map(async id => {
569
+          try {
570
+            const res = await getUser(String(id))
571
+            return { id, name: res.data?.nickName || '' }
572
+          } catch {
573
+            return { id, name: '' }
574
+          }
575
+        })
576
+        const results = await Promise.all(userPromises)
577
+        results.forEach(({ id, name }) => userMap.set(id, name))
578
+      }
579
+      submitData.equipmentInspectionRecordList = form.equipmentInspectionRecordList.map(item => {
580
+        const teamIds = item.inspectionTeamId && Array.isArray(item.inspectionTeamId) ? item.inspectionTeamId.join(',') : ''
581
+        const teamNames = item.inspectionTeamId && Array.isArray(item.inspectionTeamId) ? item.inspectionTeamId.map(id => userMap.get(id) || '').filter(Boolean).join(',') : ''
582
+        return {
583
+          ...item,
584
+          inspectionTeamId: teamIds,
585
+          inspectionTeamName: teamNames
586
+        }
587
+      })
554 588
       try {
555 589
         if (submitData.inspectionTeamLeaderId) {
556 590
           const leaderRes = await getUser(submitData.inspectionTeamLeaderId)
@@ -599,7 +633,7 @@ function addCheckRecord() {
599 633
   }
600 634
   form.equipmentInspectionRecordList.push({
601 635
     inspectionDate: '',
602
-    inspectionTeamIds: teamIds,
636
+    inspectionTeamId: teamIds,
603 637
     inspectionTeamName: '',
604 638
     inspectionResult: '',
605 639
     inspectionNature: ''