Kaynağa Gözat

复制节点

duy 8 ay önce
ebeveyn
işleme
268c80aaca

+ 50 - 5
src/views/project/debit/contract/components/unit/tree-form.vue

@@ -58,7 +58,7 @@
 
 <script setup>
 import { nextTick, ref, watch } from 'vue'
-import { getArrValue, getRandom } from 'js-fast-way'
+import { getArrValue, getRandom, isArrItem } from 'js-fast-way'
 import unitApi from '~api/project/debit/contract/unit.js'
 import { useAppStore } from '~src/store'
 
@@ -79,6 +79,11 @@ const props = defineProps({
         type: [String],
          default: '合同计量单元新增',
     },
+    parentData:{
+        type:Object,
+        default: () => ({}),
+
+    },
 })
 //事件
 const emit = defineEmits(['finish', 'close'])
@@ -89,6 +94,7 @@ const menuType = ref(props.menuType)
 const ids = ref(props.ids)
 const templateId = ref(props.templateId)
 const title = ref(props.title)
+const parentData = ref(props.parentData)
 const uuid = getRandom(4)
 
 //双向绑定
@@ -141,17 +147,20 @@ watch(() => [
     props.menuType,
     props.templateId,
     props.title,
-], ([Ids, Type, Tem, til]) => {
+    props.parentData,
+], ([Ids, Type, Tem, til, parent]) => {
     ids.value = Ids
     menuType.value = Type
     templateId.value = Tem
     title.value = til
+    parentData.value = parent
     if (title.value === '合同计量单元复制') {
             tableColumn.value = [
             { key: 'nodeName', name: '名称' },
             { key: 'startStake', name: '开始桩号' },
             { key: 'endStake', name: '结束桩号' },
             { key: 'contractPicture', name: '合同图号' },
+            { key: 'isAddChildNode', name: '是否划分子节点', width: 120, align: 'center' },
             ]
     } else {
         tableColumn.value = [
@@ -164,6 +173,9 @@ watch(() => [
         ]
     }
     getTreeDataList()
+    if (isShow.value) {
+        getLeftTreeData(ids.value)
+    }
 
 }, { immediate: true })
 
@@ -171,7 +183,7 @@ watch(() => [
 watch(isShow, (val) => {
     if (val) {
         setSplitRef()
-        getLeftTreeData(ids.value)
+      
        
       
     }
@@ -270,8 +282,41 @@ const nodeElTreeClick = (data)=>{
 
 }
 const treeNodeCheck = (_, { checkedNodes }) => {
-    console.log(checkedNodes, 'checkedNodes')
-    tableData.value = checkedNodes
+    tableData.value = []
+    checkedNodes.forEach((item)=>{
+        tableData.value.push(
+            { nodeName: item.nodeName,
+            startStake: '',
+            endStake: '',
+            contractPicture: '',
+            isAddChildNode: item.isAddChildNode,
+            leftNodeId:item.id },
+        )
+    })
+
+    
+
+    if (checkedNodes.length > 0 ) {
+        tableData.value.unshift(
+          { ...parentData.value,
+            isAddChildNode:1 },
+        )
+        let alarr = tableData.value
+             // 使用reduce方法进行去重
+            const uniqueArray = alarr.reduce((acc, current) => {
+            // 检查当前对象的某个字段是否已存在于累积数组中
+            const x = acc.find(item => item.nodeName === current.nodeName)
+            
+            // 如果不存在,则将其添加到累积数组中
+            if (!x) {
+                return acc.concat([current])
+            } else {
+                return acc
+            }
+            }, [])
+        
+            tableData.value = uniqueArray
+    }
   
 }
 const leftTree = ref(null)

+ 1 - 0
src/views/project/debit/contract/unit.vue

@@ -80,6 +80,7 @@
         <treeForm
             v-model="treeModalShow" :ids="curTreeData.id" :menu-type="menuType"
             :template-id="curTreeData.templateId" :title="treeModalShowTitle"
+            :parent-data="curTreeData"
             @finish="finishForm"
         />