Pārlūkot izejas kodu

fix:修改成本审核保存核定数据问题和回显问题

luzhixia 1 mēnesi atpakaļ
vecāks
revīzija
441e3c1c8b

+ 55 - 0
src/components/task/components/costAudit.vue

@@ -463,6 +463,7 @@
           if (tableHeadersRes.code == 200) {
             this.parseAndDisplayTableHeaders(tableHeadersRes)
             this.parseAndDisplayTableData(tableDataRes)
+            await this.tryEchoUploadData()
           }
         }
       },
@@ -485,6 +486,60 @@
         // 处理表格数据
         if (tableDataRes.code == 200) {
           this.parseAndDisplayTableData(tableDataRes)
+          await this.tryEchoUploadData()
+        }
+      },
+      // 根据已存在的上传数据进行回显(若有)
+      async tryEchoUploadData() {
+        try {
+          const uploadId = (this.auditForm && this.auditForm.uploadId) || ''
+          const auditedUnitId = this.auditedUnitId || ''
+          const taskId =
+            (this.selectedProject && this.selectedProject.taskId) || ''
+          // if (!uploadId || !auditedUnitId) return
+          const params = {
+            // uploadId,
+            // auditedUnitId,
+            type: '3',
+            taskId: taskId,
+          }
+          const res = await getSurveyDetail(params)
+          if (res && res.code === 200 && res.value) {
+            const triplets = Array.isArray(res.value)
+              ? res.value
+              : res.value.items || res.value.records || []
+            if (!Array.isArray(triplets) || triplets.length === 0) return
+            // 建立字段名映射:rkey(中文列名) -> fieldEname(表格prop)
+            const headerMap = {}
+            ;(this.tableHeadersRes || []).forEach((h) => {
+              if (h && h.fieldName && h.fieldEname)
+                headerMap[h.fieldName] = h.fieldEname
+            })
+            // 行索引:rowid -> 行对象
+            const rowMap = new Map()
+            ;(this.costAuditData || []).forEach((row) => {
+              if (row && row.rowid !== undefined && row.rowid !== null) {
+                rowMap.set(String(row.rowid), row)
+              }
+            })
+            // 应用回显
+            triplets.forEach((item) => {
+              const rowid = item.rowid || item.rowId || item.ROWID
+              const rkey = item.rkey || item.rKey || item.RKEY
+              const rvalue = item.rvalue || item.rValue || item.RVALUE
+              if (!rowid || !rkey) return
+              const row = rowMap.get(String(rowid))
+              const prop = headerMap[rkey]
+              if (row && prop) {
+                row[prop] = rvalue != null ? String(rvalue) : ''
+              }
+            })
+            // 强制刷新
+            this.costAuditData = [...this.costAuditData]
+          }
+        } catch (e) {
+          // 静默失败即可
+          console.warn('回显上传数据失败: ', e)
         }
       },
       parseAndDisplayTableHeaders(res) {

+ 18 - 7
src/views/costAudit/auditInfo/auditManage/costAudit.vue

@@ -447,11 +447,14 @@
         try {
           const uploadId = (this.auditForm && this.auditForm.uploadId) || ''
           const auditedUnitId = this.auditedUnitId || ''
-          if (!uploadId || !auditedUnitId) return
+          const taskId =
+            (this.selectedProject && this.selectedProject.taskId) || ''
+          // if (!uploadId || !auditedUnitId) return
           const params = {
-            uploadId,
-            auditedUnitId,
-            type: 1,
+            // uploadId,
+            // auditedUnitId,
+            type: '3',
+            taskId: taskId,
           }
           const res = await getSurveyDetail(params)
           if (res && res.code === 200 && res.value) {
@@ -504,7 +507,7 @@
               ...item,
               prop: item.fieldEname,
               label: item.fieldName,
-              width: '150px',
+              width: item.fieldName == '序号' ? '80px' : '150px',
               align: 'center',
             }
             this.costAuditcolumn.push(column)
@@ -779,7 +782,7 @@
           const hasData = !!(this.auditForm && this.auditForm.uploadId)
           const taskId =
             (this.selectedProject && this.selectedProject.taskId) || ''
-
+          console.log('rawItems', rawItems)
           const finalSaveData = rawItems.map((it) => {
             const base = {
               rowid: it.rowid,
@@ -789,6 +792,11 @@
               surveyTemplateId,
               catalogId,
               taskId,
+              // id: it.id,
+              parentId: it.parentid || '-1',
+              // refId: taskId,
+              type: '3',
+              // uploadId: '',
             }
             if (hasData) base.uploadId = this.auditForm.uploadId
             return base
@@ -847,7 +855,10 @@
             )
             const newItem = {
               rkey: title.rkey,
-              rvalue: node[correspondingHeader.fieldEname] || '',
+              rvalue:
+                node[correspondingHeader.prop] ||
+                node[correspondingHeader.fieldEname] ||
+                '',
               [correspondingHeader.fieldName]:
                 node[correspondingHeader.fieldEname] || '',
               surveyTemplateId: