From da8eefb2cd55ee6e6629d1f98109eb8b01cd4069 Mon Sep 17 00:00:00 2001 From: bb_pan Date: Tue, 21 Oct 2025 14:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E5=95=86=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/user/goodsManagement/index.vue | 163 +++++++++++------------ 1 file changed, 76 insertions(+), 87 deletions(-) diff --git a/src/views/user/goodsManagement/index.vue b/src/views/user/goodsManagement/index.vue index 4e1d93f..d2a9212 100644 --- a/src/views/user/goodsManagement/index.vue +++ b/src/views/user/goodsManagement/index.vue @@ -34,7 +34,7 @@ const batchAddVisible: any = ref(false) // 批量新增 const batchAddData: any = ref([]) // 批量新增 const batchAddColumn: any = ref([ { label: '装备名称', prop: 'deviceName' }, - { label: '装备型号', prop: 'typeName' }, + { label: '装备型号', prop: 'itemTypeModel' }, { label: '上传人', prop: 'uploadUser' }, { label: '上传时间', prop: 'uploadTime' }, ]) @@ -43,7 +43,8 @@ const uploadUrlTemp = window.location.origin + '/iws/mall-view/MaDevTemplate.xls // 注册地址拼装 const AssemblyRegisterAddress: any = reactive([]) -const deviceType: any = reactive([]) +const manageType: any = reactive([]) +const typeId: any = ref() onMounted(() => { // 获取装备树 @@ -57,6 +58,7 @@ onMounted(() => { }) // 设备类型树 const deviceTypeTree: any = ref([]) +const oldDeviceTypeTree: any = ref([]) const partTypeTreeProps: any = ref({ children: 'children', label: 'name', @@ -67,7 +69,21 @@ const partTypeTreeProps: any = ref({ const getTypeTreeData = async () => { const res: any = await getEquipmentTypeApi() console.log('treeData==========', res) - deviceTypeTree.value = res.data + oldDeviceTypeTree.value = res.data + deviceTypeTree.value = trimTreeLevels(res.data, 3) + // deviceTypeTree.value = res.data + console.log('🚀 ~ getTypeTreeData ~ 树:', deviceTypeTree.value) +} +const trimTreeLevels = (tree: any, maxDepth: any, currentDepth = 1) => { + return tree.map((node: any) => { + const newNode = { ...node } + if (node.children && currentDepth < maxDepth) { + newNode.children = trimTreeLevels(node.children, maxDepth, currentDepth + 1) + } else { + delete newNode.children + } + return newNode + }); } //装备类目-change const deviceTypeChange = (val: any) => { @@ -170,7 +186,7 @@ const equipmentDeployment = (row: any) => { deviceCount: 1, originaValue: '', itemTypeModel: '', - deviceType: '', + manageType: '', buyPrice: '', unitName: '', code: '', @@ -189,6 +205,7 @@ const equipmentDeployment = (row: any) => { detailsFileList.value = [] insurancePdf.value = [] examinationPdf.value = [] + addAndEditForm.deviceTypeList = [] //装备证书table equipTableList.value = [] @@ -210,7 +227,7 @@ const equipmentDeployment = (row: any) => { }) } - addAndEditForm.deviceTypeList = getSelectId(deviceTypeTree.value, addAndEditForm.typeId) + addAndEditForm.deviceTypeList = getSelectId(deviceTypeTree.value, addAndEditForm.parentId) } // 打开入驻弹框 dialogFormVisibleSettlein.value = true @@ -265,66 +282,11 @@ const deleteRowInfo = async (row: any) => { const getDetailData = async (row: any) => { await getTypeTreeData() const { data: res }: any = await getDetailApi(row.maId) - const { - deviceName, - // deviceTypeList, - deviceCount, - originaValue, - itemTypeModel, - deviceType, - buyPrice, - unitName, - code, - brand, - typeId, - companyId, - productionDate, - dayLeasePrice, - person, - personPhone, - deviceWeight, - checkDate, - checkCycle, - mainFileList, - detailsFileList, - insurancePdf, - examinationPdf, - devInfoProperties, - tableList, - maintenanceAlarmDay, - isZone, - zoneId, - } = res - Object.assign(addAndEditForm, { - deviceName, - deviceCount, - originaValue, - itemTypeModel, - deviceType, - buyPrice, - unitName, - code, - brand, - typeId, - companyId, - productionDate, - dayLeasePrice, - person, - personPhone, - deviceWeight, - checkDate, - checkCycle, - mainFileList, - detailsFileList, - insurancePdf, - examinationPdf, - devInfoProperties, - tableList, - maintenanceAlarmDay, - isZone, - zoneId, + ...res, }) + typeId.value = addAndEditForm.typeId + console.log('🚀 ~ getDetailData ~ typeId:', typeId.value) if (settleinTitle.value == '装备编辑') { Object.assign(addAndEditForm, { @@ -343,7 +305,7 @@ const getDetailData = async (row: any) => { descriptionFormList.value[0].insurancePdfs = insurancePdf descriptionFormList.value[0].examinationPdfs = examinationPdf options.value = [] - addAndEditForm.deviceTypeList = getSelectId(deviceTypeTree.value, addAndEditForm.typeId) + addAndEditForm.deviceTypeList = getSelectId(deviceTypeTree.value, addAndEditForm.parentId) warningDays.value = addAndEditForm.maintenanceAlarmDay // warningDays.value = addAndEditForm.deviceTypeList[addAndEditForm.deviceTypeList.length-1].data.maintenanceAlarmDay // warningDays.value = addAndEditForm.deviceTypeList.maintenanceAlarmDay @@ -524,7 +486,7 @@ const equipmentDeploymentParams: any = ref({ deviceCount: 1, originaValue: '', itemTypeModel: '', - deviceType: '', + manageType: '', buyPrice: '', unitName: '', code: '', @@ -544,18 +506,21 @@ const countDisabled = ref(false) //装备类目-change const dialogTypeCascader = ref() //装备类目-change -const dialogTypeChange = async () => { +const dialogTypeChange = async (val: any) => { + const nodeId = val[val.length - 1] + const nodeList = findNextLevelIds(oldDeviceTypeTree.value, nodeId) + console.log('🚀 ~ dialogTypeChange ~ nodeList:', nodeList) + typeId.value = nodeList ? nodeList[0] : [] options.value = [] const deviceTypeList = dialogTypeCascader.value.getCheckedNodes() - console.log('deviceTypeList', deviceTypeList[0].data) warningDays.value = deviceTypeList[0].data.maintenanceAlarmDay - if (deviceTypeList[0].data.deviceType == 0) { - addAndEditForm.deviceCount = 1 - typeDisabled.value = true - } else { - addAndEditForm.deviceCount = 1 - typeDisabled.value = false - } + // if (deviceTypeList[0].data.manageType == 0) { + // addAndEditForm.deviceCount = 1 + // typeDisabled.value = true + // } else { + // addAndEditForm.deviceCount = 1 + // typeDisabled.value = false + // } if (deviceTypeList[0].data.maTypeProperties == null) { propertyNames.value = [] } else { @@ -585,6 +550,25 @@ const dialogTypeChange = async () => { examinationPdf: [], }) } +const findNextLevelIds = (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) : []; + } + if (node.children) { + const result: any = findNextLevelIds(node.children, targetId); + if (result) return result; + } + } + return null // 没找到 +} +const changeDeviceType = async (val: any) => { + console.log('🚀 ~ changeDeviceType ~ val:', val) + if (val == 0) { + addAndEditForm.deviceCount = 1 + } +} //获取所属公司下拉数据 const getCompanyList = async () => { @@ -618,7 +602,7 @@ const equipRules = ref({ trigger: 'blur', }, ], - deviceType: [ + manageType: [ { required: true, message: '请选择管理方式', @@ -833,9 +817,9 @@ const submitFun = (type: any) => { ) addAndEditForm.devInfoProperties = propertyNames.value - addAndEditForm.typeId = - addAndEditForm.deviceTypeList[addAndEditForm.deviceTypeList.length - 1] - + // addAndEditForm.typeId = + // addAndEditForm.deviceTypeList[addAndEditForm.deviceTypeList.length - 1] + addAndEditForm.typeId = typeId.value let SEND_FUN_API: any = null if (type == 1) { SEND_FUN_API = equipmentAddApi @@ -1067,7 +1051,7 @@ const addAndEditForm = reactive({ deviceCount: 1, originaValue: '', itemTypeModel: '', - deviceType: '', + manageType: '', buyPrice: '', unitName: '', code: '', @@ -1310,7 +1294,7 @@ const onDialogClose = () => { deviceCount: 1, originaValue: '', itemTypeModel: '', - deviceType: '', + manageType: '', buyPrice: '', unitName: '', code: '', @@ -1565,7 +1549,7 @@ const handleDel = (index: any) => { >重置 - 装备新增 @@ -1633,7 +1617,11 @@ const handleDel = (index: any) => { > - + + +