575 lines
17 KiB
Vue
575 lines
17 KiB
Vue
<template>
|
||
<div class="storage-entry-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="250px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<el-button size="small" type="primary" @click="loadData">刷新</el-button>
|
||
<!-- <el-button size="small" @click="handleCreateEntry">新建入库单</el-button> -->
|
||
<el-button size="small" :disabled="!hasSelection" @click="confirmBatchCancel">批量作废</el-button>
|
||
<el-button size="small" :loading="exportLoading" @click="handleExport">导出</el-button>
|
||
<el-button size="small" @click="handleImport">导入</el-button>
|
||
<!-- <el-button>是否按批次显示</el-button> -->
|
||
|
||
</div>
|
||
|
||
<div class="toolbar-right">
|
||
<span class="toolbar-label">按批次查询</span>
|
||
<el-select v-model="groupByBatch" size="small" style="width:120px" @change="handleGroupByBatchChange">
|
||
<el-option label="否" :value="false" />
|
||
<el-option label="是" :value="true" />
|
||
</el-select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="入库单列表"
|
||
:data="list"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:show-selection="true"
|
||
:loading="loading"
|
||
:queryTime="queryTime"
|
||
@current-change="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@selection-change="onSelectionChange"
|
||
>
|
||
<template #column-expiry_date="{ row }">
|
||
<span :class="{ 'expiry-date-expired': row.is_shelf_life_warning_triggered }">
|
||
{{ row.expiry_date || '--' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-expiry_remaining_days="{ row }">
|
||
<span :class="{ 'expiry-date-expired': row.is_shelf_life_warning_triggered }">
|
||
{{ row.expiry_remaining_days ?? '--' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-inventory_warning_level="{ row }">
|
||
<span class="inventory-warning-level" :style="{ color: row.inventory_warning_color || '#909399' }">
|
||
{{ row.inventory_warning_level || '--' }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-inventory_warning_tip_text="{ row }">
|
||
<span>{{ row.inventory_warning_tip_text || '--' }}</span>
|
||
</template>
|
||
|
||
<template #column-shelf_life_days="{ row }">
|
||
<span>{{ row.shelf_life_days ?? '--' }}</span>
|
||
</template>
|
||
|
||
<template #column-sale_ban_period="{ row }">
|
||
<span>{{ row.sale_ban_period ?? '--' }}</span>
|
||
</template>
|
||
|
||
<template #column-order_status="{ row }">
|
||
<el-tag v-if="row.order_status" size="small" :type="orderStatusTagType(row.order_status)">
|
||
{{ orderStatusLabel(row.order_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-is_batch_mgmt_enabled="{ row }">
|
||
<div style="text-align:center">
|
||
<el-tag :type="(row.is_batch_mgmt_enabled === true || String(row.is_batch_mgmt_enabled).toLowerCase() === 'y' || String(row.is_batch_mgmt_enabled) === '1') ? 'success' : 'info'" size="small">
|
||
{{ (row.is_batch_mgmt_enabled === true || String(row.is_batch_mgmt_enabled).toLowerCase() === 'y' || String(row.is_batch_mgmt_enabled) === '1') ? '是' : '否' }}
|
||
</el-tag>
|
||
</div>
|
||
</template>
|
||
|
||
<template #column-batch_count="{ row }">
|
||
<div style="text-align:center">{{ row.batch_count || 0 }}</div>
|
||
</template>
|
||
|
||
<template #column-status="{ row }">
|
||
<el-tag v-if="row.status" size="small">
|
||
{{ row.status }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无入库单</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
|
||
<div class="lower-level" v-if="selectedEntryId" :class="tableSize">
|
||
<div class="detail-header">
|
||
<el-tabs v-model="activeTab" class="detail-tab">
|
||
<el-tab-pane label="库存明细" name="details" />
|
||
<!-- <el-tab-pane label="操作日志" name="logs" /> -->
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<KeepAlive>
|
||
<component
|
||
:is="activeComponent"
|
||
:id="selectedEntryId"
|
||
:row="selectedRow"
|
||
:group-by-batch="groupByBatch"
|
||
@refresh="loadData"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="no-selection" v-else>
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import * as indexApi from '@/api/index/index'
|
||
// import * as entryApi from '@/api/storage.entry/entry'
|
||
import * as inventoryApi from '@/api/storage.inventory/inventory'
|
||
|
||
import {
|
||
availableFields,
|
||
productstockColums,
|
||
} from './inventory-config'
|
||
|
||
import entrydetail from './component/panelstockdetail.vue'
|
||
import log from './component/log.vue'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(availableFields)))
|
||
|
||
const activeTab = ref('details')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const exportLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const groupByBatch = ref(false)
|
||
const columns = computed(() => {
|
||
const cols: any[] = JSON.parse(JSON.stringify(productstockColums))
|
||
if (groupByBatch.value) {
|
||
if (!cols.find((c: any) => c.prop === 'batch_no')) {
|
||
const batchCol = { prop: 'batch_no', label: '批次号', width: '120' }
|
||
const idx = cols.findIndex((c: any) => c.prop === 'item_name')
|
||
if (idx >= 0) cols.splice(idx + 1, 0, batchCol)
|
||
else cols.push(batchCol)
|
||
}
|
||
|
||
const warningColumns = [
|
||
{ prop: 'expiry_remaining_days', label: '剩余有效期', width: '110' },
|
||
{ prop: 'inventory_warning_level', label: '预警等级', width: '110' },
|
||
{ prop: 'inventory_warning_tip_text', label: '预警提示', width: '160' }
|
||
]
|
||
const expiryIdx = cols.findIndex((x: any) => x.prop === 'expiry_date')
|
||
for (let i = warningColumns.length - 1; i >= 0; i--) {
|
||
const c = warningColumns[i]
|
||
if (!c) continue
|
||
if (cols.find((x: any) => x.prop === c.prop)) continue
|
||
if (expiryIdx >= 0) cols.splice(expiryIdx + 1, 0, c)
|
||
else cols.push(c)
|
||
}
|
||
|
||
return cols
|
||
}
|
||
return cols.filter(
|
||
(col: any) =>
|
||
![
|
||
'production_date',
|
||
'expiry_date',
|
||
'shelf_life_days',
|
||
'sale_ban_period',
|
||
'expiry_remaining_days',
|
||
'inventory_warning_level',
|
||
'inventory_warning_tip_text'
|
||
].includes(col.prop)
|
||
)
|
||
})
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedEntryId = ref<number | string | null>(null)
|
||
|
||
const componentMap: Record<string, any> = {
|
||
details: entrydetail,
|
||
logs: log
|
||
}
|
||
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
/** 按批次列表用:根据行标识生成稳定的模拟保质期/禁售期展示 */
|
||
function mockBatchShelfLifeFields(rowKey: string) {
|
||
let hash = 0
|
||
for (let i = 0; i < rowKey.length; i++) {
|
||
hash = (hash * 31 + rowKey.charCodeAt(i)) >>> 0
|
||
}
|
||
const shelfLifeDays = 90 + (hash % 271)
|
||
const saleBanDays = 3 + (hash % 28)
|
||
return {
|
||
shelf_life_days: `${shelfLifeDays}天`,
|
||
sale_ban_period: `到期前${saleBanDays}天`
|
||
}
|
||
}
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedEntryId.value) || null
|
||
})
|
||
|
||
onMounted(() => {
|
||
loadData()
|
||
loadFilterData()
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
|
||
try {
|
||
const params: any = {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where: scanBox.value?.getConditions?.() || {},
|
||
group_by_batch: groupByBatch.value
|
||
}
|
||
|
||
const res: any = await inventoryApi.getInventoryList(params)
|
||
if (res && (res.code === 200 || res.code === 1 || res.flag === 'success')) {
|
||
const data = res.data || res
|
||
const rows = Array.isArray(data.list) ? data.list : []
|
||
|
||
list.value = rows.map((item: any) => {
|
||
const rowId = groupByBatch.value
|
||
? `${item.stock_id}-${item.space_id}-${item.batch_no || item.id || ''}`
|
||
: `${item.stock_id}-${item.space_id}`
|
||
const mockShelf = groupByBatch.value ? mockBatchShelfLifeFields(rowId) : null
|
||
|
||
return {
|
||
id: rowId,
|
||
stock_id: item.stock_id,
|
||
item_code: item.stock?.item_code || '',
|
||
item_name: item.stock?.item_name || '',
|
||
batch_no: item.batch_no || item.batch?.batch_no || '',
|
||
production_date: item.production_date || item.batch?.production_date || '',
|
||
expiry_date: item.expiry_date || item.batch?.expiry_date || '',
|
||
shelf_life_days: mockShelf?.shelf_life_days ?? '',
|
||
sale_ban_period: mockShelf?.sale_ban_period ?? '',
|
||
expiry_remaining_days: item.expiry_remaining_days,
|
||
is_shelf_life_warning_triggered: Boolean(item.is_shelf_life_warning_triggered),
|
||
space_code: item.space?.space_code || item.space?.custom_name || '',
|
||
store_name: item.store?.company_name || item.store_id || '',
|
||
inventory_type: item.inventory_type,
|
||
quantity: item.quantity,
|
||
available_quantity: item.available_quantity,
|
||
locked_quantity: item.locked_quantity,
|
||
last_inbound_time: item.last_inbound_time,
|
||
batch_count: Number(item.batch_count || 0),
|
||
is_batch_mgmt_enabled: item.stock?.is_batch_mgmt_enabled,
|
||
inventory_warning_level: item.inventory_warning_level || '',
|
||
inventory_warning_color: item.inventory_warning_color || '',
|
||
inventory_warning_tip_text: item.inventory_warning_tip_text || '',
|
||
// preserve original structures for child components that need full network shape
|
||
stock: item.stock || null,
|
||
space: item.space || null,
|
||
storage_id: item.storage_id || item.id || null,
|
||
space_id: item.space_id || null,
|
||
__raw: item
|
||
}
|
||
})
|
||
|
||
const pager = data.pagination || {}
|
||
pagination.total = pager.total || data.total || list.value.length
|
||
} else {
|
||
list.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e) {
|
||
console.error('获取库存列表失败', e)
|
||
ElMessage.error('加载库存列表失败')
|
||
list.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
async function loadFilterData() {
|
||
try {
|
||
const [storesRes, presetRes]: any = await Promise.all([
|
||
indexApi.loadStores({ type: 'entry' }),
|
||
indexApi.fastWhereTree('entry')
|
||
])
|
||
if (storesRes && storesRes.code === 200) {
|
||
const f = availableFieldsRef.find((i: any) => i.value === 'store_id')
|
||
if (f) f.options = storesRes.stores || []
|
||
}
|
||
if (presetRes && presetRes.code === 200) {
|
||
presetTree.value = presetRes.presetTree || []
|
||
}
|
||
} catch (e) {
|
||
console.error('加载筛选配置失败', e)
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleConditionClear = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
}
|
||
loadData()
|
||
}
|
||
|
||
function onSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
hasSelection.value = selectionRows.value.length > 0
|
||
}
|
||
|
||
async function handleRowClick(row: any) {
|
||
selectedEntryId.value = row?.id || null
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleGroupByBatchChange() {
|
||
pagination.currentPage = 1
|
||
selectedEntryId.value = null
|
||
loadData()
|
||
}
|
||
|
||
function handleCreateEntry() {
|
||
ElMessage.info('新建入库单')
|
||
}
|
||
|
||
|
||
async function confirmBatchCancel() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先选择要作废的入库单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(`确定要批量作废 ${selectionRows.value.length} 个入库单吗?`, '确认', { type: 'warning' })
|
||
// 调用作废 API
|
||
ElMessage.success('操作成功')
|
||
loadData()
|
||
} catch (e) {}
|
||
}
|
||
|
||
async function handleExport() {
|
||
exportLoading.value = true
|
||
setTimeout(() => {
|
||
exportLoading.value = false
|
||
ElMessage.success('导出成功')
|
||
}, 1000)
|
||
}
|
||
|
||
function handleImport() {
|
||
ElMessage.info('导入功能')
|
||
}
|
||
|
||
// 状态翻译映射
|
||
const ORDER_STATUS_MAP: Record<string, string> = {
|
||
CREATED: '待处理',
|
||
CREATING: '创建中',
|
||
PARTIAL_RECEIVED: '部分入库',
|
||
COMPLETED: '已完成',
|
||
CANCELLED: '已取消',
|
||
CLOSED: '已关闭',
|
||
PENDING: '待处理',
|
||
WAITING: '等待中'
|
||
}
|
||
const ORDER_STATUS_TAG: Record<string, string> = {
|
||
COMPLETED: 'success',
|
||
PARTIAL_RECEIVED: 'warning',
|
||
CREATED: 'info',
|
||
CREATING: 'info',
|
||
CANCELLED: 'danger',
|
||
CLOSED: 'danger'
|
||
}
|
||
function orderStatusLabel(val: string) {
|
||
return ORDER_STATUS_MAP[val] || val
|
||
}
|
||
function orderStatusTagType(val: string): any {
|
||
return ORDER_STATUS_TAG[val] || ''
|
||
}
|
||
|
||
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.storage-entry-container {
|
||
display: flex;
|
||
height: calc(100vh - 130px);
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 10px;
|
||
overflow: hidden;
|
||
|
||
.toolbar {
|
||
padding: 5px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
background-color: #fff;
|
||
}
|
||
|
||
.toolbar-right {
|
||
display: flex;
|
||
flex-direction: row;
|
||
gap: 8px;
|
||
height: 30px;
|
||
align-items: center;
|
||
|
||
.toolbar-label {
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
}
|
||
|
||
.expiry-date-expired {
|
||
color: #f56c6c;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.inventory-warning-level {
|
||
font-weight: 600;
|
||
}
|
||
|
||
.upper-wrapper {
|
||
flex: 1;
|
||
min-height: 0;
|
||
/* 不允许 upper-wrapper 自身滚动,保证页面布局不随数据滚动 */
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 在 inventory 页面内覆盖 UpperTable,使表格容器填满可用高度,表体滚动,表头与分页固定 */
|
||
.upper-wrapper :deep(.upper-table-container) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.upper-wrapper :deep(.upper-table-container) :deep(.table-container) {
|
||
/* 取消 UpperTable 的固定像素高度,改为弹性填充 */
|
||
height: auto !important;
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
overflow: hidden; /* 交由 el-table__body-wrapper 控制滚动 */
|
||
}
|
||
|
||
/* 表头粘性,始终可见 */
|
||
.upper-wrapper :deep(.el-table__header-wrapper) {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 3;
|
||
background: #fff;
|
||
}
|
||
|
||
/* 表格 body 使用自身滚动条 */
|
||
.upper-wrapper :deep(.el-table__body-wrapper) {
|
||
overflow: auto;
|
||
min-height: 0;
|
||
}
|
||
|
||
.lower-level {
|
||
flex: 0 0 40%;
|
||
height: 40%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
|
||
.detail-header {
|
||
padding: 0 10px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
background-color: #fafafa;
|
||
|
||
.detail-tab {
|
||
margin-bottom: -1px;
|
||
|
||
:deep(.el-tabs__header) { margin: 0; }
|
||
:deep(.el-tabs__item) {
|
||
height: 32px;
|
||
line-height: 32px;
|
||
font-size: 13px;
|
||
}
|
||
:deep(.el-tabs__nav-wrap::after) { height: 1px; }
|
||
}
|
||
}
|
||
|
||
.detail-container {
|
||
flex: 1;
|
||
overflow: auto;
|
||
padding: 10px;
|
||
}
|
||
}
|
||
|
||
.no-selection {
|
||
flex: 0 0 40%;
|
||
height: 40%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #909399;
|
||
background-color: #fff;
|
||
.empty-tip { text-align: center; font-size: 14px; }
|
||
}
|
||
}
|
||
}
|
||
</style>
|