diff --git a/src/views/user/goodsManagement/index.vue b/src/views/user/goodsManagement/index.vue index d2a9212..211b1da 100644 --- a/src/views/user/goodsManagement/index.vue +++ b/src/views/user/goodsManagement/index.vue @@ -508,9 +508,9 @@ const dialogTypeCascader = ref() //装备类目-change const dialogTypeChange = async (val: any) => { const nodeId = val[val.length - 1] - const nodeList = findNextLevelIds(oldDeviceTypeTree.value, nodeId) + const nodeList = findNextLevelNodes(oldDeviceTypeTree.value, nodeId) console.log('🚀 ~ dialogTypeChange ~ nodeList:', nodeList) - typeId.value = nodeList ? nodeList[0] : [] + typeId.value = nodeList ? nodeList[0].id : '' options.value = [] const deviceTypeList = dialogTypeCascader.value.getCheckedNodes() warningDays.value = deviceTypeList[0].data.maintenanceAlarmDay @@ -534,7 +534,7 @@ const dialogTypeChange = async (val: any) => { console.log(propertyNames.value) } isDisabled.value = true - addAndEditForm.unitName = deviceTypeList[0].data.unitName + addAndEditForm.unitName = nodeList ? nodeList[0].unitName : '' addAndEditForm.dayLeasePrice = deviceTypeList[0].data.leasePrice addAndEditFormRef.value.clearValidate(['unitName', 'dayLeasePrice']) equipTableList.value = [] @@ -550,19 +550,20 @@ const dialogTypeChange = async (val: any) => { examinationPdf: [], }) } -const findNextLevelIds = (tree: any, targetId: any) => { +const findNextLevelNodes = (tree: any, targetId: any) => { for (const node of tree) { if (node.id === targetId) { - // 找到了目标节点,返回它 children 的 id 数组 - return node.children ? node.children.map((child: any) => child.id) : []; + // 找到了目标节点,返回它的 children(完整内容) + return node.children ? node.children : [] } if (node.children) { - const result: any = findNextLevelIds(node.children, targetId); - if (result) return result; + const result: any = findNextLevelNodes(node.children, targetId); + if (result) return result } } return null // 没找到 } + const changeDeviceType = async (val: any) => { console.log('🚀 ~ changeDeviceType ~ val:', val) if (val == 0) {