530 lines
15 KiB
Vue
530 lines
15 KiB
Vue
<template>
|
||
<div class="storage-entry-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="320px"
|
||
: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 size="small" type="success" :disabled="!hasSelection" :loading="quickPutawayLoading" @click="handleQuickPutaway">快捷入库</el-button>
|
||
</div>
|
||
|
||
<!-- <div class="toolbar-right">
|
||
<el-input size="small" placeholder="搜索入库单号" v-model="quickSearch" style="width:220px" @keyup.enter.native="onQuickSearch" />
|
||
</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-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-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"
|
||
@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'
|
||
// import * as entryApi from '@/api/storage/entry'
|
||
import * as inventoryApi from '@/api/storage/inventory'
|
||
import * as receivingApi from '@/api/storage/receiving'
|
||
|
||
import {
|
||
availableFields,
|
||
productstockColums,
|
||
} from './entry-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 quickPutawayLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const columns = ref(productstockColums)
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedEntryId = ref<number | string | null>(null)
|
||
|
||
const quickSearch = ref('')
|
||
|
||
const componentMap: Record<string, any> = {
|
||
details: entrydetail,
|
||
logs: log
|
||
}
|
||
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
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?.() || {}
|
||
}
|
||
|
||
// 适配库存模块的搜索字段
|
||
if (quickSearch.value) {
|
||
params.where = { ...(params.where || {}), stock_id: quickSearch.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) => ({
|
||
id: item.stock_id + '-' + item.space_id, // 复合 ID
|
||
stock_id: item.stock_id,
|
||
item_code: item.stock?.item_code || '',
|
||
item_name: item.stock?.item_name || '',
|
||
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: item.batch_count
|
||
}))
|
||
|
||
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 onQuickSearch() {
|
||
pagination.currentPage = 1
|
||
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] || ''
|
||
}
|
||
|
||
async function handleQuickPutaway() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要快捷入库的入库单')
|
||
return
|
||
}
|
||
|
||
quickPutawayLoading.value = true
|
||
// 逐行校验:通过 purchase_order_code 查询收货单,验证状态与匹配状态
|
||
const validRows: Array<{ entry: any; receivingId: number }> = []
|
||
const errors: string[] = []
|
||
|
||
try {
|
||
for (const row of selectionRows.value) {
|
||
const receivingNumber = row.purchase_order_code
|
||
if (!receivingNumber) {
|
||
errors.push(`入库单【${row.entry_order_code || row.id}】无单据编号,无法查询收货单`)
|
||
continue
|
||
}
|
||
let rcvRes: any
|
||
try {
|
||
rcvRes = await receivingApi.getReceivingList({ where: { receiving_number: receivingNumber } })
|
||
} catch {
|
||
errors.push(`入库单【${row.entry_order_code}】查询收货单失败`)
|
||
continue
|
||
}
|
||
const rcvList = rcvRes?.data?.list ?? rcvRes?.data ?? []
|
||
if (!rcvList.length) {
|
||
errors.push(`入库单【${row.entry_order_code}】未找到对应收货单(单据编号:${receivingNumber})`)
|
||
continue
|
||
}
|
||
const rcv = rcvList[0]
|
||
const isCompleted = (rcv.status || '').toLowerCase() === 'completed'
|
||
const isAllMatched = (rcv.detail_status || '').toLowerCase() === 'all_matched'
|
||
if (!isCompleted) {
|
||
errors.push(`入库单【${row.entry_order_code}】对应收货单收货未完成(当前状态:${rcv.status || '未知'})`)
|
||
continue
|
||
}
|
||
if (!isAllMatched) {
|
||
errors.push(`入库单【${row.entry_order_code}】对应收货单明细匹配未完成(当前明细状态:${rcv.detail_status || '未全部匹配'})`)
|
||
continue
|
||
}
|
||
validRows.push({ entry: row, receivingId: rcv.id })
|
||
}
|
||
} finally {
|
||
if (!validRows.length || errors.length) {
|
||
quickPutawayLoading.value = false
|
||
}
|
||
}
|
||
|
||
if (errors.length) {
|
||
ElMessageBox.alert(errors.join('\n'), '校验未通过,无法快捷入库', { type: 'error' })
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`即将对以下 ${validRows.length} 条入库单执行快捷入库上架:\n${validRows.map(r => r.entry.entry_order_code).join('\n')}`,
|
||
'快捷入库确认',
|
||
{ type: 'warning', confirmButtonText: '确定入库', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
quickPutawayLoading.value = false
|
||
return
|
||
}
|
||
|
||
quickPutawayLoading.value = true
|
||
const failList: string[] = []
|
||
try {
|
||
for (const { entry, receivingId } of validRows) {
|
||
try {
|
||
const res: any = await inventoryApi.quickPutaway({ receiving_id: receivingId })
|
||
if (!res || (res.code !== 200 && res.status !== 'success' && res.flag !== 'success')) {
|
||
failList.push(`${entry.entry_order_code}:${res?.message || res?.msg || '接口返回失败'}`)
|
||
}
|
||
} catch (e: any) {
|
||
failList.push(`${entry.entry_order_code}:${e?.message || '请求异常'}`)
|
||
}
|
||
}
|
||
if (failList.length) {
|
||
ElMessage.error(`${failList.length} 条入库单执行失败:\n${failList.join('\n')}`)
|
||
} else {
|
||
ElMessage.success(`${validRows.length} 条入库单快捷入库成功!`)
|
||
}
|
||
loadData()
|
||
} finally {
|
||
quickPutawayLoading.value = false
|
||
}
|
||
}
|
||
</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: 15px;
|
||
height: 30px;
|
||
align-items: center;
|
||
}
|
||
|
||
.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>
|