286 lines
8.3 KiB
Vue
286 lines
8.3 KiB
Vue
<template>
|
|
<div class="space-list">
|
|
<div class="section-header">
|
|
<span>仓位格子管理</span>
|
|
<div class="header-actions">
|
|
<el-button
|
|
type="primary"
|
|
size="small"
|
|
@click="loadSpaces"
|
|
:loading="loading"
|
|
>
|
|
<i class="el-icon-refresh"></i>
|
|
</el-button>
|
|
<el-button
|
|
type="success"
|
|
size="small"
|
|
@click="generateSpaces"
|
|
:loading="generating"
|
|
v-if="!spaces.length"
|
|
>
|
|
生成仓位
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 仓位列表 -->
|
|
<div class="space-grid" v-if="spaces.length > 0">
|
|
<div class="grid-header">
|
|
<div class="grid-cell">列</div>
|
|
<div class="grid-cell">层</div>
|
|
<div class="grid-cell">格</div>
|
|
<div class="grid-cell">编码</div>
|
|
<div class="grid-cell">状态</div>
|
|
<div class="grid-cell">操作</div>
|
|
</div>
|
|
|
|
<div class="grid-body">
|
|
<div
|
|
v-for="space in sortedSpaces"
|
|
:key="space.id"
|
|
class="space-row"
|
|
:class="{
|
|
'selected': selectedSpaceId === space.id,
|
|
'occupied': space.space_status === 'OCCUPIED'
|
|
}"
|
|
@click="selectSpace(space)"
|
|
>
|
|
<div class="grid-cell">{{ space.column_no }}</div>
|
|
<div class="grid-cell">{{ space.row_no }}</div>
|
|
<div class="grid-cell">{{ space.level_no }}</div>
|
|
<div class="grid-cell">{{ space.space_code }}</div>
|
|
<div class="grid-cell">
|
|
<el-tag
|
|
size="small"
|
|
:type="getStatusTag(space.space_status)"
|
|
>
|
|
{{ getStatusText(space.space_status) }}
|
|
</el-tag>
|
|
</div>
|
|
<div class="grid-cell">
|
|
<el-button
|
|
type="link"
|
|
size="small"
|
|
@click.stop="editSpace(space)"
|
|
>
|
|
<i class="el-icon-edit"></i>
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 分页 -->
|
|
<div class="pagination" v-if="spaces.length > pageSize">
|
|
<el-pagination
|
|
small
|
|
:current-page="currentPage"
|
|
:page-size="pageSize"
|
|
:total="spaces.length"
|
|
layout="prev, pager, next"
|
|
@current-change="handlePageChange"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 空状态 -->
|
|
<div v-else class="empty-state">
|
|
<p>暂无仓位数据</p>
|
|
</div>
|
|
|
|
<!-- 仓位表单 -->
|
|
<space-form
|
|
v-if="showForm"
|
|
:space="currentSpace"
|
|
@close="closeForm"
|
|
@saved="handleSpaceSaved"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, computed, watch, onMounted } from 'vue'
|
|
import * as warehouseApi from '@/api/warehouse/warehouse'
|
|
import SpaceForm from './SpaceForm.vue'
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
const props = defineProps({ rackId: { type: [Number, String], required: true } })
|
|
const emit = defineEmits(['refresh'])
|
|
|
|
const spaces = ref<any[]>([])
|
|
const loading = ref(false)
|
|
const generating = ref(false)
|
|
const currentPage = ref(1)
|
|
const pageSize = ref(10)
|
|
const selectedSpaceId = ref<any>(null)
|
|
const showForm = ref(false)
|
|
const currentSpace = ref<any>(null)
|
|
|
|
const statusMap: any = {
|
|
'AVAILABLE': { tag: 'success', text: '可用' },
|
|
'OCCUPIED': { tag: 'warning', text: '占用' },
|
|
'RESERVED': { tag: 'info', text: '预留' },
|
|
'MAINTENANCE': { tag: 'danger', text: '维护' },
|
|
'DISABLED': { tag: 'info', text: '禁用' }
|
|
}
|
|
|
|
const sortedSpaces = computed(() => {
|
|
return [...spaces.value].sort((a, b) => {
|
|
const colA = parseInt(a.column_no) || 0
|
|
const colB = parseInt(b.column_no) || 0
|
|
if (colA !== colB) return colA - colB
|
|
|
|
const rowA = parseInt(a.row_no) || 0
|
|
const rowB = parseInt(b.row_no) || 0
|
|
if (rowA !== rowB) return rowA - rowB
|
|
|
|
const levelA = parseInt(a.level_no) || 0
|
|
const levelB = parseInt(b.level_no) || 0
|
|
return levelA - levelB
|
|
})
|
|
})
|
|
|
|
const paginatedSpaces = computed(() => {
|
|
const start = (currentPage.value - 1) * pageSize.value
|
|
const end = start + pageSize.value
|
|
return sortedSpaces.value.slice(start, end)
|
|
})
|
|
|
|
async function loadSpaces() {
|
|
loading.value = true
|
|
try {
|
|
const response: any = await warehouseApi.getSpacesByRack(props.rackId)
|
|
if (response.code === 200) {
|
|
spaces.value = response.spaces || []
|
|
ElMessage.success(`加载了 ${spaces.value.length} 个仓位`)
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error('加载仓位失败')
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function generateSpaces() {
|
|
generating.value = true
|
|
try {
|
|
const response: any = await warehouseApi.createRackWithSpaces(props.rackId)
|
|
if (response.code === 200) {
|
|
ElMessage.success('仓位生成成功')
|
|
await loadSpaces()
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error('生成仓位失败')
|
|
} finally {
|
|
generating.value = false
|
|
}
|
|
}
|
|
|
|
function selectSpace(space: any) { selectedSpaceId.value = space.id }
|
|
|
|
function editSpace(space: any) {
|
|
currentSpace.value = space
|
|
showForm.value = true
|
|
}
|
|
|
|
function closeForm() {
|
|
showForm.value = false
|
|
currentSpace.value = null
|
|
}
|
|
|
|
function handleSpaceSaved() {
|
|
closeForm()
|
|
loadSpaces()
|
|
emit('refresh')
|
|
}
|
|
|
|
function getStatusTag(status: string) { return statusMap[status]?.tag || 'info' }
|
|
function getStatusText(status: string) { return statusMap[status]?.text || status }
|
|
|
|
function handlePageChange(page: number) { currentPage.value = page }
|
|
|
|
onMounted(() => { loadSpaces() })
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.space-list {
|
|
.section-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 12px;
|
|
padding-bottom: 8px;
|
|
border-bottom: 1px solid #ebeef5;
|
|
|
|
span {
|
|
font-weight: 500;
|
|
color: #303133;
|
|
}
|
|
}
|
|
|
|
.space-grid {
|
|
.grid-header {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr 2fr 2fr 1fr;
|
|
gap: 8px;
|
|
padding: 8px;
|
|
background: #f8f9fa;
|
|
border-radius: 4px;
|
|
margin-bottom: 8px;
|
|
|
|
.grid-cell {
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: #606266;
|
|
text-align: center;
|
|
}
|
|
}
|
|
|
|
.grid-body {
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
|
|
.space-row {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr 2fr 2fr 1fr;
|
|
gap: 8px;
|
|
padding: 8px;
|
|
border-bottom: 1px solid #ebeef5;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s;
|
|
|
|
&:hover {
|
|
background-color: #f5f7fa;
|
|
}
|
|
|
|
&.selected {
|
|
background-color: #ecf5ff;
|
|
}
|
|
|
|
&.occupied {
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.grid-cell {
|
|
font-size: 12px;
|
|
text-align: center;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
}
|
|
}
|
|
|
|
.pagination {
|
|
margin-top: 12px;
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 32px;
|
|
color: #c0c4cc;
|
|
}
|
|
}
|
|
</style> |