소스 검색

复制树修改

duy 7 달 전
부모
커밋
d5d905103b
1개의 변경된 파일66개의 추가작업 그리고 34개의 파일을 삭제
  1. 66 34
      src/views/project/debit/contract/components/unit/tree-form.vue

+ 66 - 34
src/views/project/debit/contract/components/unit/tree-form.vue

@@ -61,7 +61,7 @@
 
 <script setup>
 import { nextTick, ref, watch } from 'vue'
-import { arrToId, getArrValue, getRandom, isArrItem } from 'js-fast-way'
+import { arrToId, getArrValue, getRandom, isArrIndex, isArrItem } from 'js-fast-way'
 import unitApi from '~api/project/debit/contract/unit.js'
 import { useAppStore } from '~src/store'
 
@@ -194,6 +194,7 @@ watch(() => [
 watch(isShow, (val) => {
     if (val) {
         setSplitRef()
+        checkStrictly.value = false
       
        
       
@@ -347,39 +348,70 @@ const defaultCheckedKeys = ref([])
 const defaultExpandAll = ref(true)
 
 const changeIsAdd = (val, row, index)=>{
-        // const { isParent } = row
-        // if (isParent && val === 0) {
-        //     let rowTreeData = leftTree.value.treeRef.getNode(row.id)
-        //     let delKeys = arrToId(rowTreeData.data.children).split(',')
-        //     nextTick(()=>{
-        //         delKeys.forEach((ele)=>{
-        //             leftTree.value.treeRef.setChecked(ele, false, true)
-        //             let checkKeys = leftTree.value.treeRef.getCheckedKeys()
-        //             let arr = []
-        //             tableData.value.forEach((ele)=>{
-        //                 checkKeys.forEach((ele1)=>{
-        //                     if (ele.id === ele1) {
-        //                         arr.push(ele)
-        //                     }
-        //                 })
-        //             })
-        //             tableData.value = arr
-        //          if (checkKeys.length > 0) {
-        //             tableData.value.unshift(
-        //                 { nodeName: parentData.value.nodeName,
-        //                 startStake: '',
-        //                 endStake: '',
-        //                 contractPicture: '',
-        //                 isAddChildNode:0,
-        //                 id:parentData.value.id,
-        //                 parentId:parentData.value.parentId,
-        //                 isParent:isTable.value ? false : true,
-        //                 },
-        //             )
-        //          }
-        //         })
-        //     })
-        // } 
+        const { isParent } = row
+        if (isParent && val === 0) {
+            let rowTreeData = leftTree.value.treeRef.getNode(row.id)
+            let delKeys = arrToId(rowTreeData.data.children).split(',')
+            nextTick(()=>{
+                delKeys.forEach((ele)=>{
+               
+                    leftTree.value.treeRef.setChecked(ele, false, true)
+                    leftTree.value.treeRef.setChecked(row.id, true, false)
+                    let checkKeys = leftTree.value.treeRef.getCheckedKeys()
+                    let arr = []
+                    tableData.value.forEach((ele)=>{
+                        checkKeys.forEach((ele1)=>{
+                            if (ele.id === ele1) {
+                                arr.push(ele)
+                            }
+                        })
+                    })
+                    tableData.value = arr
+                  
+                })
+                const isIdExist = tableData.value.some(obj => obj.id === parentData.value.id)
+                if (!isIdExist) {
+                    tableData.value.unshift(
+                            { nodeName: parentData.value.nodeName,
+                            startStake: '',
+                            endStake: '',
+                            contractPicture: '',
+                            isAddChildNode:1,
+                            id:parentData.value.id,
+                            parentId:parentData.value.parentId,
+                            isParent:true,
+                            },
+                 )
+                }
+                
+            })
+        } else if (isParent && val === 1) {
+            checkStrictly.value = false
+            let rowTreeData = leftTree.value.treeRef.getNode(row.id)
+            let delKeys = arrToId(rowTreeData.data?.children).split(',') || []
+            let checkNodes = []
+            nextTick(()=>{
+                delKeys.forEach((ele)=>{
+                    leftTree.value.treeRef.setChecked(ele, true, true)
+                    checkNodes = leftTree.value.treeRef.getCheckedNodes()
+                })
+                const filteredArray1 = checkNodes.filter(obj1 => !tableData.value.some(obj2 => obj1.id === obj2.id))
+
+                filteredArray1.forEach((ele)=>{
+                    tableData.value.push(
+                        { nodeName: ele.nodeName,
+                        startStake: '',
+                        endStake: '',
+                        contractPicture: '',
+                        isAddChildNode:1,
+                        id:ele.id,
+                        parentId:ele.parentId,
+                        isParent:ele?.children ? true : false,
+                        },
+                    )
+                })
+            })
+        }
 }
 const leftTree = ref(null)
 </script>