Browse Source

fix: 财务表、调查表查看的时候不要保存按钮

shiyanyu 1 tháng trước cách đây
mục cha
commit
f3231fd688

+ 3 - 1
src/views/EntDeclaration/auditTaskManagement/components/FixedTableDialog.vue

@@ -106,7 +106,9 @@
     </el-table>
 
     <div slot="footer" class="dialog-footer">
-      <el-button type="primary" @click="handleSave">保存</el-button>
+      <el-button v-if="!isViewMode" type="primary" @click="handleSave">
+        保存
+      </el-button>
       <el-button @click="handleCancel">取消</el-button>
     </div>
   </el-dialog>

+ 3 - 1
src/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue

@@ -138,7 +138,9 @@
     </el-form>
 
     <div slot="footer" class="dialog-footer">
-      <el-button type="primary" @click="handleSave">保存</el-button>
+      <el-button v-if="!isViewMode" type="primary" @click="handleSave">
+        保存
+      </el-button>
       <el-button @click="handleCancel">取消</el-button>
     </div>
   </el-dialog>

+ 6 - 133
src/views/costAudit/baseInfo/catalogManage/surveyDialog.vue

@@ -756,53 +756,9 @@
           allRows.push(newRow)
         })
 
-        // 按父子关系排序:父项在前,子项在对应的父项后面
-        allRows.sort((a, b) => {
-          // 先按orderNum排序父项
-          if (a.isChild && !b.isChild) {
-            // 如果a是子项,b是父项,需要检查a的父项是否在b之后
-            const parentOfA = allRows.find(
-              (item) => item.rowid === a.parentid || item.itemId === a.parentid
-            )
-            if (parentOfA && parentOfA.orderNum > b.orderNum) {
-              return 1
-            }
-            return -1
-          }
-          if (!a.isChild && b.isChild) {
-            // 如果a是父项,b是子项,需要检查b的父项是否在a之前
-            const parentOfB = allRows.find(
-              (item) => item.rowid === b.parentid || item.itemId === b.parentid
-            )
-            if (parentOfB && parentOfB.orderNum < a.orderNum) {
-              return -1
-            }
-            return 1
-          }
-
-          // 如果都是父项或都是子项,按orderNum排序
-          return (a.orderNum || 0) - (b.orderNum || 0)
-        })
-
-        // 重新排序,确保子项紧跟在其对应的父项后面
-        const sortedArray = []
-        const parentItems = allRows.filter((item) => !item.isChild)
-        const childItems = allRows.filter((item) => item.isChild)
-
-        parentItems.forEach((parent) => {
-          sortedArray.push(parent)
-          // 找到并添加该父项的所有子项
-          const relatedChildren = childItems.filter(
-            (child) =>
-              child.parentid === parent.rowid ||
-              child.parentid === parent.itemId
-          )
-          // 子项按orderNum排序
-          relatedChildren.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0))
-          sortedArray.push(...relatedChildren)
-        })
-
-        this.contentEditForm.fixedTable.fixedTables = sortedArray
+        // 使用统一的层次排序:父项在前,子项紧随其后
+        this.contentEditForm.fixedTable.fixedTables =
+          this.flattenHierarchy(allRows)
       },
       getFixedPreviewRowClass({ row }) {
         if (!row) return ''
@@ -902,92 +858,9 @@
           allRows.push(newRow)
         })
 
-        // 按父子关系排序:父项在前,子项在对应的父项后面
-        // 1. 先创建一个映射表,方便通过ID查找父项
-        const rowMap = new Map()
-        const sortedArray = []
-        const addedItems = new Set()
-
-        // 深拷贝原始数据并过滤掉重复项
-        const uniqueRows = allRows.reduce((acc, current) => {
-          const isDuplicate = acc.some(
-            (row) =>
-              (row.rowid && current.rowid && row.rowid === current.rowid) ||
-              (row.itemId && current.itemId && row.itemId === current.itemId)
-          )
-          if (!isDuplicate) {
-            acc.push(JSON.parse(JSON.stringify(current)))
-          }
-          return acc
-        }, [])
-
-        // 填充映射表
-        uniqueRows.forEach((row) => {
-          if (row.rowid) rowMap.set(String(row.rowid), row)
-          if (row.itemId) rowMap.set(String(row.itemId), row)
-        })
-
-        // 先按orderNum排序所有父项
-        const parentItems = uniqueRows.filter((item) => !item.isChild)
-        parentItems.sort(
-          (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
-        )
-
-        // 递归添加父项及其子项的函数
-        const addItemWithChildren = (item) => {
-          // 确保项目ID唯一
-          const itemIdKey = String(
-            item.rowid || item.itemId || `temp_${Math.random()}`
-          )
-
-          // 如果已经添加过,则跳过
-          if (addedItems.has(itemIdKey)) return
-
-          // 添加当前项目
-          sortedArray.push(item)
-          addedItems.add(itemIdKey)
-
-          // 找到并添加所有子项
-          const children = uniqueRows.filter((child) => {
-            if (child.isChild) {
-              const childParentId = String(child.parentid)
-              return (
-                childParentId === String(item.rowid) ||
-                childParentId === String(item.itemId)
-              )
-            }
-            return false
-          })
-
-          // 子项按orderNum排序
-          children.sort(
-            (a, b) => (Number(a.orderNum) || 0) - (Number(b.orderNum) || 0)
-          )
-
-          // 添加所有子项
-          children.forEach((child) => addItemWithChildren(child))
-        }
-
-        // 遍历所有父项,添加父项及其子项
-        parentItems.forEach((parent) => addItemWithChildren(parent))
-
-        // 添加剩余的没有被添加的项目(应该很少,但作为兜底)
-        uniqueRows.forEach((row) => {
-          const itemIdKey = String(
-            row.rowid || row.itemId || `temp_${Math.random()}`
-          )
-          if (!addedItems.has(itemIdKey)) {
-            sortedArray.push(row)
-            addedItems.add(itemIdKey)
-          }
-        })
-
-        // 最后,重新计算显示序号,确保序号连续且正确
-        sortedArray.forEach((item, index) => {
-          item.orderText = String(index + 1)
-        })
-
-        this.contentEditForm.dynamicTable.dynamicTables = sortedArray
+        // 使用统一的层次排序:父项在前,子项紧随其后
+        this.contentEditForm.dynamicTable.dynamicTables =
+          this.flattenHierarchy(allRows)
       },
       // 字符串转对象数组
       stringToObjects(str) {