Prechádzať zdrojové kódy

fix: 成本审核表格显示父项子项

shiyanyu 1 mesiac pred
rodič
commit
f7b2045ac4

+ 38 - 2
src/views/costAudit/auditInfo/auditManage/costAudit.vue

@@ -631,8 +631,44 @@
             this.costAuditData.push(rowData)
           })
 
-          // 表格排序,子项排在父项的后面
-          this.sortItemsByHierarchy()
+          // 平铺顺序:父项在前、子项紧随其后
+          const sortFn = (a, b) =>
+            Number(a.orderNum || 0) - Number(b.orderNum || 0)
+          const byRowId = new Map()
+          const parents = []
+          const childGroups = new Map()
+          this.costAuditData.forEach((row) => {
+            if (row && row.children) delete row.children
+            const key = row.rowid != null ? String(row.rowid) : ''
+            if (key) byRowId.set(key, row)
+            const pid = row.parentid
+            const isParent =
+              pid === -1 || pid === '-1' || pid === null || pid === undefined
+            if (isParent) {
+              parents.push(row)
+            } else {
+              const pKey = pid != null ? String(pid) : ''
+              if (!childGroups.has(pKey)) childGroups.set(pKey, [])
+              childGroups.get(pKey).push(row)
+            }
+          })
+          parents.sort(sortFn)
+          const flat = []
+          const seen = new Set()
+          parents.forEach((p) => {
+            flat.push(p)
+            seen.add(p)
+            const group = childGroups.get(String(p.rowid)) || []
+            group.sort(sortFn).forEach((c) => {
+              flat.push(c)
+              seen.add(c)
+            })
+          })
+          // 处理找不到父项的子项:放在末尾
+          this.costAuditData.forEach((row) => {
+            if (!seen.has(row)) flat.push(row)
+          })
+          this.costAuditData = flat
         }
       },
       handleSaveTemplate(type) {