2025-08-02 13:38:04 +08:00
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<el-tree
|
2025-11-03 17:06:38 +08:00
|
|
|
v-loading="loading"
|
2025-08-02 13:38:04 +08:00
|
|
|
:data="treeData"
|
|
|
|
|
:props="treeProps"
|
|
|
|
|
node-key="warehouseId"
|
|
|
|
|
highlight-current
|
|
|
|
|
@node-click="handleNodeClick"
|
|
|
|
|
:expand-on-click-node="false"
|
|
|
|
|
:default-expand-all="true"
|
|
|
|
|
class="stock-tree"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { listWarehouse } from '@/api/wms/warehouse';
|
2025-11-03 17:06:38 +08:00
|
|
|
import { listActualWarehouse } 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',
|
|
|
|
|
label: 'warehouseLabel',
|
|
|
|
|
isLeaf: () => false
|
|
|
|
|
}
|
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: {
|
|
|
|
|
getWarehouseTree() {
|
2025-11-03 17:06:38 +08:00
|
|
|
this.loading = true;
|
|
|
|
|
if (this.warehouseType === 'real') {
|
|
|
|
|
listActualWarehouse({ pageSize: 1000 }).then(response => {
|
|
|
|
|
this.treeData = response.rows.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
warehouseLabel: item.actualWarehouseName
|
|
|
|
|
}))
|
|
|
|
|
this.loading = false;
|
|
|
|
|
// this.treeData = [{ warehouseName: '全部', value: undefined }, ...this.handleTree(response.rows, 'warehouseId', 'parentId')];
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
listWarehouse().then(response => {
|
|
|
|
|
this.treeData = response.data.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
warehouseLabel: item.warehouseName
|
|
|
|
|
}))
|
|
|
|
|
this.loading = false;
|
|
|
|
|
// this.treeData = [{ warehouseName: '全部', value: undefined }, ...this.handleTree(response.data, 'warehouseId', 'parentId')];
|
|
|
|
|
});
|
|
|
|
|
}
|
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>
|
|
|
|
|
|
2025-08-25 11:46:03 +08:00
|
|
|
<!-- <style scoped>
|
2025-08-02 13:38:04 +08:00
|
|
|
.stock-tree-card {
|
|
|
|
|
height: 100%;
|
|
|
|
|
border: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
}
|
|
|
|
|
.stock-tree-title {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
padding: 8px 0;
|
|
|
|
|
}
|
|
|
|
|
.stock-tree {
|
|
|
|
|
min-height: 500px;
|
|
|
|
|
max-height: 80vh;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
}
|
2025-08-25 11:46:03 +08:00
|
|
|
</style> -->
|