Files
klp-oa/klp-ui/src/components/KLPService/WarehouseTree/index.vue

85 lines
2.3 KiB
Vue
Raw Normal View History

2025-08-02 13:38:04 +08:00
<template>
<el-tree v-loading="loading" :data="treeData" :props="treeProps" node-key="warehouseId" highlight-current
@node-click="handleNodeClick" :expand-on-click-node="false"
:lazy="this.warehouseType === 'real'" :load="loadChildren" class="stock-tree" />
2025-08-02 13:38:04 +08:00
</template>
<script>
import { listWarehouse } from '@/api/wms/warehouse';
import { listActualWarehouse } from '@/api/wms/actualWarehouse';
2025-08-02 13:38:04 +08:00
export default {
name: "WarehouseTree",
props: {
warehouseType: {
type: String,
default: 'real'
},
2025-08-02 13:38:04 +08:00
},
data() {
return {
treeData: [],
loading: true,
treeProps: {
children: 'children',
label: 'warehouseLabel',
isLeaf: () => false
}
2025-08-02 13:38:04 +08:00
};
},
watch: {
warehouseType: {
handler(newVal, oldVal) {
this.getWarehouseTree()
},
immediate: true
}
2025-08-02 13:38:04 +08:00
},
methods: {
loadChildren(node, resolve) {
console.log(node);
if (node.level === 0) {
// resolve(this.handleTree(this.treeData, 'warehouseId', 'parentId'));
} else {
listActualWarehouse({ parentId: node.data.actualWarehouseId }).then(response => {
resolve(response.data.map(item => ({
...item,
warehouseLabel: item.actualWarehouseName
})));
});
}
},
2025-08-02 13:38:04 +08:00
getWarehouseTree() {
this.loading = true;
if (this.warehouseType === 'real') {
listActualWarehouse({ parentId: 0 }).then(response => {
this.treeData = response.data.map(item => ({
...item,
warehouseLabel: item.actualWarehouseName
}))
this.loading = false;
});
} else {
listWarehouse().then(response => {
this.treeData = response.data.map(item => ({
...item,
warehouseLabel: item.warehouseName
}))
this.loading = false;
});
}
2025-08-02 13:38:04 +08:00
},
handleTree(data, id, parentId) {
const cloneData = JSON.parse(JSON.stringify(data));
return cloneData.filter(father => {
const branchArr = cloneData.filter(child => father[id] === child[parentId]);
if (branchArr.length > 0) father.children = branchArr;
return father[parentId] === 0 || father[parentId] === null;
});
},
handleNodeClick(node) {
this.$emit('node-click', node);
}
}
};
</script>