394 lines
11 KiB
Vue
394 lines
11 KiB
Vue
<template>
|
|
<div class="entry-details">
|
|
<div class="header-actions">
|
|
<div class="left-actions">
|
|
<el-button size="small" @click="reloadAll">刷新</el-button>
|
|
<el-button
|
|
size="small"
|
|
type="primary"
|
|
:disabled="!canDirectInbound"
|
|
:loading="commitLoading"
|
|
@click="handleCommit"
|
|
>
|
|
提交完成入库
|
|
</el-button>
|
|
<el-button
|
|
size="small"
|
|
:disabled="!canBatchImport"
|
|
@click="openBatchImportDialog"
|
|
>
|
|
批量导入
|
|
</el-button>
|
|
</div>
|
|
<div class="right-actions">
|
|
<el-tag v-if="canBatchImport" size="small" type="success">可导入/PDA 入库</el-tag>
|
|
<span v-if="directSummary.total_direct_inbound !== undefined" class="summary-text">
|
|
已导入 {{ directSummary.total_direct_inbound ?? 0 }} / 计划 {{ directSummary.total_planned ?? '—' }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-content">
|
|
<UpperTable
|
|
:data="tableData"
|
|
:columns="detailColumns"
|
|
:show-selection="true"
|
|
:pagination="pagination"
|
|
:loading="loading"
|
|
@selection-change="handleSelectionChange"
|
|
@page-size-change="handlePageSizeChange"
|
|
@page-change="handlePageChange"
|
|
>
|
|
<template #column-operation="{ row }">
|
|
<el-button
|
|
link
|
|
type="primary"
|
|
size="small"
|
|
:disabled="!canImportRow(row)"
|
|
@click="openImportDialog(row)"
|
|
>
|
|
导入
|
|
</el-button>
|
|
</template>
|
|
<template #column-direct_inbound_quantity="{ row }">
|
|
<el-tag size="small" :type="Number(row.direct_inbound_quantity) > 0 ? 'success' : 'info'">
|
|
{{ row.direct_inbound_quantity ?? 0 }}
|
|
</el-tag>
|
|
</template>
|
|
<template #column-remaining_quantity="{ row }">
|
|
<el-tag size="small" :type="Number(row.remaining_quantity) > 0 ? 'warning' : 'info'">
|
|
{{ row.remaining_quantity ?? 0 }}
|
|
</el-tag>
|
|
</template>
|
|
<template #column-pending_total="{ row }">
|
|
<span>{{ row.pending_total ?? 0 }}</span>
|
|
</template>
|
|
</UpperTable>
|
|
</div>
|
|
|
|
<DirectInboundImportDialog
|
|
v-model="importDialogVisible"
|
|
:entry-order-id="entryOrderId"
|
|
:entry-order-code="entryOrderCode"
|
|
:order-status="entryOrderStatus"
|
|
:target-item="importTargetItem"
|
|
:batch-file-mode="batchFileMode"
|
|
:entry-items="tableData as DirectInboundImportRow[]"
|
|
@success="handleImportSuccess"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, reactive, ref, watch, onMounted } from 'vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import UpperTable from '@/components/UpperTable/index.vue'
|
|
import {
|
|
commit,
|
|
getEntryDetail,
|
|
type EntryDetailItem,
|
|
} from '@/api/storage.entry/entry'
|
|
import DirectInboundImportDialog, {
|
|
type DirectInboundImportRow,
|
|
} from './DirectInboundImportDialog.vue'
|
|
import {
|
|
canDirectInboundOperate,
|
|
entrydetail,
|
|
} from '../entry-config'
|
|
|
|
const props = defineProps<{
|
|
id?: string | number
|
|
row?: Record<string, unknown> | null
|
|
/** 由父级递增,用于跨 Tab 触发明细刷新 */
|
|
entryDetailRefreshTick?: number
|
|
}>()
|
|
|
|
const emit = defineEmits(['refresh'])
|
|
|
|
const tableData = ref<Record<string, unknown>[]>([])
|
|
const loading = ref(false)
|
|
const commitLoading = ref(false)
|
|
const multipleSelection = ref<Record<string, unknown>[]>([])
|
|
const entryOrderStatus = ref('')
|
|
const entryOrderId = computed(() => {
|
|
const fromProps = Number(props.id)
|
|
if (Number.isFinite(fromProps) && fromProps > 0) return fromProps
|
|
const fromRow = Number(props.row?.id)
|
|
return Number.isFinite(fromRow) && fromRow > 0 ? fromRow : undefined
|
|
})
|
|
const entryOrderCode = ref('')
|
|
const directSummary = ref<Record<string, unknown>>({})
|
|
|
|
const pagination = reactive({
|
|
currentPage: 1,
|
|
pageSize: 20,
|
|
total: 0,
|
|
})
|
|
|
|
const canBatchImport = computed(() => {
|
|
const status = props.row?.order_status ?? entryOrderStatus.value
|
|
if (status === null || status === undefined || status === '') return false
|
|
return String(status).trim().toUpperCase() === 'CREATED'
|
|
})
|
|
|
|
const canDirectInbound = computed(() => {
|
|
const status = props.row?.order_status ?? entryOrderStatus.value
|
|
return canDirectInboundOperate(status)
|
|
})
|
|
|
|
const detailColumns = computed(() => {
|
|
const columns = [...entrydetail]
|
|
const countIndex = columns.findIndex((col) => col.prop === 'count')
|
|
const insertAt = countIndex >= 0 ? countIndex : columns.length
|
|
columns.splice(insertAt, 0,
|
|
{ prop: 'direct_inbound_quantity', label: '已导入', width: '90', align: 'right' },
|
|
{ prop: 'remaining_quantity', label: '剩余可入', width: '90', align: 'right' },
|
|
)
|
|
if (canBatchImport.value) {
|
|
columns.push({
|
|
prop: 'operation',
|
|
label: '操作',
|
|
width: '90',
|
|
fixed: 'right',
|
|
align: 'center',
|
|
} as unknown as (typeof entrydetail)[number])
|
|
}
|
|
return columns
|
|
})
|
|
|
|
const importDialogVisible = ref(false)
|
|
const importTargetItem = ref<DirectInboundImportRow | null>(null)
|
|
const batchFileMode = ref(false)
|
|
|
|
watch(importDialogVisible, (visible) => {
|
|
if (!visible) {
|
|
batchFileMode.value = false
|
|
importTargetItem.value = null
|
|
}
|
|
})
|
|
|
|
watch(
|
|
() => props.entryDetailRefreshTick,
|
|
() => {
|
|
if (props.id && props.entryDetailRefreshTick) {
|
|
void reloadAll()
|
|
}
|
|
}
|
|
)
|
|
|
|
watch(
|
|
() => props.id,
|
|
(newVal) => {
|
|
if (newVal) {
|
|
void reloadAll()
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
function unwrapPayload(res: Record<string, unknown> | null | undefined) {
|
|
if (!res) return null
|
|
if (res.data && typeof res.data === 'object') {
|
|
return res.data as Record<string, unknown>
|
|
}
|
|
return res
|
|
}
|
|
|
|
function buildDirectSummary(items: EntryDetailItem[]) {
|
|
let totalPlanned = 0
|
|
let totalDirectInbound = 0
|
|
for (const item of items) {
|
|
totalPlanned += Number(item.count) || 0
|
|
totalDirectInbound += Number(item.direct_inbound_quantity) || 0
|
|
}
|
|
return {
|
|
total_items: items.length,
|
|
total_planned: totalPlanned,
|
|
total_direct_inbound: totalDirectInbound,
|
|
}
|
|
}
|
|
|
|
async function loadEntryDetail() {
|
|
if (!props.id) return
|
|
loading.value = true
|
|
try {
|
|
const res = await getEntryDetail({ id: Number(props.id) })
|
|
|
|
if (res && res.code === 200 && res.data?.entryOrder) {
|
|
const entryOrder = res.data.entryOrder
|
|
entryOrderStatus.value = entryOrder.order_status || ''
|
|
entryOrderCode.value = entryOrder.entry_order_code || ''
|
|
const items = entryOrder.items || []
|
|
|
|
tableData.value = items.map((item: EntryDetailItem) => ({
|
|
...item,
|
|
direct_inbound_quantity: item.direct_inbound_quantity ?? 0,
|
|
remaining_quantity: item.remaining_quantity ?? item.count ?? 0,
|
|
entry_order_code: entryOrder.entry_order_code || '',
|
|
purchase_order_code: entryOrder.purchase_order_code || '',
|
|
store_name: entryOrder.store_name || '',
|
|
}))
|
|
|
|
directSummary.value = buildDirectSummary(items)
|
|
pagination.total = tableData.value.length
|
|
} else {
|
|
throw new Error(res?.message || '接口返回数据异常')
|
|
}
|
|
} catch (error) {
|
|
console.error('获取明细失败:', error)
|
|
ElMessage.error('获取明细失败')
|
|
tableData.value = []
|
|
pagination.total = 0
|
|
entryOrderStatus.value = ''
|
|
entryOrderCode.value = ''
|
|
directSummary.value = {}
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function reloadAll() {
|
|
await loadEntryDetail()
|
|
}
|
|
|
|
function canImportRow(row: DirectInboundImportRow) {
|
|
const status = props.row?.order_status ?? entryOrderStatus.value
|
|
if (status === null || status === undefined || status === '') return false
|
|
if (String(status).trim().toUpperCase() !== 'CREATED') return false
|
|
if (!canDirectInbound.value || !row.stock_id) return false
|
|
const available = Number(row.remaining_quantity ?? row.count ?? 0)
|
|
return Number.isFinite(available) && available > 0
|
|
}
|
|
|
|
function openImportDialog(row: DirectInboundImportRow) {
|
|
if (!canImportRow(row)) {
|
|
ElMessage.warning('该商品无可导入数量')
|
|
return
|
|
}
|
|
batchFileMode.value = false
|
|
importTargetItem.value = row
|
|
importDialogVisible.value = true
|
|
}
|
|
|
|
function openBatchImportDialog() {
|
|
if (!canBatchImport.value) {
|
|
ElMessage.warning('仅「已创建」状态可使用批量导入')
|
|
return
|
|
}
|
|
importTargetItem.value = null
|
|
batchFileMode.value = true
|
|
importDialogVisible.value = true
|
|
}
|
|
|
|
async function handleImportSuccess() {
|
|
await reloadAll()
|
|
emit('refresh')
|
|
}
|
|
|
|
async function handleCommit() {
|
|
const id = entryOrderId.value
|
|
const code = entryOrderCode.value
|
|
if (!id) {
|
|
ElMessage.warning('缺少入库单 ID')
|
|
return
|
|
}
|
|
if (!canDirectInbound.value) {
|
|
ElMessage.warning('当前入库单状态不允许提交')
|
|
return
|
|
}
|
|
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
`确认提交并完成入库单「${code || id}」的导入/PDA 入库?提交后将写入库存并更新入库单状态为已完成。`,
|
|
'提交完成入库',
|
|
{ type: 'warning', confirmButtonText: '确认提交', cancelButtonText: '取消' }
|
|
)
|
|
} catch {
|
|
return
|
|
}
|
|
|
|
commitLoading.value = true
|
|
try {
|
|
const res = await commit({ entry_order_id: id })
|
|
if (res?.code !== 200 && res?.code !== undefined) {
|
|
throw new Error(res?.message || '提交完成入库失败')
|
|
}
|
|
|
|
const payload = unwrapPayload(res as Record<string, unknown>)
|
|
ElMessage.success(
|
|
`入库完成:共 ${payload?.items_count ?? '—'} 种商品,总量 ${payload?.total_quantity ?? '—'}`
|
|
)
|
|
await reloadAll()
|
|
emit('refresh')
|
|
} catch (error) {
|
|
console.error('提交完成入库失败:', error)
|
|
ElMessage.error(error instanceof Error ? error.message : '提交完成入库失败')
|
|
} finally {
|
|
commitLoading.value = false
|
|
}
|
|
}
|
|
|
|
const handleSelectionChange = (val: Record<string, unknown>[]) => {
|
|
multipleSelection.value = val
|
|
}
|
|
|
|
const handlePageSizeChange = () => {
|
|
void reloadAll()
|
|
}
|
|
|
|
const handlePageChange = () => {
|
|
void reloadAll()
|
|
}
|
|
|
|
defineExpose({
|
|
openBatchImportDialog,
|
|
reloadAll,
|
|
})
|
|
|
|
onMounted(() => {
|
|
if (props.id) {
|
|
void reloadAll()
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.entry-details {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
background: #fff;
|
|
|
|
.header-actions {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px solid #ebeef5;
|
|
margin-bottom: 10px;
|
|
|
|
.left-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.right-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.summary-text {
|
|
font-size: 12px;
|
|
color: #606266;
|
|
}
|
|
}
|
|
|
|
.table-content {
|
|
flex: 1;
|
|
min-height: 200px;
|
|
overflow: hidden;
|
|
}
|
|
}
|
|
</style>
|