1955 lines
59 KiB
Vue
1955 lines
59 KiB
Vue
<!-- 库位管理(左树 + 右货架行布局) -->
|
||
<!-- eslint-disable vue/no-v-model-argument -->
|
||
<template>
|
||
<div
|
||
class="page-container storage-page"
|
||
ref="pageContainerRef"
|
||
:style="pageContainerStyle"
|
||
v-loading="clearSlotsLoading"
|
||
element-loading-text="正在清空格子..."
|
||
element-loading-background="rgba(255,255,255,0.7)"
|
||
>
|
||
<section class="panel">
|
||
<div class="flex gap-4">
|
||
<!-- 左侧:库位 -->
|
||
<div class="w-[280px] shrink-0 border-r border-[var(--mint-border)] pr-4">
|
||
<div class="panel-top storage-aside__head">
|
||
<h2>库位</h2>
|
||
<el-button type="primary" size="small" @click="handleAddRoot">
|
||
<el-icon><Plus /></el-icon>
|
||
新增
|
||
</el-button>
|
||
</div>
|
||
|
||
<el-input
|
||
v-model="treeKeyword"
|
||
placeholder="搜索节点"
|
||
clearable
|
||
class="storage-tree-search"
|
||
/>
|
||
|
||
<el-tree
|
||
ref="treeRef"
|
||
:data="treeData"
|
||
:props="{ label: 'nodeName', children: 'children' }"
|
||
node-key="id"
|
||
highlight-current
|
||
default-expand-all
|
||
:filter-node-method="filterNode"
|
||
@node-click="handleNodeClick"
|
||
>
|
||
<template #default="{ data }">
|
||
<div class="storage-tree-node">
|
||
<span
|
||
v-if="data.isLeaf === 1 && slotStatsMap[data.id]"
|
||
class="storage-tree-node__stats"
|
||
>
|
||
{{ slotStatsMap[data.id].occupied }}/{{ slotStatsMap[data.id].total }}
|
||
</span>
|
||
<span class="storage-tree-node__name">
|
||
<span v-if="data.nodeCode" class="storage-tree-node__code">{{ data.nodeCode }}</span>
|
||
{{ data.nodeName }}
|
||
</span>
|
||
<span v-if="data.isLeaf === 1" class="storage-tree-node__leaf">存</span>
|
||
<div class="storage-tree-node__actions">
|
||
<button title="新增子节点" @click.stop="handleAddChild(data)">+</button>
|
||
<button title="编辑" @click.stop="handleEditNode(data)">✎</button>
|
||
<button title="删除" @click.stop="handleDeleteNode(data)">×</button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</el-tree>
|
||
</div>
|
||
|
||
<!-- 右侧:格子内容 -->
|
||
<div class="flex-1 min-w-0">
|
||
<template v-if="!selectedNode">
|
||
<el-empty description="请在左侧选择一个叶子节点查看格子" />
|
||
</template>
|
||
|
||
<template v-else-if="selectedNode.isLeaf !== 1">
|
||
<div class="storage-content-header">
|
||
<div>
|
||
<h3>
|
||
{{
|
||
buildTreePathLabelFromFlat(selectedNode.id, flatList, { nameKey: 'nodeName' })
|
||
}}
|
||
</h3>
|
||
<p class="storage-content-subtitle">非叶子节点,请继续选择子节点</p>
|
||
</div>
|
||
</div>
|
||
<el-empty description="此节点下还有子节点,请展开选择叶子节点查看格子" />
|
||
</template>
|
||
|
||
<template v-else>
|
||
<div class="storage-content-header">
|
||
<div>
|
||
<h3>
|
||
{{
|
||
buildTreePathLabelFromFlat(selectedNode.id, flatList, { nameKey: 'nodeName' })
|
||
}}
|
||
</h3>
|
||
<div class="storage-content-stats">
|
||
<span
|
||
>总数 <strong>{{ slotStats.total }}</strong></span
|
||
>
|
||
<span class="stats-dot">·</span>
|
||
<span
|
||
>空闲 <strong>{{ slotStats.empty }}</strong></span
|
||
>
|
||
<span class="stats-dot">·</span>
|
||
<span
|
||
>占用 <strong>{{ slotStats.occupied }}</strong></span
|
||
>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="storage-toolbar">
|
||
<el-button
|
||
type="primary"
|
||
:disabled="slotList.length > 0"
|
||
@click="batchDialogVisible = true"
|
||
>
|
||
批量生成格子
|
||
</el-button>
|
||
<el-button
|
||
v-if="slotList.length > 0"
|
||
class="btn-ghost"
|
||
:loading="clearSlotsLoading"
|
||
@click="handleClearSlots"
|
||
>
|
||
清空格子
|
||
</el-button>
|
||
</div>
|
||
|
||
<div v-if="slotList.length === 0" class="storage-empty-cells">
|
||
<el-empty description="暂无格子" />
|
||
</div>
|
||
|
||
<div v-else class="shelf-scroll-wrapper" v-loading="slotLoading">
|
||
<div class="shelf-container">
|
||
<div v-for="(row, ri) in shelfRows" :key="ri" class="shelf-row-wrapper">
|
||
<div class="shelf-row">
|
||
<div class="shelf-label">{{ row.label }}</div>
|
||
<div class="shelf-cells">
|
||
<div
|
||
class="shelf-cell shelf-cell--add"
|
||
title="在此行前面增加格子"
|
||
@click="handleAddSlotInRow(ri)"
|
||
>
|
||
<span class="add-icon">+</span>
|
||
</div>
|
||
<div
|
||
v-for="(cell, cellIndex) in row.cells"
|
||
:key="cell.id"
|
||
class="shelf-cell"
|
||
:class="{ occupied: cell.slotStatus === '占用' }"
|
||
@click="handleOpenOccupancyDialog(cell)"
|
||
>
|
||
<button
|
||
class="cell-delete-btn"
|
||
@click.stop="handleDeleteSlot(cell)"
|
||
title="删除"
|
||
>×</button
|
||
>
|
||
<span class="cell-code">{{ cell.fullSlotCode || cell.slotCode || '—' }}</span>
|
||
<span v-if="cell.occupiedCount > 0" class="cell-badge">{{
|
||
cell.occupiedCount
|
||
}}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div
|
||
class="shelf-add-row"
|
||
title="在下方新增一行"
|
||
@click="handleOpenAddRowDialog(ri)"
|
||
>
|
||
<span class="add-row-icon">+ 新增行</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 节点新增/编辑弹窗 -->
|
||
<el-dialog
|
||
v-model="nodeDialogVisible"
|
||
:title="nodeDialogTitle"
|
||
width="560px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@close="handleNodeDialogClose"
|
||
>
|
||
<el-form
|
||
ref="nodeFormRef"
|
||
:model="nodeFormData"
|
||
:rules="nodeFormRules"
|
||
label-position="top"
|
||
class="storage-dialog-form"
|
||
scroll-to-error
|
||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="上级节点">
|
||
<el-select
|
||
v-model="nodeFormData.parentId"
|
||
placeholder="请选择上级节点(空为根节点)"
|
||
clearable
|
||
filterable
|
||
>
|
||
<el-option
|
||
v-for="item in flatList"
|
||
:key="item.id"
|
||
:label="buildTreePathLabelFromFlat(item.id, flatList, { nameKey: 'nodeName' })"
|
||
:value="item.id"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="节点名称" prop="nodeName">
|
||
<el-input v-model="nodeFormData.nodeName" placeholder="请输入节点名称" />
|
||
</el-form-item>
|
||
<el-form-item prop="nodeCode">
|
||
<template #label>
|
||
节点编号<span class="form-label-tip">单段字母或数字,不含连字符</span>
|
||
</template>
|
||
<el-input v-model="nodeFormData.nodeCode" placeholder="如 1、03、A" />
|
||
</el-form-item>
|
||
<el-form-item label="节点类型">
|
||
<el-select v-model="nodeFormData.nodeType" placeholder="请选择节点类型">
|
||
<el-option label="设施" value="facility" />
|
||
<el-option label="层" value="layer" />
|
||
<el-option label="盒" value="box" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="是否存储格">
|
||
<el-switch v-model="nodeFormData.isLeaf" :active-value="1" :inactive-value="0" />
|
||
</el-form-item>
|
||
<el-form-item label="排序">
|
||
<el-input-number
|
||
v-model="nodeFormData.orderNum"
|
||
:min="0"
|
||
:step="1"
|
||
controls-position="right"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="备注" class="form-col-span-2">
|
||
<el-input v-model="nodeFormData.remark" placeholder="可选" />
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button class="btn-ghost" @click="nodeDialogVisible = false">
|
||
<el-icon><Close /></el-icon>
|
||
取消
|
||
</el-button>
|
||
<el-button
|
||
class="btn-main"
|
||
type="primary"
|
||
:loading="nodeSubmitLoading"
|
||
@click="handleNodeSubmit"
|
||
>
|
||
<el-icon><Check /></el-icon>
|
||
确定
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 格子编辑弹窗 -->
|
||
<el-dialog
|
||
v-model="slotDialogVisible"
|
||
:title="slotDialogTitle"
|
||
width="480px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@close="handleSlotDialogClose"
|
||
>
|
||
<el-form
|
||
ref="slotFormRef"
|
||
:model="slotFormData"
|
||
:rules="slotFormRules"
|
||
label-position="top"
|
||
class="storage-dialog-form"
|
||
scroll-to-error
|
||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="本地编码(行-列)" prop="slotCode">
|
||
<el-input v-model="slotFormData.slotCode" placeholder="如 1-3" />
|
||
</el-form-item>
|
||
<el-form-item label="格子状态">
|
||
<el-select v-model="slotFormData.slotStatus" placeholder="请选择状态">
|
||
<el-option label="空" value="空" />
|
||
<el-option label="占用" value="占用" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button class="btn-ghost" @click="slotDialogVisible = false">
|
||
<el-icon><Close /></el-icon>
|
||
取消
|
||
</el-button>
|
||
<el-button
|
||
class="btn-main"
|
||
type="primary"
|
||
:loading="slotSubmitLoading"
|
||
@click="handleSlotSubmit"
|
||
>
|
||
<el-icon><Check /></el-icon>
|
||
确定
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 批量生成格子弹窗 -->
|
||
<el-dialog
|
||
v-model="batchDialogVisible"
|
||
title="批量生成格子"
|
||
width="480px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@close="handleBatchDialogClose"
|
||
>
|
||
<el-form
|
||
ref="batchFormRef"
|
||
:model="batchForm"
|
||
label-position="top"
|
||
class="storage-dialog-form"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="行数">
|
||
<el-input
|
||
type="number"
|
||
step="any"
|
||
v-model="batchForm.rows"
|
||
:min="1"
|
||
:max="20"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="列数">
|
||
<el-input
|
||
type="number"
|
||
step="any"
|
||
v-model="batchForm.cols"
|
||
:min="1"
|
||
:max="20"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
<div class="form-col-span-2 storage-batch-preview">
|
||
将生成 <strong>{{ batchForm.rows * batchForm.cols }}</strong> 个格子({{
|
||
batchForm.rows
|
||
}}
|
||
行 × {{ batchForm.cols }} 列)
|
||
<template v-if="batchPreviewCode">
|
||
,示例编号:<strong>{{ batchPreviewCode }}</strong>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button class="btn-ghost" @click="batchDialogVisible = false">
|
||
<el-icon><Close /></el-icon>
|
||
取消
|
||
</el-button>
|
||
<el-button
|
||
class="btn-main"
|
||
type="primary"
|
||
:loading="batchSubmitLoading"
|
||
@click="handleBatchSubmit"
|
||
>
|
||
<el-icon><Check /></el-icon>
|
||
确认生成
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 新增行弹窗 -->
|
||
<el-dialog
|
||
v-model="addRowDialogVisible"
|
||
title="新增行"
|
||
width="400px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@close="handleAddRowDialogClose"
|
||
>
|
||
<el-form :model="addRowForm" label-position="top" class="storage-dialog-form">
|
||
<el-form-item label="列数">
|
||
<el-input
|
||
type="number"
|
||
step="any"
|
||
v-model="addRowForm.cols"
|
||
:min="1"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
<div class="storage-batch-preview">
|
||
将在当前行下方新增 <strong>{{ addRowForm.cols }}</strong> 个格子
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button class="btn-ghost" @click="addRowDialogVisible = false">
|
||
<el-icon><Close /></el-icon>
|
||
取消
|
||
</el-button>
|
||
<el-button
|
||
class="btn-main"
|
||
type="primary"
|
||
:loading="addSlotLoading"
|
||
@click="handleAddRowBelowConfirm"
|
||
>
|
||
<el-icon><Check /></el-icon>
|
||
确认
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 占用明细弹窗 -->
|
||
<el-dialog
|
||
v-model="occupancyDialogVisible"
|
||
:title="occupancyDialogTitle"
|
||
width="1280px"
|
||
class="dialog-form-layout storage-occupancy-dialog"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
>
|
||
<el-tabs v-model="occupancyActiveTab" class="storage-occupancy-tabs">
|
||
<el-tab-pane label="在库物品" name="stored">
|
||
<div class="list-toolbar occupancy-list-toolbar">
|
||
<div class="list-toolbar-row">
|
||
<el-button
|
||
v-if="occupancyTotal === 0"
|
||
class="btn-main"
|
||
type="primary"
|
||
@click="handleOpenStoreDialog"
|
||
>
|
||
<el-icon><Plus /></el-icon>
|
||
入库
|
||
</el-button>
|
||
<span v-else class="occupancy-full-tip">该储物格已有物品在库,一格只能存放一个物品</span>
|
||
</div>
|
||
</div>
|
||
<div class="list-body list-wrap view-inner-table-wrap">
|
||
<el-table
|
||
class="list-table inner-table"
|
||
:data="occupancyList"
|
||
v-loading="occupancyLoading"
|
||
stripe
|
||
row-key="id"
|
||
empty-text="暂无在库物品"
|
||
>
|
||
<el-table-column
|
||
type="index"
|
||
label="序号"
|
||
min-width="68"
|
||
align="center"
|
||
header-align="center"
|
||
:index="(index) => (occupancyPage - 1) * occupancyPageSize + index + 1"
|
||
/>
|
||
<el-table-column label="物品类型" min-width="120" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.itemType === 'cell_product' ? 'primary' : 'info'" size="small">
|
||
{{ row.itemType === 'cell_product' ? '细胞产品' : '其他' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="itemCode"
|
||
label="物品编码"
|
||
min-width="140"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column
|
||
prop="itemName"
|
||
label="物品名称"
|
||
min-width="140"
|
||
align="center"
|
||
header-align="center"
|
||
show-overflow-tooltip
|
||
/>
|
||
<el-table-column label="来源" min-width="120" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
{{
|
||
{ production: '生产入库', manual: '手动入库', transfer: '转移' }[
|
||
row.itemSource
|
||
] || row.itemSource
|
||
}}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="storedAt"
|
||
label="入库时间"
|
||
min-width="170"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column
|
||
label="操作"
|
||
min-width="120"
|
||
fixed="right"
|
||
align="center"
|
||
header-align="center"
|
||
>
|
||
<template #default="{ row }">
|
||
<div style="display: flex; justify-content: center; gap: 8px">
|
||
<el-button class="btn-op-item" @click="handleRemoveOccupancy(row)">
|
||
<el-icon><Top /></el-icon>出库
|
||
</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="pagination list-pager-bar">
|
||
<el-pagination
|
||
:current-page="occupancyPage"
|
||
:page-size="occupancyPageSize"
|
||
:total="occupancyTotal"
|
||
layout="total, prev, pager, next"
|
||
@current-change="(val) => ((occupancyPage = val), loadOccupancies())"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</el-tab-pane>
|
||
|
||
<el-tab-pane label="出入库历史" name="history">
|
||
<div class="list-body list-wrap view-inner-table-wrap">
|
||
<el-table
|
||
class="list-table inner-table"
|
||
:data="historyList"
|
||
v-loading="historyLoading"
|
||
stripe
|
||
row-key="id"
|
||
empty-text="暂无出入库历史"
|
||
>
|
||
<el-table-column
|
||
type="index"
|
||
label="序号"
|
||
min-width="68"
|
||
align="center"
|
||
header-align="center"
|
||
:index="(index) => (historyPage - 1) * historyPageSize + index + 1"
|
||
/>
|
||
<el-table-column label="物品类型" min-width="120" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.itemType === 'cell_product' ? 'primary' : 'info'" size="small">
|
||
{{ row.itemType === 'cell_product' ? '细胞产品' : '其他' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="itemCode"
|
||
label="物品编码"
|
||
min-width="140"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column
|
||
prop="itemName"
|
||
label="物品名称"
|
||
min-width="140"
|
||
align="center"
|
||
header-align="center"
|
||
show-overflow-tooltip
|
||
/>
|
||
<el-table-column label="来源" min-width="120" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
{{
|
||
{ production: '生产入库', manual: '手动入库', transfer: '转移' }[
|
||
row.itemSource
|
||
] || row.itemSource
|
||
}}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="storedAt"
|
||
label="入库时间"
|
||
min-width="170"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column
|
||
prop="removedAt"
|
||
label="出库时间"
|
||
min-width="170"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column label="状态" min-width="100" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
<el-tag
|
||
:type="row.occupancyStatus === 'stored' ? 'success' : 'warning'"
|
||
size="small"
|
||
>
|
||
{{ row.occupancyStatus === 'stored' ? '在库' : '已出库' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="pagination list-pager-bar">
|
||
<el-pagination
|
||
:current-page="historyPage"
|
||
:page-size="historyPageSize"
|
||
:total="historyTotal"
|
||
layout="total, prev, pager, next"
|
||
@current-change="(val) => ((historyPage = val), loadHistory())"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</el-tab-pane>
|
||
|
||
<el-tab-pane label="格子信息" name="info">
|
||
<el-form
|
||
ref="occupancySlotFormRef"
|
||
:model="occupancySlotFormData"
|
||
:rules="occupancySlotFormRules"
|
||
label-position="top"
|
||
class="storage-dialog-form"
|
||
scroll-to-error
|
||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="完整编号" class="form-col-span-2">
|
||
<el-input
|
||
:model-value="currentSlot?.fullSlotCode || '—'"
|
||
readonly
|
||
placeholder="保存后自动生成"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="本地编码(行-列)" prop="slotCode">
|
||
<el-input v-model="occupancySlotFormData.slotCode" placeholder="如 1-3" />
|
||
</el-form-item>
|
||
<el-form-item label="格子状态">
|
||
<el-select v-model="occupancySlotFormData.slotStatus" placeholder="请选择状态">
|
||
<el-option label="空" value="空" />
|
||
<el-option label="占用" value="占用" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="备注" class="form-col-span-2">
|
||
<el-input v-model="occupancySlotFormData.remark" placeholder="可选" />
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
<div class="occupancy-slot-save-bar">
|
||
<el-button
|
||
class="btn-main"
|
||
type="primary"
|
||
:loading="occupancySlotSaving"
|
||
@click="handleOccupancySlotSave"
|
||
>
|
||
<el-icon><Check /></el-icon>
|
||
保存
|
||
</el-button>
|
||
</div>
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</el-dialog>
|
||
|
||
<!-- 手动入库弹窗 -->
|
||
<el-dialog
|
||
v-model="storeDialogVisible"
|
||
title="手动入库"
|
||
width="480px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
append-to-body
|
||
modal-class="protocol-dialog-mask"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
>
|
||
<el-form
|
||
ref="storeFormRef"
|
||
:model="storeFormData"
|
||
:rules="storeFormRules"
|
||
label-position="top"
|
||
>
|
||
<el-form-item label="物品编码" prop="itemCode">
|
||
<el-input v-model="storeFormData.itemCode" placeholder="请输入物品编码" />
|
||
</el-form-item>
|
||
<el-form-item label="物品名称" prop="itemName">
|
||
<el-input v-model="storeFormData.itemName" placeholder="请输入物品名称" />
|
||
</el-form-item>
|
||
<el-form-item label="来源" prop="itemSource">
|
||
<el-select v-model="storeFormData.itemSource" placeholder="请选择来源">
|
||
<el-option label="手动入库" value="manual" />
|
||
<el-option label="转移" value="transfer" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="备注">
|
||
<el-input v-model="storeFormData.remark" type="textarea" :rows="2" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button class="btn-ghost" @click="storeDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="storeSubmitLoading" @click="handleStoreSubmit"
|
||
>确认入库</el-button
|
||
>
|
||
</template>
|
||
</el-dialog>
|
||
</section>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Plus, Close, Check, Top } from '@element-plus/icons-vue'
|
||
import {
|
||
fetchStorageFacilityList,
|
||
fetchCreateStorageFacility,
|
||
fetchUpdateStorageFacility,
|
||
fetchDeleteStorageFacility,
|
||
fetchStorageSlotList,
|
||
fetchBatchCreateSlots,
|
||
fetchClearStorageSlots,
|
||
fetchInsertStorageSlotRow,
|
||
fetchCreateStorageSlot,
|
||
fetchUpdateStorageSlot,
|
||
fetchDeleteStorageSlot,
|
||
fetchSlotOccupancies,
|
||
fetchSlotOccupancyHistory,
|
||
fetchCreateOccupancy,
|
||
fetchRemoveOccupancy
|
||
} from '@/api/admin'
|
||
import { buildTreePathLabelFromFlat } from '@/utils/tree-path'
|
||
import { buildNodeCodePathFromFlat } from '@/utils/storage-slot-options'
|
||
|
||
defineOptions({ name: 'StorageFacility' })
|
||
|
||
// Row labels use sequential numbers (1, 2, 3...)
|
||
|
||
// ==================== 树形数据 ====================
|
||
const loading = ref(false)
|
||
const flatList = ref<any[]>([])
|
||
const treeData = ref<any[]>([])
|
||
const treeRef = ref()
|
||
const treeKeyword = ref('')
|
||
|
||
const getNodeOrderNum = (item: any): number => {
|
||
const raw = item?.orderNum ?? item?.order_num ?? item?.sortOrder ?? item?.sort_order ?? 0
|
||
const parsed = Number(raw)
|
||
return Number.isFinite(parsed) ? parsed : 0
|
||
}
|
||
|
||
const buildTree = (list: any[]) => {
|
||
const map = new Map<string, any>()
|
||
const roots: any[] = []
|
||
list.forEach((item) => {
|
||
map.set(item.id, { ...item, children: [] })
|
||
})
|
||
list.forEach((item) => {
|
||
const node = map.get(item.id)!
|
||
if (item.parentId && item.parentId !== '0' && map.has(item.parentId)) {
|
||
map.get(item.parentId)!.children.push(node)
|
||
} else {
|
||
roots.push(node)
|
||
}
|
||
})
|
||
const sortNodes = (nodes: any[]) => {
|
||
nodes.sort((a, b) => {
|
||
const orderDiff = getNodeOrderNum(a) - getNodeOrderNum(b)
|
||
if (orderDiff !== 0) return orderDiff
|
||
return String(a.nodeName || '').localeCompare(String(b.nodeName || ''), 'zh-Hans-CN')
|
||
})
|
||
nodes.forEach((node) => {
|
||
if (node.children?.length) sortNodes(node.children)
|
||
})
|
||
}
|
||
|
||
sortNodes(roots)
|
||
return roots
|
||
}
|
||
|
||
const loadData = async () => {
|
||
loading.value = true
|
||
try {
|
||
const res: any = await fetchStorageFacilityList()
|
||
const list = res?.list || res || []
|
||
flatList.value = list
|
||
treeData.value = buildTree(list)
|
||
nextTick(loadAllSlotStats)
|
||
} catch (error) {
|
||
console.error('加载库位数据失败:', error)
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
const filterNode = (value: string, data: any) => {
|
||
if (!value) return true
|
||
return data.nodeName?.includes(value)
|
||
}
|
||
|
||
watch(treeKeyword, (val) => {
|
||
treeRef.value?.filter(val)
|
||
})
|
||
|
||
// ==================== 节点选中 → 格子面板 ====================
|
||
const selectedNode = ref<any>(null)
|
||
const slotLoading = ref(false)
|
||
const slotList = ref<any[]>([])
|
||
|
||
// 各叶子节点的格子统计 { id: { total, occupied, empty } }
|
||
const slotStatsMap = ref<Record<string, { total: number; occupied: number; empty: number }>>({})
|
||
|
||
/** 当前选中节点的格子统计 */
|
||
const slotStats = computed(() => {
|
||
const total = slotList.value.length
|
||
const occupied = slotList.value.filter((s) => s.slotStatus === '占用').length
|
||
return { total, occupied, empty: total - occupied }
|
||
})
|
||
|
||
/** slotList 变化时同步更新统计 Map */
|
||
watch(slotList, () => {
|
||
if (selectedNode.value?.id) {
|
||
const total = slotList.value.length
|
||
const occupied = slotList.value.filter((s) => s.slotStatus === '占用').length
|
||
slotStatsMap.value = {
|
||
...slotStatsMap.value,
|
||
[selectedNode.value.id]: { total, occupied, empty: total - occupied }
|
||
}
|
||
}
|
||
})
|
||
|
||
/** 加载所有叶子节点的格子统计 */
|
||
const loadAllSlotStats = async () => {
|
||
const leafNodes = flatList.value.filter((item) => item.isLeaf === 1)
|
||
if (leafNodes.length === 0) return
|
||
const results = await Promise.allSettled(
|
||
leafNodes.map(async (node) => {
|
||
const res: any = await fetchStorageSlotList({ facilityNodeId: node.id })
|
||
const list = res?.list || res || []
|
||
const total = list.length
|
||
const occupied = list.filter((s: any) => s.slotStatus === '占用').length
|
||
return { id: node.id, total, occupied, empty: total - occupied }
|
||
})
|
||
)
|
||
const map: Record<string, any> = { ...slotStatsMap.value }
|
||
results.forEach((r) => {
|
||
if (r.status === 'fulfilled') {
|
||
map[r.value.id] = r.value
|
||
}
|
||
})
|
||
slotStatsMap.value = map
|
||
}
|
||
|
||
const handleNodeClick = (data: any) => {
|
||
selectedNode.value = data
|
||
if (data.isLeaf === 1) {
|
||
loadSlots(data.id)
|
||
} else {
|
||
slotList.value = []
|
||
}
|
||
}
|
||
|
||
const loadSlots = async (facilityNodeId: string) => {
|
||
slotLoading.value = true
|
||
try {
|
||
const res: any = await fetchStorageSlotList({ facilityNodeId })
|
||
slotList.value = res?.list || res || []
|
||
} catch (error) {
|
||
console.error('加载格子数据失败:', error)
|
||
slotList.value = []
|
||
} finally {
|
||
slotLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 货架行计算(按 slotCode 中的行号分组) ====================
|
||
const batchForm = reactive({
|
||
rows: 4,
|
||
cols: 6
|
||
})
|
||
|
||
const batchPreviewCode = computed(() => {
|
||
if (!selectedNode.value?.id) return ''
|
||
const path = buildNodeCodePathFromFlat(selectedNode.value.id, flatList.value)
|
||
if (!path) return ''
|
||
return `${path}-1-1`
|
||
})
|
||
|
||
/** 解析 slotCode "{prefix}{row}-{col}" 格式,提取行号和列号 */
|
||
const parseSlotCode = (code: string): { prefix: string; row: number; col: number } | null => {
|
||
const match = code.match(/^(.*?)(\d+)-(\d+)$/)
|
||
if (!match) return null
|
||
return { prefix: match[1], row: parseInt(match[2], 10), col: parseInt(match[3], 10) }
|
||
}
|
||
|
||
const shelfRows = computed(() => {
|
||
const rowMap = new Map<number, { prefix: string; cells: any[] }>()
|
||
const ungrouped: any[] = []
|
||
|
||
for (const slot of slotList.value) {
|
||
const parsed = parseSlotCode(slot.slotCode || '')
|
||
if (parsed) {
|
||
if (!rowMap.has(parsed.row)) {
|
||
rowMap.set(parsed.row, { prefix: parsed.prefix, cells: [] })
|
||
}
|
||
rowMap.get(parsed.row)!.cells.push(slot)
|
||
} else {
|
||
ungrouped.push(slot)
|
||
}
|
||
}
|
||
|
||
// 按行号排序,每个行内按列号排序
|
||
const result: { label: string; cells: any[]; rowNum: number; prefix: string }[] = []
|
||
const sortedEntries = [...rowMap.entries()].sort(([a], [b]) => a - b)
|
||
|
||
for (const [rowNum, data] of sortedEntries) {
|
||
data.cells.sort((a, b) => {
|
||
const pa = parseSlotCode(a.slotCode || '')
|
||
const pb = parseSlotCode(b.slotCode || '')
|
||
return (pa?.col ?? 0) - (pb?.col ?? 0)
|
||
})
|
||
result.push({
|
||
label: String(result.length + 1),
|
||
cells: data.cells,
|
||
rowNum,
|
||
prefix: data.prefix
|
||
})
|
||
}
|
||
|
||
// 无法解析编码的格子归入末尾
|
||
if (ungrouped.length > 0) {
|
||
result.push({
|
||
label: String(result.length + 1),
|
||
cells: ungrouped,
|
||
rowNum: result.length + 1,
|
||
prefix: ''
|
||
})
|
||
}
|
||
|
||
return result
|
||
})
|
||
|
||
// ==================== 节点弹窗 ====================
|
||
const nodeDialogVisible = ref(false)
|
||
const nodeDialogTitle = ref('新增根节点')
|
||
const isNodeEdit = ref(false)
|
||
const nodeSubmitLoading = ref(false)
|
||
const nodeFormRef = ref()
|
||
|
||
const nodeFormData = reactive({
|
||
id: '',
|
||
parentId: '',
|
||
nodeName: '',
|
||
nodeCode: '',
|
||
nodeType: 'facility',
|
||
isLeaf: 0 as 0 | 1,
|
||
orderNum: 0,
|
||
remark: ''
|
||
})
|
||
|
||
const validateNodeCode = (_rule: unknown, value: string, callback: (err?: Error) => void) => {
|
||
const v = (value || '').trim()
|
||
if (!v) {
|
||
callback(new Error('请输入节点编号'))
|
||
return
|
||
}
|
||
if (!/^[A-Za-z0-9]+$/.test(v)) {
|
||
callback(new Error('编号只能包含字母和数字,不能含连字符'))
|
||
return
|
||
}
|
||
callback()
|
||
}
|
||
|
||
const nodeFormRules = {
|
||
nodeName: [{ required: true, message: '请输入节点名称', trigger: 'blur' }],
|
||
nodeCode: [{ required: true, validator: validateNodeCode, trigger: 'blur' }]
|
||
}
|
||
|
||
const handleAddRoot = () => {
|
||
isNodeEdit.value = false
|
||
nodeDialogTitle.value = '新增根节点'
|
||
Object.assign(nodeFormData, {
|
||
id: '',
|
||
parentId: '',
|
||
nodeName: '',
|
||
nodeCode: '',
|
||
nodeType: 'facility',
|
||
isLeaf: 0,
|
||
orderNum: 0,
|
||
remark: ''
|
||
})
|
||
nodeDialogVisible.value = true
|
||
nextTick(() => nodeFormRef.value?.clearValidate?.())
|
||
}
|
||
|
||
const handleAddChild = (data: any) => {
|
||
isNodeEdit.value = false
|
||
nodeDialogTitle.value = '新增子节点'
|
||
Object.assign(nodeFormData, {
|
||
id: '',
|
||
parentId: data.id,
|
||
nodeName: '',
|
||
nodeCode: '',
|
||
nodeType: 'layer',
|
||
isLeaf: 0,
|
||
orderNum: 0,
|
||
remark: ''
|
||
})
|
||
nodeDialogVisible.value = true
|
||
nextTick(() => nodeFormRef.value?.clearValidate?.())
|
||
}
|
||
|
||
const handleEditNode = (data: any) => {
|
||
isNodeEdit.value = true
|
||
nodeDialogTitle.value = '编辑节点'
|
||
Object.assign(nodeFormData, {
|
||
id: data.id,
|
||
parentId: data.parentId && data.parentId !== '0' ? data.parentId : '',
|
||
nodeName: data.nodeName || '',
|
||
nodeCode: data.nodeCode || '',
|
||
nodeType: data.nodeType || 'facility',
|
||
isLeaf: data.isLeaf ?? 0,
|
||
orderNum: getNodeOrderNum(data),
|
||
remark: data.remark || ''
|
||
})
|
||
nodeDialogVisible.value = true
|
||
nextTick(() => nodeFormRef.value?.clearValidate?.())
|
||
}
|
||
|
||
const handleNodeSubmit = async () => {
|
||
await nodeFormRef.value?.validate?.()
|
||
nodeSubmitLoading.value = true
|
||
try {
|
||
const payload = {
|
||
parentId: nodeFormData.parentId || undefined,
|
||
nodeName: nodeFormData.nodeName.trim(),
|
||
nodeCode: nodeFormData.nodeCode.trim(),
|
||
nodeType: nodeFormData.nodeType,
|
||
isLeaf: nodeFormData.isLeaf,
|
||
orderNum: Number(nodeFormData.orderNum) || 0,
|
||
remark: nodeFormData.remark?.trim() || undefined
|
||
}
|
||
if (isNodeEdit.value && nodeFormData.id) {
|
||
await fetchUpdateStorageFacility(nodeFormData.id, payload)
|
||
} else {
|
||
await fetchCreateStorageFacility(payload)
|
||
}
|
||
ElMessage.success(isNodeEdit.value ? '更新成功' : '创建成功')
|
||
nodeDialogVisible.value = false
|
||
await loadData()
|
||
} catch {
|
||
/* 校验或接口错误已由全局处理 */
|
||
} finally {
|
||
nodeSubmitLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleNodeDialogClose = () => {
|
||
Object.assign(nodeFormData, {
|
||
id: '',
|
||
parentId: '',
|
||
nodeName: '',
|
||
nodeCode: '',
|
||
nodeType: 'facility',
|
||
isLeaf: 0,
|
||
orderNum: 0,
|
||
remark: ''
|
||
})
|
||
nodeFormRef.value?.clearValidate?.()
|
||
}
|
||
|
||
const handleDeleteNode = async (data: any) => {
|
||
try {
|
||
const hasChildren = data.children?.length > 0
|
||
const msg = hasChildren
|
||
? '该节点下有子节点,删除将一并删除。确定继续吗?'
|
||
: '确定要删除该节点吗?'
|
||
await ElMessageBox.confirm(msg, '提示', { type: 'warning' })
|
||
await fetchDeleteStorageFacility(data.id)
|
||
ElMessage.success('删除成功')
|
||
if (selectedNode.value?.id === data.id) {
|
||
selectedNode.value = null
|
||
slotList.value = []
|
||
}
|
||
await loadData()
|
||
} catch (error: any) {
|
||
if (error !== 'cancel') console.error('删除失败:', error)
|
||
}
|
||
}
|
||
|
||
// ==================== 格子弹窗 ====================
|
||
const slotDialogVisible = ref(false)
|
||
const slotDialogTitle = ref('编辑格子')
|
||
const isSlotEdit = ref(false)
|
||
const slotSubmitLoading = ref(false)
|
||
const slotFormRef = ref()
|
||
const editingSlotId = ref<string | null>(null)
|
||
|
||
const slotFormData = reactive({
|
||
slotCode: '',
|
||
slotStatus: '空',
|
||
remark: ''
|
||
})
|
||
|
||
const slotFormRules = {
|
||
slotCode: [{ required: true, message: '请输入格子编码', trigger: 'blur' }]
|
||
}
|
||
|
||
const handleEditSlot = (row: any) => {
|
||
isSlotEdit.value = true
|
||
slotDialogTitle.value = '编辑格子'
|
||
editingSlotId.value = row.id
|
||
Object.assign(slotFormData, {
|
||
slotCode: row.slotCode || '',
|
||
slotStatus: row.slotStatus || '空',
|
||
remark: row.remark || ''
|
||
})
|
||
slotDialogVisible.value = true
|
||
nextTick(() => slotFormRef.value?.clearValidate?.())
|
||
}
|
||
|
||
const handleSlotSubmit = async () => {
|
||
await slotFormRef.value?.validate?.()
|
||
slotSubmitLoading.value = true
|
||
try {
|
||
const payload = {
|
||
facilityNodeId: selectedNode.value?.id,
|
||
slotCode: slotFormData.slotCode.trim(),
|
||
slotStatus: slotFormData.slotStatus,
|
||
remark: slotFormData.remark?.trim() || undefined
|
||
}
|
||
if (isSlotEdit.value && editingSlotId.value) {
|
||
await fetchUpdateStorageSlot(editingSlotId.value, payload)
|
||
}
|
||
ElMessage.success('更新成功')
|
||
slotDialogVisible.value = false
|
||
if (selectedNode.value?.id) await loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 校验或接口错误已由全局处理 */
|
||
} finally {
|
||
slotSubmitLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleSlotDialogClose = () => {
|
||
Object.assign(slotFormData, { slotCode: '', slotStatus: '空', remark: '' })
|
||
editingSlotId.value = null
|
||
slotFormRef.value?.clearValidate?.()
|
||
}
|
||
|
||
const handleDeleteSlot = async (row: any) => {
|
||
try {
|
||
await ElMessageBox.confirm('确定要删除该格子吗?', '提示', { type: 'warning' })
|
||
await fetchDeleteStorageSlot(row.id)
|
||
ElMessage.success('删除成功')
|
||
if (selectedNode.value?.id) await loadSlots(selectedNode.value.id)
|
||
} catch (error: any) {
|
||
if (error !== 'cancel') console.error('删除失败:', error)
|
||
}
|
||
}
|
||
|
||
// ==================== 批量生成 ====================
|
||
const batchDialogVisible = ref(false)
|
||
const batchSubmitLoading = ref(false)
|
||
const batchFormRef = ref()
|
||
|
||
const handleBatchSubmit = async () => {
|
||
if (!selectedNode.value?.id) return
|
||
batchSubmitLoading.value = true
|
||
try {
|
||
await fetchBatchCreateSlots({
|
||
facilityNodeId: selectedNode.value.id,
|
||
rows: batchForm.rows,
|
||
cols: batchForm.cols
|
||
})
|
||
ElMessage.success('批量生成成功')
|
||
batchDialogVisible.value = false
|
||
await loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 校验或接口错误已由全局处理 */
|
||
} finally {
|
||
batchSubmitLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleBatchDialogClose = () => {
|
||
batchForm.rows = 4
|
||
batchForm.cols = 6
|
||
}
|
||
|
||
// ==================== 清空格子 ====================
|
||
const clearSlotsLoading = ref(false)
|
||
|
||
const handleClearSlots = async () => {
|
||
if (slotList.value.length === 0) return
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定清空当前节点下所有 ${slotList.value.length} 个格子吗?此操作不可恢复。`,
|
||
'提示',
|
||
{ type: 'warning' }
|
||
)
|
||
clearSlotsLoading.value = true
|
||
const res: any = await fetchClearStorageSlots({ facilityNodeId: selectedNode.value.id })
|
||
const clearedCount = Number(res?.clearedCount ?? 0)
|
||
ElMessage.success(clearedCount > 0 ? `已清空 ${clearedCount} 个格子` : '已清空所有格子')
|
||
await loadSlots(selectedNode.value.id)
|
||
} catch (error: any) {
|
||
if (error !== 'cancel') console.error('清空失败:', error)
|
||
} finally {
|
||
clearSlotsLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 单独新增行/格子 ====================
|
||
const addSlotLoading = ref(false)
|
||
|
||
/** 在指定行前面追加一个格子 */
|
||
const handleAddSlotInRow = async (rowIndex: number) => {
|
||
if (!selectedNode.value?.id || addSlotLoading.value) return
|
||
const row = shelfRows.value[rowIndex]
|
||
if (!row) return
|
||
|
||
// 计算该行下一个列号
|
||
let nextCol = 1
|
||
for (const cell of row.cells) {
|
||
const parsed = parseSlotCode(cell.slotCode || '')
|
||
if (parsed && parsed.col >= nextCol) nextCol = parsed.col + 1
|
||
}
|
||
|
||
const slotCode = `${row.rowNum}-${nextCol}`
|
||
addSlotLoading.value = true
|
||
try {
|
||
await fetchCreateStorageSlot({
|
||
facilityNodeId: selectedNode.value.id,
|
||
slotCode,
|
||
slotStatus: '空'
|
||
})
|
||
ElMessage.success('新增格子成功')
|
||
await loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 校验或接口错误已由全局处理 */
|
||
} finally {
|
||
addSlotLoading.value = false
|
||
}
|
||
}
|
||
|
||
/** 在指定行下方新增一行(弹窗确认,含行号重排插入) */
|
||
const addRowDialogVisible = ref(false)
|
||
const addRowForm = reactive({ cols: 4 })
|
||
const addRowTargetIndex = ref(-1)
|
||
|
||
const handleOpenAddRowDialog = (rowIndex: number) => {
|
||
addRowTargetIndex.value = rowIndex
|
||
addRowForm.cols = 4
|
||
addRowDialogVisible.value = true
|
||
}
|
||
|
||
const handleAddRowDialogClose = () => {
|
||
addRowForm.cols = 4
|
||
addRowTargetIndex.value = -1
|
||
}
|
||
|
||
const handleAddRowBelowConfirm = async () => {
|
||
if (!selectedNode.value?.id || addSlotLoading.value) return
|
||
const rowIndex = addRowTargetIndex.value
|
||
if (rowIndex < 0 || rowIndex >= shelfRows.value.length) return
|
||
|
||
const currentRow = shelfRows.value[rowIndex]
|
||
const numCols = Number(addRowForm.cols)
|
||
if (!Number.isFinite(numCols)) {
|
||
ElMessage.warning('列数必须是数字')
|
||
return
|
||
}
|
||
const normalizedCols = Math.floor(numCols)
|
||
if (normalizedCols < 1) {
|
||
ElMessage.warning('列数必须大于 0')
|
||
return
|
||
}
|
||
|
||
addSlotLoading.value = true
|
||
try {
|
||
await fetchInsertStorageSlotRow({
|
||
facilityNodeId: selectedNode.value.id,
|
||
afterRowNum: currentRow.rowNum,
|
||
cols: normalizedCols
|
||
})
|
||
|
||
ElMessage.success('新增行成功')
|
||
addRowDialogVisible.value = false
|
||
await loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 校验或接口错误已由全局处理 */
|
||
} finally {
|
||
addSlotLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 容器高度自适应 ====================
|
||
const pageContainerRef = ref<HTMLElement>()
|
||
const pageContainerStyle = ref<Record<string, string>>({})
|
||
|
||
const updateContainerHeight = () => {
|
||
const el = pageContainerRef.value
|
||
if (!el) return
|
||
const top = Math.ceil(el.getBoundingClientRect().top)
|
||
// 减去父容器 .layout-content 的 bottom padding
|
||
const parentPaddingBottom = parseInt(getComputedStyle(el.parentElement!).paddingBottom) || 0
|
||
pageContainerStyle.value = {
|
||
height: `calc(100vh - ${top + parentPaddingBottom}px - 15px)`,
|
||
overflow: 'hidden'
|
||
}
|
||
}
|
||
|
||
// ==================== 占用明细弹窗 ====================
|
||
const occupancyDialogVisible = ref(false)
|
||
const occupancyDialogTitle = ref('')
|
||
const occupancyActiveTab = ref('stored')
|
||
const currentSlot = ref<any>(null)
|
||
const occupancyLoading = ref(false)
|
||
const occupancyList = ref<any[]>([])
|
||
const occupancyTotal = ref(0)
|
||
const occupancyPage = ref(1)
|
||
const occupancyPageSize = 20
|
||
|
||
const historyLoading = ref(false)
|
||
const historyList = ref<any[]>([])
|
||
const historyTotal = ref(0)
|
||
const historyPage = ref(1)
|
||
const historyPageSize = 20
|
||
|
||
// 手动入库弹窗
|
||
const storeDialogVisible = ref(false)
|
||
const storeSubmitLoading = ref(false)
|
||
const storeFormRef = ref()
|
||
const storeFormData = reactive({
|
||
itemCode: '',
|
||
itemName: '',
|
||
itemSource: 'manual',
|
||
remark: ''
|
||
})
|
||
const storeFormRules = {
|
||
itemCode: [{ required: true, message: '请输入物品编码', trigger: 'blur' }],
|
||
itemName: [{ required: true, message: '请输入物品名称', trigger: 'blur' }],
|
||
itemSource: [{ required: true, message: '请选择来源', trigger: 'change' }]
|
||
}
|
||
|
||
// 格子信息 tab
|
||
const occupancySlotFormRef = ref()
|
||
const occupancySlotSaving = ref(false)
|
||
const occupancySlotFormData = reactive({
|
||
slotCode: '',
|
||
slotStatus: '空',
|
||
remark: ''
|
||
})
|
||
const occupancySlotFormRules = {
|
||
slotCode: [{ required: true, message: '请输入格子编码', trigger: 'blur' }]
|
||
}
|
||
|
||
const handleOccupancySlotSave = async () => {
|
||
await occupancySlotFormRef.value?.validate?.()
|
||
if (!currentSlot.value) return
|
||
occupancySlotSaving.value = true
|
||
try {
|
||
await fetchUpdateStorageSlot(currentSlot.value.id, {
|
||
slotCode: occupancySlotFormData.slotCode.trim(),
|
||
slotStatus: occupancySlotFormData.slotStatus,
|
||
remark: occupancySlotFormData.remark?.trim() || undefined
|
||
})
|
||
ElMessage.success('保存成功')
|
||
if (selectedNode.value?.id) await loadSlots(selectedNode.value.id)
|
||
// 同步更新 currentSlot 以反映最新值
|
||
const refreshed = slotList.value.find((s: any) => s.id === currentSlot.value.id)
|
||
if (refreshed) {
|
||
currentSlot.value = refreshed
|
||
Object.assign(occupancySlotFormData, {
|
||
slotCode: refreshed.slotCode || '',
|
||
slotStatus: refreshed.slotStatus || '空',
|
||
remark: refreshed.remark || ''
|
||
})
|
||
}
|
||
} catch {
|
||
/* 错误已全局处理 */
|
||
} finally {
|
||
occupancySlotSaving.value = false
|
||
}
|
||
}
|
||
|
||
const handleOpenOccupancyDialog = (cell: any) => {
|
||
currentSlot.value = cell
|
||
occupancyDialogTitle.value = `储物格明细 — ${cell.fullSlotCode || cell.slotCode || cell.id}`
|
||
occupancyActiveTab.value = 'stored'
|
||
occupancyPage.value = 1
|
||
historyPage.value = 1
|
||
// 初始化格子编辑表单
|
||
Object.assign(occupancySlotFormData, {
|
||
slotCode: cell.slotCode || '',
|
||
slotStatus: cell.slotStatus || '空',
|
||
remark: cell.remark || ''
|
||
})
|
||
occupancyDialogVisible.value = true
|
||
nextTick(() => occupancySlotFormRef.value?.clearValidate?.())
|
||
loadOccupancies()
|
||
loadHistory()
|
||
}
|
||
|
||
const loadOccupancies = async () => {
|
||
if (!currentSlot.value) return
|
||
occupancyLoading.value = true
|
||
try {
|
||
const res: any = await fetchSlotOccupancies({
|
||
slotId: currentSlot.value.id,
|
||
occupancyStatus: 'stored',
|
||
page: occupancyPage.value,
|
||
pageSize: occupancyPageSize
|
||
})
|
||
const data = res?.data || res || {}
|
||
occupancyList.value = data.items || data.list || []
|
||
occupancyTotal.value = data.total || 0
|
||
} catch {
|
||
occupancyList.value = []
|
||
} finally {
|
||
occupancyLoading.value = false
|
||
}
|
||
}
|
||
|
||
const loadHistory = async () => {
|
||
if (!currentSlot.value) return
|
||
historyLoading.value = true
|
||
try {
|
||
const res: any = await fetchSlotOccupancyHistory({
|
||
slotId: currentSlot.value.id,
|
||
page: historyPage.value,
|
||
pageSize: historyPageSize
|
||
})
|
||
const data = res?.data || res || {}
|
||
historyList.value = data.items || data.list || []
|
||
historyTotal.value = data.total || 0
|
||
} catch {
|
||
historyList.value = []
|
||
} finally {
|
||
historyLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleOpenStoreDialog = () => {
|
||
Object.assign(storeFormData, { itemCode: '', itemName: '', itemSource: 'manual', remark: '' })
|
||
storeDialogVisible.value = true
|
||
nextTick(() => storeFormRef.value?.clearValidate?.())
|
||
}
|
||
|
||
const handleStoreSubmit = async () => {
|
||
await storeFormRef.value?.validate?.()
|
||
if (!currentSlot.value) return
|
||
storeSubmitLoading.value = true
|
||
try {
|
||
await fetchCreateOccupancy({
|
||
slotId: currentSlot.value.id,
|
||
itemType: 'other',
|
||
itemCode: storeFormData.itemCode.trim(),
|
||
itemName: storeFormData.itemName.trim(),
|
||
itemSource: storeFormData.itemSource,
|
||
remark: storeFormData.remark?.trim() || undefined
|
||
})
|
||
ElMessage.success('入库成功')
|
||
storeDialogVisible.value = false
|
||
loadOccupancies()
|
||
loadHistory()
|
||
if (selectedNode.value?.id) loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 错误已全局处理 */
|
||
} finally {
|
||
storeSubmitLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleRemoveOccupancy = async (row: any) => {
|
||
try {
|
||
await ElMessageBox.confirm(`确认将「${row.itemName || row.itemCode}」出库?`, '出库确认', {
|
||
type: 'warning'
|
||
})
|
||
await fetchRemoveOccupancy(row.id)
|
||
ElMessage.success('出库成功')
|
||
loadOccupancies()
|
||
loadHistory()
|
||
if (selectedNode.value?.id) loadSlots(selectedNode.value.id)
|
||
} catch {
|
||
/* 取消或错误 */
|
||
}
|
||
}
|
||
|
||
// ==================== 初始化 ====================
|
||
onMounted(() => {
|
||
loadData()
|
||
nextTick(updateContainerHeight)
|
||
window.addEventListener('resize', updateContainerHeight)
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
window.removeEventListener('resize', updateContainerHeight)
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* Full-height layout: panel stops 15px from viewport bottom */
|
||
.storage-page {
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: unset !important;
|
||
}
|
||
|
||
.page-head {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.panel {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 0;
|
||
|
||
/* The flex row (left tree + right content) */
|
||
> .flex {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
}
|
||
|
||
/* Left tree area — scroll independently */
|
||
.panel > .flex > :first-child {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.panel > .flex > :first-child :deep(.el-tree) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
scrollbar-width: none;
|
||
|
||
&::-webkit-scrollbar {
|
||
display: none;
|
||
}
|
||
}
|
||
|
||
/* Right content area — scroll independently */
|
||
.panel > .flex > :last-child {
|
||
overflow-y: auto;
|
||
padding: 0 4px;
|
||
scrollbar-width: none;
|
||
|
||
&::-webkit-scrollbar {
|
||
display: none;
|
||
}
|
||
}
|
||
|
||
.storage-aside__head {
|
||
flex-direction: column;
|
||
align-items: stretch;
|
||
justify-content: flex-start;
|
||
flex-wrap: nowrap;
|
||
gap: 8px;
|
||
}
|
||
|
||
.storage-tree-search {
|
||
margin: 10px auto 12px;
|
||
width: calc(100% - 32px);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.storage-tree-node {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
flex: 1;
|
||
font-size: 13px;
|
||
overflow: hidden;
|
||
|
||
&__stats {
|
||
font-size: 10px;
|
||
padding: 1px 5px;
|
||
border-radius: 3px;
|
||
background: #d1fae5;
|
||
color: #065f46;
|
||
flex-shrink: 0;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
&__name {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
&__code {
|
||
display: inline-block;
|
||
margin-right: 4px;
|
||
padding: 0 5px;
|
||
border-radius: 3px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
background: var(--primary-bg, #ecfdf5);
|
||
color: var(--primary-dark, #059669);
|
||
vertical-align: baseline;
|
||
}
|
||
|
||
&__leaf {
|
||
font-size: 11px;
|
||
padding: 1px 6px;
|
||
border-radius: 3px;
|
||
background: #e8f4ee;
|
||
color: #065f46;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
&__actions {
|
||
display: flex;
|
||
gap: 2px;
|
||
margin-left: auto;
|
||
opacity: 0;
|
||
transition: opacity 0.15s;
|
||
flex-shrink: 0;
|
||
|
||
button {
|
||
background: none;
|
||
border: none;
|
||
cursor: pointer;
|
||
padding: 2px 4px;
|
||
font-size: 12px;
|
||
color: #909399;
|
||
line-height: 1;
|
||
|
||
&:hover {
|
||
color: #047857;
|
||
}
|
||
}
|
||
}
|
||
|
||
&:hover .storage-tree-node__actions {
|
||
opacity: 1;
|
||
}
|
||
}
|
||
|
||
:deep(.el-tree-node__content) {
|
||
&:hover .storage-tree-node__actions {
|
||
opacity: 1;
|
||
}
|
||
}
|
||
|
||
.storage-content-header {
|
||
margin-top: 10px;
|
||
margin-bottom: 16px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 1px solid #f0f0f0;
|
||
}
|
||
|
||
.storage-content-stats {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
margin-top: 4px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
|
||
strong {
|
||
color: #303133;
|
||
}
|
||
|
||
.stats-dot {
|
||
color: #dcdfe6;
|
||
}
|
||
}
|
||
|
||
.storage-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.storage-empty-cells {
|
||
padding: 20px 0;
|
||
}
|
||
|
||
.storage-dialog-form {
|
||
:deep(.el-form-item) {
|
||
margin-bottom: 0;
|
||
}
|
||
}
|
||
|
||
.storage-batch-preview {
|
||
background: #e8f4ee;
|
||
border-radius: 6px;
|
||
padding: 10px 14px;
|
||
font-size: 13px;
|
||
color: #065f46;
|
||
margin-top: 4px;
|
||
}
|
||
|
||
/* Shelf layout — scroll wrapper for overflow */
|
||
.shelf-scroll-wrapper {
|
||
overflow: auto;
|
||
max-height: 100%;
|
||
}
|
||
|
||
.shelf-container {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0;
|
||
}
|
||
|
||
.shelf-row-wrapper {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.shelf-row {
|
||
display: flex;
|
||
align-items: stretch;
|
||
}
|
||
|
||
.shelf-add-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
padding: 4px 0 4px 32px;
|
||
cursor: pointer;
|
||
opacity: 0;
|
||
transition: opacity 0.15s;
|
||
|
||
.shelf-row-wrapper:hover & {
|
||
opacity: 1;
|
||
}
|
||
|
||
.add-row-icon {
|
||
font-size: 12px;
|
||
color: #6bb99a;
|
||
padding: 2px 12px;
|
||
border: 1px dashed #a8d4c4;
|
||
border-radius: 4px;
|
||
transition: all 0.15s;
|
||
}
|
||
|
||
&:hover .add-row-icon {
|
||
color: #047857;
|
||
border-color: #047857;
|
||
background: #e8f4ee;
|
||
}
|
||
}
|
||
|
||
.shelf-label {
|
||
width: 36px;
|
||
flex-shrink: 0;
|
||
background: #ea580c;
|
||
color: #fff;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
border-radius: 4px 0 0 4px;
|
||
}
|
||
|
||
.shelf-cells {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
}
|
||
|
||
.shelf-cell {
|
||
width: 80px;
|
||
height: 80px;
|
||
border: 1px solid #fed7aa;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
transition: all 0.15s;
|
||
position: relative;
|
||
border-radius: 4px;
|
||
flex-shrink: 0;
|
||
|
||
&:hover {
|
||
background: #fff7ed;
|
||
}
|
||
|
||
/* 占用状态 — 深橙背景 */
|
||
&.occupied {
|
||
background: #ea580c;
|
||
border-color: #c2410c;
|
||
|
||
&:hover {
|
||
background: #c2410c;
|
||
}
|
||
|
||
.cell-code {
|
||
color: #fff;
|
||
}
|
||
}
|
||
|
||
/* 新增格子按钮 */
|
||
&--add {
|
||
border: 1px dashed #fdba74;
|
||
background: transparent;
|
||
|
||
&:hover {
|
||
background: #fff7ed;
|
||
border-color: #f97316;
|
||
}
|
||
|
||
.add-icon {
|
||
font-size: 32px;
|
||
color: #fb923c;
|
||
line-height: 1;
|
||
}
|
||
|
||
&:hover .add-icon {
|
||
color: #f97316;
|
||
}
|
||
}
|
||
}
|
||
|
||
.cell-delete-btn {
|
||
position: absolute;
|
||
top: 0;
|
||
right: 0;
|
||
width: 22px;
|
||
height: 22px;
|
||
border: none;
|
||
border-radius: 0 4px 0 4px;
|
||
background: rgba(245, 108, 108, 0.85);
|
||
color: #fff;
|
||
font-size: 14px;
|
||
line-height: 22px;
|
||
text-align: center;
|
||
cursor: pointer;
|
||
padding: 0;
|
||
opacity: 0;
|
||
transition: opacity 0.15s;
|
||
z-index: 1;
|
||
|
||
&:hover {
|
||
background: #f56c6c;
|
||
}
|
||
|
||
.shelf-cell:hover & {
|
||
opacity: 1;
|
||
}
|
||
}
|
||
|
||
.cell-code {
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
text-align: center;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
max-width: 72px;
|
||
padding: 0 4px;
|
||
}
|
||
|
||
.cell-badge {
|
||
position: absolute;
|
||
top: 4px;
|
||
right: 4px;
|
||
min-width: 20px;
|
||
height: 20px;
|
||
line-height: 20px;
|
||
font-size: 11px;
|
||
text-align: center;
|
||
color: #fff;
|
||
background: #f56c6c;
|
||
border-radius: 8px;
|
||
padding: 0 4px;
|
||
}
|
||
|
||
.occupancy-list-toolbar {
|
||
margin-bottom: 12px;
|
||
padding-bottom: 0;
|
||
border-bottom: none;
|
||
}
|
||
|
||
.occupancy-full-tip {
|
||
font-size: 13px;
|
||
color: var(--mint-text-muted, #64748b);
|
||
}
|
||
|
||
:deep(.el-dialog.storage-occupancy-dialog) {
|
||
min-height: min(720px, calc(100vh - 100px));
|
||
}
|
||
|
||
.storage-occupancy-tabs {
|
||
:deep(.el-tabs__content) {
|
||
min-height: 520px;
|
||
}
|
||
}
|
||
|
||
.view-inner-table-wrap.list-body.list-wrap {
|
||
margin-top: 0;
|
||
border: 1px solid var(--mint-border, #e2e8f0);
|
||
border-radius: var(--mint-radius, 10px);
|
||
overflow: hidden;
|
||
background: #fff;
|
||
|
||
:deep(.el-table) {
|
||
--el-table-header-bg-color: var(--mint-table-head, #f8fafc);
|
||
--el-table-border-color: var(--mint-border, #e2e8f0);
|
||
--el-table-row-hover-bg-color: var(--mint-row-hover, #f0fdf4);
|
||
--el-table-text-color: var(--mint-text, #0f172a);
|
||
--el-table-header-text-color: var(--mint-text-muted, #64748b);
|
||
font-size: 14px;
|
||
}
|
||
|
||
:deep(.el-table th.el-table__cell) {
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: var(--mint-text-muted, #64748b);
|
||
}
|
||
|
||
:deep(.el-table td.el-table__cell) {
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
color: var(--mint-text, #0f172a);
|
||
}
|
||
|
||
:deep(.el-empty) {
|
||
padding: 24px 0;
|
||
}
|
||
|
||
.pagination.list-pager-bar {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
}
|
||
|
||
.occupancy-slot-save-bar {
|
||
margin-top: 24px;
|
||
padding-top: 16px;
|
||
border-top: 1px solid var(--el-border-color-lighter);
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
</style>
|