2025-08-02 13:38:04 +08:00
|
|
|
<template>
|
2025-12-05 15:39:25 +08:00
|
|
|
<div>
|
|
|
|
|
<el-tree key="warehouseTree" v-loading="loading" :data="treeData" :props="treeProps" node-key="actualWarehouseId" highlight-current
|
|
|
|
|
@node-click="handleNodeClick" :expand-on-click-node="false" class="stock-tree" />
|
|
|
|
|
</div>
|
2025-08-02 13:38:04 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { listWarehouse } from '@/api/wms/warehouse';
|
2025-12-05 15:39:25 +08:00
|
|
|
// import { listActualWarehouse } from '@/api/wms/actualWarehouse';
|
|
|
|
|
import { treeActualWarehouseTwoLevel } from '@/api/wms/actualWarehouse';
|
2025-08-02 13:38:04 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "WarehouseTree",
|
|
|
|
|
props: {
|
2025-11-03 17:06:38 +08:00
|
|
|
warehouseType: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'real'
|
|
|
|
|
},
|
2025-08-02 13:38:04 +08:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2025-11-03 17:06:38 +08:00
|
|
|
treeData: [],
|
|
|
|
|
loading: true,
|
|
|
|
|
treeProps: {
|
|
|
|
|
children: 'children',
|
2025-12-05 15:39:25 +08:00
|
|
|
label: 'actualWarehouseName',
|
|
|
|
|
isLeaf: 'isLeaf'
|
2025-11-03 17:06:38 +08:00
|
|
|
}
|
2025-08-02 13:38:04 +08:00
|
|
|
};
|
|
|
|
|
},
|
2025-11-03 17:06:38 +08:00
|
|
|
watch: {
|
|
|
|
|
warehouseType: {
|
|
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
this.getWarehouseTree()
|
|
|
|
|
},
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
2025-08-02 13:38:04 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2025-11-24 15:45:08 +08:00
|
|
|
loadChildren(node, resolve) {
|
2025-12-05 15:39:25 +08:00
|
|
|
if (this.warehouseType !== 'real') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-11-24 15:45:08 +08:00
|
|
|
if (node.level === 0) {
|
|
|
|
|
// resolve(this.handleTree(this.treeData, 'warehouseId', 'parentId'));
|
|
|
|
|
} else {
|
|
|
|
|
listActualWarehouse({ parentId: node.data.actualWarehouseId }).then(response => {
|
2025-12-05 15:39:25 +08:00
|
|
|
resolve(response.data);
|
2025-11-24 15:45:08 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-08-02 13:38:04 +08:00
|
|
|
getWarehouseTree() {
|
2025-11-03 17:06:38 +08:00
|
|
|
this.loading = true;
|
|
|
|
|
if (this.warehouseType === 'real') {
|
2025-12-05 15:39:25 +08:00
|
|
|
treeActualWarehouseTwoLevel().then(response => {
|
|
|
|
|
this.treeData = response.data
|
2025-11-03 17:06:38 +08:00
|
|
|
this.loading = false;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
listWarehouse().then(response => {
|
|
|
|
|
this.treeData = response.data.map(item => ({
|
|
|
|
|
...item,
|
2025-12-05 15:39:25 +08:00
|
|
|
actualWarehouseId: item.warehouseId,
|
|
|
|
|
actualWarehouseName: item.warehouseName
|
2025-11-03 17:06:38 +08:00
|
|
|
}))
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-11-24 15:45:08 +08:00
|
|
|
</script>
|