535 lines
14 KiB
Vue
535 lines
14 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>
|
||
</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 :type="getStatusType(row.order_status)" size="small">
|
||
{{ translateField('order_status', row.order_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-order_type="{ row }">
|
||
<span>{{ translateField('order_type', row.order_type) }}</span>
|
||
</template>
|
||
|
||
<template #column-sync_status="{ row }">
|
||
<el-tag :type="getSyncStatusType(row.sync_status)" size="small">
|
||
{{ translateField('sync_status', row.sync_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="operate" />
|
||
<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 {
|
||
availableFields,
|
||
entryColums,
|
||
} from './entry-config'
|
||
|
||
import entrydetail from './component/entrydetail.vue'
|
||
import log from './component/log.vue'
|
||
import entryoperate from './component/entryoperate.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 columns = ref(entryColums)
|
||
|
||
|
||
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,
|
||
operate: entryoperate
|
||
}
|
||
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedEntryId.value) || null
|
||
})
|
||
|
||
function translateField(fieldValue: string, value: any) {
|
||
const field = availableFieldsRef.find((f: any) => f.value === fieldValue)
|
||
if (field && field.options) {
|
||
const option = field.options.find((opt: any) => opt.value === value)
|
||
return option ? option.label : value
|
||
}
|
||
return value
|
||
}
|
||
|
||
function getStatusType(status: string) {
|
||
const map: Record<string, string> = {
|
||
'CREATED': 'info',
|
||
'PENDING': 'warning',
|
||
'PARTIAL': 'primary',
|
||
'COMPLETED': 'success',
|
||
'CANCELLED': 'danger'
|
||
}
|
||
return map[status] || ''
|
||
}
|
||
|
||
function getSyncStatusType(status: string) {
|
||
const map: Record<string, string> = {
|
||
'PENDING': 'info',
|
||
'SYNCING': 'primary',
|
||
'SUCCESS': 'success',
|
||
'FAIL': 'danger'
|
||
}
|
||
return map[status] || ''
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadData()
|
||
loadFilterData()
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const params = {
|
||
page: pagination.currentPage,
|
||
page_size: pagination.pageSize,
|
||
quick_search: quickSearch.value,
|
||
...(scanBox.value?.getConditions() || {})
|
||
}
|
||
|
||
let useMock = false
|
||
try {
|
||
const res = await entryApi.getEntryList(params)
|
||
if (res && res.code === 200 && res.data && res.data.length > 0) {
|
||
list.value = res.data
|
||
pagination.total = res.total || res.data.length
|
||
} else {
|
||
useMock = true
|
||
console.log('API未返回数据,准备使用模拟数据')
|
||
}
|
||
} catch (apiError) {
|
||
console.warn('API调用失败,改用模拟数据', apiError)
|
||
useMock = true
|
||
}
|
||
|
||
if (useMock) {
|
||
const mockData = [
|
||
{
|
||
id: 90,
|
||
entry_order_code: '2885-2011062548597596161',
|
||
order_type: 'CGRK',
|
||
purchase_order_code: '',
|
||
total_order_lines: 1,
|
||
order_create_time: '2026-01-13 13:07:36',
|
||
expect_start_time: '2026-01-13 13:07:36',
|
||
expect_end_time: '2026-01-13 13:07:36',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
express_code: '',
|
||
supplier_code: '',
|
||
supplier_name: '',
|
||
source_type: 'QM',
|
||
order_status: 'COMPLETED',
|
||
sync_status: 'SUCCESS',
|
||
warehouse_id: 100000,
|
||
store_id: 1000016,
|
||
store_name: '花颜物语',
|
||
warehouse_name: '天豹2',
|
||
status: '已完成'
|
||
},
|
||
{
|
||
id: 93,
|
||
entry_order_code: '2885-2011043642256453634',
|
||
order_type: 'CGRK',
|
||
purchase_order_code: '',
|
||
total_order_lines: 1,
|
||
order_create_time: '2026-01-13 13:17:13',
|
||
expect_start_time: '2026-01-13 13:17:13',
|
||
expect_end_time: '2026-01-13 13:17:13',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
express_code: '',
|
||
supplier_code: '',
|
||
supplier_name: '',
|
||
source_type: 'QM',
|
||
order_status: 'COMPLETED',
|
||
sync_status: 'SUCCESS',
|
||
warehouse_id: 100000,
|
||
store_id: 1000016,
|
||
store_name: '花颜物语',
|
||
warehouse_name: '天豹2',
|
||
status: '已完成'
|
||
},
|
||
{
|
||
id: 95,
|
||
entry_order_code: 'CGW2601201120',
|
||
order_type: 'CGRK',
|
||
purchase_order_code: '',
|
||
total_order_lines: 1,
|
||
order_create_time: '2026-01-20 12:48:05',
|
||
expect_start_time: '2026-01-20 12:52:34',
|
||
expect_end_time: '2026-01-20 12:52:34',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
express_code: '',
|
||
supplier_code: '0004',
|
||
supplier_name: 'NBBT30',
|
||
source_type: 'QM',
|
||
order_status: 'COMPLETED',
|
||
sync_status: 'SUCCESS',
|
||
warehouse_id: 100000,
|
||
store_id: 1000016,
|
||
store_name: '花颜物语',
|
||
warehouse_name: '天豹2',
|
||
status: '已完成'
|
||
},
|
||
{
|
||
id: 97,
|
||
entry_order_code: '2885-2021923981203890178',
|
||
order_type: 'CGRK',
|
||
purchase_order_code: '',
|
||
total_order_lines: 1,
|
||
order_create_time: '2026-02-12 12:27:01',
|
||
expect_start_time: '2026-02-12 12:27:01',
|
||
expect_end_time: '2026-02-12 12:27:01',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
express_code: '',
|
||
supplier_code: '',
|
||
supplier_name: '',
|
||
source_type: 'QM',
|
||
order_status: 'CREATED',
|
||
sync_status: 'PENDING',
|
||
warehouse_id: 100000,
|
||
store_id: 1000016,
|
||
store_name: '花颜物语',
|
||
warehouse_name: '天豹2',
|
||
status: '待入库'
|
||
}
|
||
]
|
||
list.value = mockData
|
||
pagination.total = mockData.length
|
||
}
|
||
} catch (e) {
|
||
console.error('加载逻辑发生严重错误', e)
|
||
ElMessage.error('加载入库单失败')
|
||
} 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('导入功能')
|
||
}
|
||
</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: 0 0 auto;
|
||
min-height: 0;
|
||
/* 不允许 upper-wrapper 自身滚动,保证页面布局不随数据滚动 */
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 在 entry 页面内覆盖 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: 1;
|
||
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: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #909399;
|
||
background-color: #fff;
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 14px;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|