Browse Source

复制树修改

duy 7 months ago
parent
commit
bb63bc2f12

+ 60 - 6
src/views/project/debit/contract/components/unit/tree-form.vue

@@ -19,6 +19,9 @@
                             show-checkbox  
                             :datas="leftTreeData" 
                             :h-props="lefttreeProps" 
+                            :default-expand-all="defaultExpandAll"
+                            :check-strictly="checkStrictly"
+                            :default-checked-keys="defaultCheckedKeys"
                             @node-tap="nodeElTreeClick"
                             @check="treeNodeCheck"
                         />
@@ -40,8 +43,8 @@
                         <template #contractPicture="{ row }">
                             <hc-table-input v-model="row.contractPicture" />
                         </template>
-                        <template #isAddChildNode="{ row }">
-                            <el-radio-group v-model="row.isAddChildNode">
+                        <template #isAddChildNode="{ row, index }">
+                            <el-radio-group v-model="row.isAddChildNode" @change="changeIsAdd($event, row, index)">
                                 <el-radio :value="1">是</el-radio>
                                 <el-radio :value="0" class="ml-2">否</el-radio>
                             </el-radio-group>
@@ -58,7 +61,7 @@
 
 <script setup>
 import { nextTick, ref, watch } from 'vue'
-import { getArrValue, getRandom, isArrItem } from 'js-fast-way'
+import { arrToId, getArrValue, getRandom, isArrItem } from 'js-fast-way'
 import unitApi from '~api/project/debit/contract/unit.js'
 import { useAppStore } from '~src/store'
 
@@ -84,6 +87,10 @@ const props = defineProps({
         default: () => ({}),
 
     },
+    isTable: {
+        type: Boolean,
+        default: false,
+    },
 })
 //事件
 const emit = defineEmits(['finish', 'close'])
@@ -95,6 +102,7 @@ const ids = ref(props.ids)
 const templateId = ref(props.templateId)
 const title = ref(props.title)
 const parentData = ref(props.parentData)
+const isTable = ref(props.isTable)
 const uuid = getRandom(4)
 
 //双向绑定
@@ -148,12 +156,14 @@ watch(() => [
     props.templateId,
     props.title,
     props.parentData,
-], ([Ids, Type, Tem, til, parent]) => {
+    props.isTable,
+], ([Ids, Type, Tem, til, parent, tab]) => {
     ids.value = Ids
     menuType.value = Type
     templateId.value = Tem
     title.value = til
     parentData.value = parent
+    isTable.value = tab
     if (title.value === '合同计量单元复制') {
             tableColumn.value = [
             { key: 'nodeName', name: '名称' },
@@ -175,6 +185,7 @@ watch(() => [
     getTreeDataList()
     if (isShow.value) {
         getLeftTreeData(ids.value)
+        checkStrictly.value = false
     }
 
 }, { immediate: true })
@@ -247,7 +258,7 @@ const modalSave = async () => {
          }
         emit('finish')
     } else {
-
+        console.log(tableData.value, 'tableData.value')
         const { error, code, msg } = await unitApi.copyNode({
             contractId:contractId.value,
             id:ids.value,
@@ -281,7 +292,8 @@ const lefttreeProps = {
 const nodeElTreeClick = (data)=>{
 
 }
-const treeNodeCheck = (_, { checkedNodes }) => {
+const treeNodeCheck = (_, { checkedNodes, checkedKeys }) => {
+   console.log(checkedNodes, 'checkedNodes')
     tableData.value = []
     checkedNodes.forEach((item)=>{
         tableData.value.push(
@@ -292,6 +304,7 @@ const treeNodeCheck = (_, { checkedNodes }) => {
             isAddChildNode: item.isAddChildNode,
             id:item.id,
             parentId:item.parentId,
+            isParent:item?.children ? true : false,
            },
         )
     })
@@ -299,6 +312,7 @@ const treeNodeCheck = (_, { checkedNodes }) => {
     
 
     if (checkedNodes.length > 0 ) {
+        console.log(parentData.value, 'parentData')
         tableData.value.unshift(
             { nodeName: parentData.value.nodeName,
             startStake: '',
@@ -307,6 +321,7 @@ const treeNodeCheck = (_, { checkedNodes }) => {
             isAddChildNode: parentData.value.isAddChildNode || 1,
             id:parentData.value.id,
             parentId:parentData.value.parentId,
+            isParent:isTable.value ? false : true,
              },
         )
         let alarr = tableData.value
@@ -327,6 +342,45 @@ const treeNodeCheck = (_, { checkedNodes }) => {
     }
   
 }
+const checkStrictly = ref(false)
+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 leftTree = ref(null)
 </script>
 

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

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