460 lines
13 KiB
Vue
460 lines
13 KiB
Vue
<template>
|
||
<div class="entry-details">
|
||
<div class="header-actions">
|
||
<div class="left-actions">
|
||
<el-button size="small" type="primary" @click="reloadAll">刷新</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
plain
|
||
:disabled="!canDirectInbound"
|
||
:loading="commitLoading"
|
||
@click="handleCommit"
|
||
>
|
||
提交完成入库
|
||
</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
plain
|
||
: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"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
: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-remaining_quantity="{ row }">
|
||
<span :class="getStatusTextClass(Number(row.remaining_quantity) > 0 ? 'warning' : 'info')">
|
||
{{ row.remaining_quantity ?? 0 }}
|
||
</span>
|
||
</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 { getStatusTextClass } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import {
|
||
commit,
|
||
getEntryDetail,
|
||
getEntryDetailStore,
|
||
type EntryDetailItem,
|
||
type EntryDetailItemBarcode,
|
||
} from '@/api/storage.entry/entry'
|
||
import DirectInboundImportDialog, {
|
||
type DirectInboundImportRow,
|
||
} from './DirectInboundImportDialog.vue'
|
||
import {
|
||
canDirectInboundOperate,
|
||
entrydetail,
|
||
isPendingEntryOrderStatus,
|
||
} from '../entry-config'
|
||
|
||
const props = defineProps<{
|
||
id?: string | number
|
||
row?: Record<string, unknown> | null
|
||
/** 由父级递增,用于跨 Tab 触发明细刷新 */
|
||
entryDetailRefreshTick?: number
|
||
/** 货主侧模式,使用 getEntryDetailStore 接口 */
|
||
storeMode?: boolean
|
||
}>()
|
||
|
||
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
|
||
return isPendingEntryOrderStatus(status)
|
||
})
|
||
|
||
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 + 1 : columns.length
|
||
columns.splice(insertAt, 0,
|
||
{ 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 fetchDetail = props.storeMode ? getEntryDetailStore : getEntryDetail
|
||
const res = await fetchDetail({ 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 || ''
|
||
|
||
// items 与 entryOrder 同级,在 res.data 下
|
||
const rawItems: any[] = res.data.items || []
|
||
const items: EntryDetailItem[] = rawItems.map((item: any) => {
|
||
const stock = item.stock || {}
|
||
const barcodes: EntryDetailItemBarcode[] = (stock.barcodes || []).map((b: any) => ({
|
||
id: b.id,
|
||
barcode: b.barcode,
|
||
}))
|
||
const imageUrls: string[] = Array.isArray(stock.image_url) ? stock.image_url : []
|
||
const primaryBarcode = barcodes.length > 0 ? (barcodes[0]?.barcode ?? '') : ''
|
||
return {
|
||
id: item.id,
|
||
stock_id: item.stock_id ?? stock.id,
|
||
warehouse_item_code: stock.item_code || '',
|
||
warehouse_item_name: stock.item_name || '',
|
||
warehouse_item_spec: stock.sku_property || '',
|
||
barcode: primaryBarcode || '',
|
||
stock_unit: stock.stock_unit || '',
|
||
count: item.planned ?? item.count ?? 0,
|
||
received_quantity: item.completed ?? item.received_quantity ?? 0,
|
||
warehouse_quantity: stock.quantity ?? null,
|
||
warehouse_locked_quantity: stock.locked_quantity ?? null,
|
||
is_batch_mgmt: stock.is_batch_mgmt === 'Y' ? '是' : '否',
|
||
is_shelf_life_mgmt: stock.is_shelf_life_mgmt === 'Y' ? '是' : '否',
|
||
warehouse_image_url: imageUrls.length > 0 ? imageUrls[0] : '',
|
||
barcodes,
|
||
direct_inbound_quantity: item.direct_inbound_quantity ?? 0,
|
||
remaining_quantity: item.remaining_quantity ?? ((item.planned ?? item.count ?? 0) - (item.completed ?? item.received_quantity ?? 0)),
|
||
pending_total: item.pending_total ?? 0,
|
||
bindings: item.bindings || [],
|
||
direct_logs: item.direct_logs || [],
|
||
entry_order_code: entryOrder.entry_order_code || '',
|
||
store_name: entryOrder.store_remask || entryOrder.store_name || '',
|
||
}
|
||
})
|
||
|
||
tableData.value = items
|
||
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')
|
||
}
|
||
|
||
/** 提交入库后是否通知货主:返回 0=通知、1=不通知;关闭/ESC 返回 null(取消) */
|
||
async function askOwnerNotice(actionDesc: string): Promise<number | null> {
|
||
return new Promise((resolve) => {
|
||
ElMessageBox.confirm(`${actionDesc},是否通知货主?`, '通知货主设置', {
|
||
confirmButtonText: '通知货主',
|
||
cancelButtonText: '不通知',
|
||
type: 'warning',
|
||
distinguishCancelAndClose: true
|
||
})
|
||
.then(() => resolve(0))
|
||
.catch((action: string | 'cancel' | 'close') => {
|
||
resolve(action === 'cancel' ? 1 : null)
|
||
})
|
||
})
|
||
}
|
||
|
||
async function handleCommit() {
|
||
const id = entryOrderId.value
|
||
const code = entryOrderCode.value
|
||
if (!id) {
|
||
ElMessage.warning('缺少入库单 ID')
|
||
return
|
||
}
|
||
if (!canDirectInbound.value) {
|
||
ElMessage.warning('当前入库单状态不允许提交')
|
||
return
|
||
}
|
||
|
||
const noNeedNotice = await askOwnerNotice(`确认提交并完成入库单「${code || id}」的导入/PDA 入库`)
|
||
if (noNeedNotice === null) return
|
||
|
||
commitLoading.value = true
|
||
try {
|
||
const res = await commit({ entry_order_id: id, noNeedNotice })
|
||
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">
|
||
@use "../../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
.entry-details {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
padding: 6px 10px 8px;
|
||
background: #fff;
|
||
box-sizing: border-box;
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 6px;
|
||
flex-shrink: 0;
|
||
gap: 4px;
|
||
flex-wrap: wrap;
|
||
|
||
.left-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
|
||
/* 清除 Element Plus 默认按钮左边距,统一由 gap 控制等间距 */
|
||
:deep(.el-button) {
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
}
|
||
|
||
.right-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.summary-text {
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
}
|
||
|
||
.table-content {
|
||
flex: 1;
|
||
min-height: 120px;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
|
||
/* 分页区与「操作日志」保持一致:去掉 UpperTable 默认的底部分隔线/内边距,
|
||
右对齐,仅保留 6px 上间距;左侧「已选 N 条 / 查询用时」文案一并去掉 */
|
||
:deep(.pagination-container) {
|
||
padding: 0;
|
||
border-top: none;
|
||
margin-top: 6px;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
:deep(.pagination-info) {
|
||
display: none;
|
||
}
|
||
}
|
||
}
|
||
</style>
|