WEB/src/views/warehouse/WarehouseTree.vue
2026-03-20 18:18:53 +08:00

97 lines
2.2 KiB
Vue

<template>
<el-card class="warehouse-tree-card">
<template #header>
<div class="clearfix">
<span>仓库列表</span>
<el-button type="text" @click="emit('add')">添加仓库</el-button>
</div>
</template>
<div class="tree-container">
<el-tree
ref="treeRef"
:data="props.warehouseList"
node-key="id"
:props="treeProps"
:expand-on-click-node="false"
:highlight-current="true"
@node-click="handleNodeClick"
>
<template #default="{ node, data }">
<span class="tree-node">
<el-icon><office-building /></el-icon>
<span class="node-label">{{ data.label }}</span>
</span>
</template>
</el-tree>
</div>
</el-card>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { OfficeBuilding } from '@element-plus/icons-vue'
const props = defineProps({
warehouseList: { type: Array, default: () => [] }
})
const emit = defineEmits(['add', 'select'])
const treeRef = ref(null)
const treeProps = {
children: 'children',
label: 'name'
}
onMounted(() => {
console.log(props.warehouseList)
})
function handleNodeClick(data: any) {
emit('select', data)
}
</script>
<style scoped>
.warehouse-tree-card {
height: 220px;
display:flex;
flex-direction: column;
.el-card__header {
padding: 0;
height:40px;
line-height: 40px;
padding-left: 20px;
.clearfix{
display:flex;
flex-direction: row;
justify-content: space-between;
}
}
.el-card__body{
flex:1;
height: 10px;
}
.tree-container {
height: 100%;
overflow-y: auto;
.tree-node {
display: flex;
align-items: center;
font-size: 14px;
i {
margin-right: 6px;
color: #409EFF;
}
.node-label {
flex: 1;
}
}
}
}
</style>