280 lines
8.9 KiB
Vue
280 lines
8.9 KiB
Vue
<template>
|
||
<div class="rack-space-management">
|
||
<!-- 货架管理部分 -->
|
||
<div v-if="props.rack && props.rack.type === 'rack'" class="rack-management">
|
||
<!-- 仓位管理部分 -->
|
||
<el-card class="space-management-card">
|
||
<template #header>
|
||
<div class="card-header">
|
||
<span>仓位管理(货架{{ props.rack.name }})</span>
|
||
<span>
|
||
<el-button type="text" size="small" @click="handleAddSpace">
|
||
一键排列拣货路径
|
||
</el-button>
|
||
<el-button type="text" size="small" @click="handleAddSpace">
|
||
打印
|
||
</el-button>
|
||
<el-button type="text" size="small" @click="handleAddSpace">
|
||
修复货架
|
||
</el-button>
|
||
<el-button type="text" size="small" @click="handleAddSpace">
|
||
导出
|
||
</el-button>
|
||
<el-button type="text" size="small" @click="handleAddSpace">
|
||
导入批量修改
|
||
</el-button>
|
||
</span>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 仓位列表 -->
|
||
<el-table :data="rackSpaces" height="100%" style="width: 100%" @row-click="handleSpaceClick"
|
||
highlight-current-row :row-style="rowStyle" :cell-style="cellStyle">
|
||
<el-table-column type="selection"></el-table-column>
|
||
<el-table-column sortable prop="space_code" label="仓位编码" width="120" fixed="left"/>
|
||
<el-table-column prop="custom_name" label="自定义名称" width="120" />
|
||
<el-table-column prop="custom_barcode" label="自定义条码" width="150" />
|
||
<el-table-column prop="column_no" label="组" width="80" />
|
||
<el-table-column prop="row_no" label="层" width="80" />
|
||
<el-table-column prop="level_no" label="格" width="80" />
|
||
<el-table-column label="状态">
|
||
<template #default="{ row }">
|
||
<el-tag :type="spaceStatusStatus(row.space_status)" size="small">
|
||
{{ spaceStatusText(row.space_status) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column sortable prop="pick_sequence" label="拣货顺序" width="100" fixed="right" />
|
||
</el-table>
|
||
|
||
<div class="info">
|
||
<span>货架/实际/可用/禁用:{{ calculateRackTotal() }}/{{ rackSpaces.length }}/{{ canUseSpacecCount }}/{{ canNotUseSpace }}</span>
|
||
<span>有存货的仓位数:{{ useSpaceCount }}</span>
|
||
</div>
|
||
</el-card>
|
||
</div>
|
||
<div v-else class="empty-rack-container">
|
||
<el-empty description="选择货架后查看信息" />
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, watch, computed, } from 'vue'
|
||
import * as warehouseApi from '@/api/warehouse'
|
||
import { ElMessage } from 'element-plus'
|
||
|
||
const props = defineProps({
|
||
rack: { type: Object, default: null },
|
||
warehouse: { type: Object, default: null },
|
||
zone: { type: Object, default: null }
|
||
})
|
||
|
||
const emit = defineEmits(['edit-warehouse','edit-zone','edit-rack','edit-space','space-click','refresh'])
|
||
|
||
const rackSpaces = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const useSpaceCount = ref(0)
|
||
const canUseSpacecCount = ref(0)
|
||
const canNotUseSpace = ref(0)
|
||
|
||
watch(() => props.rack, (newVal) => {
|
||
console.log('货架信息', newVal)
|
||
if (newVal && newVal.type === 'rack') {
|
||
loadRackSpaces()
|
||
}
|
||
}, { immediate: true })
|
||
|
||
watch(() => props.warehouse, (newVal) => {
|
||
console.log('仓库信息', newVal)
|
||
}, { immediate: true })
|
||
|
||
function spaceStatusText(status: string) {
|
||
let text = ''
|
||
switch (status) {
|
||
case 'AVAILABLE': text = '可用'; break
|
||
case 'OCCUPIED': text = '可用/存货'; break
|
||
case 'DISABLED': text = '禁用'; break
|
||
}
|
||
return text
|
||
}
|
||
|
||
function spaceStatusStatus(status: string) {
|
||
let text = ''
|
||
switch (status) {
|
||
case 'AVAILABLE':
|
||
case 'OCCUPIED': text = 'success'; break
|
||
default: text = 'warning'; break
|
||
}
|
||
return text
|
||
}
|
||
|
||
function rowStyle() {
|
||
return { height: '30px' }
|
||
}
|
||
|
||
function cellStyle() {
|
||
return { padding: '0', textAlign: 'center' }
|
||
}
|
||
|
||
function calculateRackTotal() {
|
||
if (!props.rack) return 0
|
||
const { rackColumns = 1, rackRows = 1, rackLevels = 1 } = props.rack.data || {}
|
||
return rackColumns * rackRows * rackLevels
|
||
}
|
||
|
||
async function loadRackSpaces() {
|
||
if (!props.rack || props.rack.type !== 'rack') return
|
||
loading.value = true
|
||
try {
|
||
const response: any = await warehouseApi.getSpacesByRack(props.rack.id)
|
||
if (response.code === 200) {
|
||
rackSpaces.value = response.spaces || []
|
||
useSpaceCount.value = 0
|
||
canUseSpacecCount.value = 0
|
||
canNotUseSpace.value = 0
|
||
rackSpaces.value.forEach(item => {
|
||
switch (item.space_status) {
|
||
case 'AVAILABLE':
|
||
canUseSpacecCount.value++
|
||
break
|
||
case 'OCCUPIED':
|
||
canUseSpacecCount.value++
|
||
useSpaceCount.value++
|
||
break
|
||
default:
|
||
canNotUseSpace.value++
|
||
}
|
||
})
|
||
}
|
||
} catch (error) {
|
||
console.error('加载仓位失败:', error)
|
||
rackSpaces.value = []
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleEditWarehouse() { emit('edit-warehouse', props.warehouse) }
|
||
function handleEditZone() { emit('edit-zone', props.zone) }
|
||
function handleEditRack() { emit('edit-rack', props.rack) }
|
||
|
||
async function handleAddSpace() {
|
||
if (!props.rack || props.rack.type !== 'rack') return
|
||
loading.value = true
|
||
try {
|
||
const response: any = await warehouseApi.createRackWithSpaces(props.rack.id)
|
||
if (response.code === 200) {
|
||
ElMessage.success('货架生成成功')
|
||
await loadRackSpaces()
|
||
}
|
||
} catch (error) {
|
||
console.error('加载仓位失败:', error)
|
||
rackSpaces.value = []
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleEditSpace(space: any) { emit('edit-space', space) }
|
||
|
||
function handleSpaceClick(space: any) { emit('space-click', space) }
|
||
|
||
function refresh() {
|
||
if (props.rack && props.rack.type === 'rack') loadRackSpaces()
|
||
emit('refresh')
|
||
}
|
||
|
||
defineExpose({ loadRackSpaces, refresh })
|
||
</script>
|
||
|
||
<style scoped>
|
||
.rack-space-management {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16px;
|
||
height: 425px;
|
||
width: 600px;
|
||
overflow: hidden;
|
||
|
||
.space-management-card {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
|
||
:deep(.el-card__body) {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
padding: 10px;
|
||
}
|
||
}
|
||
|
||
.el-card__header {
|
||
flex-shrink: 0;
|
||
height: 40px;
|
||
line-height: 40px;
|
||
padding: 0 20px;
|
||
|
||
.card-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
}
|
||
|
||
.rack-management {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.el-table {
|
||
flex: 1;
|
||
width: 100%;
|
||
|
||
::v-deep .el-table__inner-wrapper {
|
||
height: 100% !important;
|
||
}
|
||
|
||
::v-deep .el-table__row {
|
||
cursor: pointer;
|
||
|
||
&:hover {
|
||
background-color: #f5f7fa;
|
||
}
|
||
}
|
||
}
|
||
|
||
.el-table td {
|
||
padding: 0;
|
||
}
|
||
|
||
.info {
|
||
flex-shrink: 0;
|
||
width: 100%;
|
||
height: 30px;
|
||
line-height: 30px;
|
||
font-size: 13px;
|
||
display: flex;
|
||
flex-direction: row;
|
||
justify-content: space-between;
|
||
margin-top: 10px;
|
||
border-top: 1px solid #f0f0f0;
|
||
padding-top: 5px;
|
||
}
|
||
|
||
.empty-rack-container {
|
||
height: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #fff;
|
||
border-radius: 4px;
|
||
border: 1px solid #ebeef5;
|
||
}
|
||
}
|
||
</style> |