This commit is contained in:
liufumingren 2026-06-26 09:22:43 +08:00
parent ce6ff6d406
commit 55e06d51aa
4 changed files with 217 additions and 141 deletions

View File

@ -680,26 +680,26 @@ export function quickInbound(data: QuickInboundParams): Promise<QuickInboundResp
export type ReceivingCompareMatchStatus = 'matched' | 'entry_only' | string
/** 逐行对照项(comparison 数组元素) */
/** 逐行对照项(comparison / entry_only / receiving_only 数组元素) */
export type ReceivingCompareRow = {
entry_item_id?: number
stock_id?: number
item_code?: string
warehouse_item_code?: string
product_code?: string
item_name?: string
product_name?: string
warehouse_item_name?: string
barcode?: string
entry_plan_qty?: number
entry_received_qty?: number
plan_qty?: number
count?: number
received_quantity?: number
receiving_qty?: number
receiving_quantity?: number
actual_quantity?: number
box_quantity?: number
receiving_allocated?: number
warehouse_item_spec?: string
/** 入库计划数量 */
entry_count?: number
/** 入库已收数量 */
entry_received?: number
receiving_detail_id?: number | null
receiving_product_code?: string | null
receiving_product_name?: string | null
/** 收货实际数量 */
receiving_actual_quantity?: number | null
/** 收货已分配数量 */
receiving_allocated?: number | null
/** 收货可用数量 */
receiving_available?: number | null
match_status?: ReceivingCompareMatchStatus
[key: string]: unknown
}
@ -729,11 +729,26 @@ export type ReceivingCompareSummary = {
[key: string]: unknown
}
/** 单个收货单对照结果(comparisons 数组元素) */
export type ReceivingCompareItem = {
receiving_id?: number
receiving_number?: string
/** 对照状态:matched / error 等 */
status?: string
comparison?: ReceivingCompareRow[]
entry_only?: ReceivingCompareRow[]
receiving_only?: ReceivingCompareRow[]
summary?: ReceivingCompareSummary
[key: string]: unknown
}
export type ReceivingCompareParams = {
/** 入库单ID */
entry_order_id: number
/** 收货单ID */
receiving_id: number
/** 收货单ID,单个时使用,与 receiving_ids 二选一 */
receiving_id?: number
/** 收货单ID数组,优先使用;与 receiving_id 二选一 */
receiving_ids?: number[]
}
export type ReceivingCompareResponse = {
@ -741,16 +756,16 @@ export type ReceivingCompareResponse = {
message?: string
entry_order_id?: number
entry_order_code?: string
receiving_id?: number
receiving_number?: string
comparison?: ReceivingCompareRow[]
entry_only?: ReceivingCompareRow[]
receiving_only?: ReceivingCompareRow[]
summary?: ReceivingCompareSummary
/** 各收货单对照结果列表 */
comparisons?: ReceivingCompareItem[]
/** 校验失败的收货单列表 */
errors?: Array<{ receiving_id?: number; message?: string; [key: string]: unknown }>
/** 总体汇总统计 */
total_summary?: ReceivingCompareSummary
data?: Partial<Omit<ReceivingCompareResponse, 'data'>>
}
/** 入库单与收货单商品对照 */
/** 入库单与收货单商品对照(支持单个或多个收货单) */
export function receivingCompare(
data: ReceivingCompareParams
): Promise<ReceivingCompareResponse> {

View File

@ -23,6 +23,22 @@
<span class="summary-label">订单状态</span>
<el-tag size="small" :type="entryOrderStatusTag">{{ entryOrderStatusLabel }}</el-tag>
</span>
<span v-if="entryExpressCode" class="summary-inline">
<span class="summary-label">运单号</span>
<span class="summary-value">{{ entryExpressCode }}</span>
</span>
<span v-if="entryLogisticsName" class="summary-inline">
<span class="summary-label">物流公司</span>
<span class="summary-value">{{ entryLogisticsName }}</span>
</span>
<span v-if="entryPurchaseOrderCode" class="summary-inline">
<span class="summary-label">单据编号</span>
<span class="summary-value">{{ entryPurchaseOrderCode }}</span>
</span>
<span v-if="entryRemark" class="summary-inline summary-inline--remark">
<span class="summary-label">备注</span>
<span class="summary-value summary-value--remark">{{ entryRemark }}</span>
</span>
</div>
<div class="bind-dialog-body">
@ -56,6 +72,7 @@
v-for="row in compareRows"
:key="row.rowKey"
class="compare-row"
:class="{ 'compare-row--matched': row.matchStatus === 'matched' }"
>
<div
class="compare-cell"
@ -170,7 +187,7 @@ import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
import { useResizeObserver } from '@vueuse/core'
import { ElMessage } from 'element-plus'
import type { TableInstance } from 'element-plus'
import { getReceivingList, getReceivingDetail } from '@/api/storage_receiving/receiving'
import { getReceivingList } from '@/api/storage_receiving/receiving'
import {
bindReceiving,
getEntryDetail,
@ -178,6 +195,7 @@ import {
type BindReceivingResponse,
type EntryDetailItem,
type ReceivingCompareResponse,
type ReceivingCompareItem,
type ReceivingCompareRow,
} from '@/api/storage.entry/entry'
import {
@ -216,6 +234,7 @@ type CompareDisplayRow = {
entryQty: string | number
receivingName: string
receivingQty: string | number
matchStatus?: string
}
const props = defineProps<{
@ -286,13 +305,36 @@ const entryOrderStatusLabel = computed(() => {
const entryOrderStatusTag = computed(() => getEntryOrderStatusTagType(props.row?.order_status))
const entryRemark = computed(() => {
const remark = props.row?.remark
return remark !== null && remark !== undefined && String(remark).trim() ? String(remark).trim() : ''
})
const entryExpressCode = computed(() => {
const code = props.row?.express_code
return code !== null && code !== undefined && String(code).trim() ? String(code).trim() : ''
})
const entryLogisticsName = computed(() => {
const name = props.row?.logistics_name
return name !== null && name !== undefined && String(name).trim() ? String(name).trim() : ''
})
const entryPurchaseOrderCode = computed(() => {
const code = props.row?.purchase_order_code
return code !== null && code !== undefined && String(code).trim() ? String(code).trim() : ''
})
const isEntryFullyCovered = ref(false)
const canSubmitBind = computed(
() =>
!!entryOrderId.value &&
selectedReceivingRows.value.length > 0 &&
!bindSubmitting.value &&
!compareLoading.value &&
!receivingListLoading.value
!receivingListLoading.value &&
isEntryFullyCovered.value
)
function isApiSuccess(res: { code?: number; flag?: string } | null | undefined): boolean {
@ -349,42 +391,18 @@ function mapEntryItem(item: EntryDetailItem) {
}
}
function mapReceivingDetailItem(item: Record<string, unknown>) {
return {
name: pickText(item, ['product_name', 'warehouse_item_name', 'item_name']),
qty: pickQty(item, ['actual_quantity', 'receiving_qty', 'quantity', 'box_quantity']),
}
}
function buildCompareRowsFromSides(
entryList: Array<{ name: string; qty: string | number }>,
receivingList: Array<{ name: string; qty: string | number }>
): CompareDisplayRow[] {
const maxLen = Math.max(entryList.length, receivingList.length)
if (!maxLen) return []
return Array.from({ length: maxLen }, (_, index) => ({
rowKey: `row-${index}`,
entryName: entryList[index]?.name ?? '—',
entryQty: entryList[index]?.qty ?? '—',
receivingName: receivingList[index]?.name ?? '—',
receivingQty: receivingList[index]?.qty ?? '—',
}))
}
function hasCompareEntryData(record: Record<string, unknown>): boolean {
return !!(
pickTextOrEmpty(record, ['item_code', 'warehouse_item_code', 'product_code']) ||
pickTextOrEmpty(record, ['item_name', 'warehouse_item_name', 'product_name']) ||
pickQty(record, ['entry_plan_qty', 'plan_qty', 'count', 'entry_received_qty', 'received_quantity']) !==
'—'
pickTextOrEmpty(record, ['warehouse_item_code']) ||
pickTextOrEmpty(record, ['warehouse_item_name']) ||
pickQty(record, ['entry_count', 'entry_received']) !== '—'
)
}
function hasCompareReceivingData(record: Record<string, unknown>): boolean {
return !!(
pickTextOrEmpty(record, ['item_code', 'warehouse_item_code', 'product_code']) ||
pickTextOrEmpty(record, ['item_name', 'warehouse_item_name', 'product_name']) ||
pickQty(record, ['receiving_qty', 'receiving_quantity', 'actual_quantity', 'quantity']) !== '—'
pickTextOrEmpty(record, ['receiving_product_name']) ||
pickQty(record, ['receiving_actual_quantity', 'receiving_allocated', 'receiving_available']) !== '—'
)
}
@ -399,47 +417,23 @@ function buildCompareRowsFromApi(records: ReceivingCompareRow[]): CompareDisplay
return {
rowKey: `compare-${index}-${status || 'row'}`,
matchStatus: status || '',
entryName: hasEntry
? pickText(raw, ['item_name', 'warehouse_item_name', 'product_name'])
? pickText(raw, ['warehouse_item_name'])
: '—',
entryQty: hasEntry
? pickQty(raw, [
'entry_plan_qty',
'plan_qty',
'count',
'entry_received_qty',
'received_quantity',
'total_planned',
])
? pickQty(raw, ['entry_count', 'entry_received'])
: '—',
receivingName: hasReceiving
? pickText(raw, ['item_name', 'warehouse_item_name', 'product_name'])
? pickText(raw, ['receiving_product_name', 'warehouse_item_name'])
: '—',
receivingQty: hasReceiving
? pickQty(raw, ['receiving_qty', 'receiving_quantity', 'actual_quantity', 'quantity', 'box_quantity'])
? pickQty(raw, ['receiving_available', 'receiving_actual_quantity', 'receiving_allocated', 'entry_count'])
: '—',
}
})
}
function compareRowsLackQty(rows: CompareDisplayRow[]): boolean {
return rows.length > 0 && rows.every((row) => row.entryQty === '—' && row.receivingQty === '—')
}
function shouldUseSideCompareFallback(
apiRows: CompareDisplayRow[],
entryMapped: Array<{ name: string; qty: string | number }>,
receivingMapped: Array<{ name: string; qty: string | number }>
): boolean {
if (!apiRows.length) return true
if (compareRowsLackQty(apiRows)) return true
const entryQtyMissing =
entryMapped.length > 0 && apiRows.every((row) => row.entryQty === '—')
const receivingQtyMissing =
receivingMapped.length > 0 && apiRows.every((row) => row.receivingQty === '—')
return entryQtyMissing || receivingQtyMissing
}
function buildEntryOnlyCompareRows(): CompareDisplayRow[] {
return entryItems.value.map((item, index) => {
const mapped = mapEntryItem(item)
@ -478,6 +472,7 @@ function resetReceivingState() {
selectedReceivingRows.value = []
compareRows.value = []
entryItems.value = []
isEntryFullyCovered.value = false
pagination.currentPage = 1
pagination.pageSize = 10
pagination.total = 0
@ -516,20 +511,11 @@ async function loadEntryItems() {
}
}
async function loadReceivingDetailItems(receivingId: number): Promise<Record<string, unknown>[]> {
const res: any = await getReceivingDetail({
id: receivingId,
pagination: { page: 1, pageSize: 500 },
})
if (!isApiSuccess(res) || !res.data) return []
const receivingData = res.data.receiving || {}
if (Array.isArray(receivingData.details)) return receivingData.details
if (Array.isArray(res.data.list)) return res.data.list
if (Array.isArray(res.data.details)) return res.data.details
return []
}
async function refreshCompareRows() {
if (compareLoading.value) return
isEntryFullyCovered.value = false
const selected = selectedReceivingRows.value
if (!selected.length) {
compareRows.value = buildEntryOnlyCompareRows()
@ -538,47 +524,89 @@ async function refreshCompareRows() {
compareLoading.value = true
try {
if (selected.length === 1 && entryOrderId.value) {
const firstSelected = selected[0]
const receivingId = Number(firstSelected?.id)
if (Number.isFinite(receivingId) && receivingId > 0) {
const res = await receivingCompare({
entry_order_id: entryOrderId.value,
receiving_id: receivingId,
})
if (isApiSuccess(res)) {
const payload = (
res.data && typeof res.data === 'object' ? { ...res, ...res.data } : res
) as ReceivingCompareResponse
const records = [
...(Array.isArray(payload.comparison) ? payload.comparison : []),
...(Array.isArray(payload.entry_only) ? payload.entry_only : []),
...(Array.isArray(payload.receiving_only) ? payload.receiving_only : []),
]
const entryMapped = entryItems.value.map(mapEntryItem)
const receivingMapped = (await loadReceivingDetailItems(receivingId)).map(mapReceivingDetailItem)
if (!entryOrderId.value) {
compareRows.value = buildEntryOnlyCompareRows()
return
}
if (records.length) {
const apiRows = buildCompareRowsFromApi(records)
compareRows.value = shouldUseSideCompareFallback(apiRows, entryMapped, receivingMapped)
? buildCompareRowsFromSides(entryMapped, receivingMapped)
: apiRows
} else {
compareRows.value = buildCompareRowsFromSides(entryMapped, receivingMapped)
const eid = entryOrderId.value
const ids = selected
.map((row) => Number(row.id))
.filter((id) => Number.isFinite(id) && id > 0)
if (!eid || !ids.length) {
compareRows.value = buildEntryOnlyCompareRows()
return
}
const res = await receivingCompare({
entry_order_id: eid,
receiving_ids: ids,
})
if (!isApiSuccess(res)) {
compareRows.value = buildEntryOnlyCompareRows()
return
}
const payload = (
res.data && typeof res.data === 'object' ? { ...res, ...res.data } : res
) as ReceivingCompareResponse
const allRecords: ReceivingCompareRow[] = []
const seenKeys = new Set<string>()
// 按 warehouse_item_code 跟踪最佳匹配状态:matched > entry_only
const itemMatchStatus = new Map<string, string>()
for (const item of (payload.comparisons ?? [])) {
const records = [
...(Array.isArray(item.comparison) ? item.comparison : []),
...(Array.isArray(item.receiving_only) ? item.receiving_only : []),
]
for (const record of records) {
const raw = record as Record<string, unknown>
const ms = String(raw.match_status ?? '').toLowerCase()
// 收货侧可用量为 0 则不展示(无实际可绑定量)
if (!raw.warehouse_item_code && Number(raw.receiving_available) === 0) continue
const key = String(raw.warehouse_item_code ?? Math.random())
// 更新该商品的最佳匹配状态
const prev = itemMatchStatus.get(key)
if (!prev || (prev === 'entry_only' && ms === 'matched')) {
itemMatchStatus.set(key, ms)
}
if (!seenKeys.has(key)) {
seenKeys.add(key)
allRecords.push(record)
} else if (ms === 'matched') {
// 已存在 entry_only 记录,现在遇到 matched,覆盖更新
const idx = allRecords.findIndex((r) => {
const rRaw = r as Record<string, unknown>
return String(rRaw.warehouse_item_code ?? '') === key
})
if (idx >= 0) {
allRecords[idx] = record
}
return
}
}
}
const receivingMapped: Array<{ name: string; qty: string | number }> = []
for (const row of selected) {
const receivingId = Number(row.id)
if (!Number.isFinite(receivingId) || receivingId <= 0) continue
const details = await loadReceivingDetailItems(receivingId)
details.forEach((item) => receivingMapped.push(mapReceivingDetailItem(item)))
// 只要有一个 entry_only 的商品从未被任何收货单 matched,则不算完全覆盖
let hasUnmatchedEntry = false
for (const [, status] of itemMatchStatus) {
if (status === 'entry_only') {
hasUnmatchedEntry = true
break
}
}
isEntryFullyCovered.value = !hasUnmatchedEntry
if (allRecords.length) {
compareRows.value = buildCompareRowsFromApi(allRecords)
} else {
compareRows.value = buildEntryOnlyCompareRows()
}
compareRows.value = buildCompareRowsFromSides(entryItems.value.map(mapEntryItem), receivingMapped)
} catch (error) {
console.error('加载对照数据失败:', error)
compareRows.value = buildEntryOnlyCompareRows()
@ -590,9 +618,12 @@ async function refreshCompareRows() {
function handleReceivingSelectionChange(rows: ReceivingListItem[]) {
selectedReceivingRows.value = rows || []
void refreshCompareRows()
}
watch(selectedReceivingRows, () => {
void refreshCompareRows()
})
async function loadReceivingList() {
if (!entryStoreId.value) {
receivingList.value = []
@ -606,9 +637,11 @@ async function loadReceivingList() {
try {
const res = await getReceivingList({
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
filterDepleted: true,
where: {
store_id: { operator: 'eq', value: entryStoreId.value, type: 'number' },
is_review: { operator: 'eq', value: 1, type: 'number' },
storage_status: { operator: 'in', value: ['none', 'partial'], type: 'text' },
},
})
if (!isApiSuccess(res)) {
@ -780,6 +813,17 @@ watch(
word-break: break-all;
}
.summary-inline--remark {
flex-basis: 100%;
}
.summary-value--remark {
max-width: 600px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bind-dialog-body {
flex: 1;
min-height: 0;
@ -911,6 +955,17 @@ watch(
}
}
.compare-row--matched {
.compare-cell {
background: #67c23a !important;
color: #fff !important;
}
.compare-cell--qty {
color: #fff !important;
}
}
.compare-cell--qty {
text-align: right;
color: #606266;

View File

@ -190,16 +190,19 @@ const itemBindingRows = ref<ItemBindingRow[]>([])
const comparePreview = ref<ReceivingCompareResponse | null>(null)
const activeCompareReceivingId = ref<number | null>(null)
const compareSummaryItems = computed(() =>
buildReceivingCompareSummaryItems(comparePreview.value?.summary as Record<string, unknown> | undefined)
)
const compareSummaryItems = computed(() => {
const first = comparePreview.value?.comparisons?.[0]
return buildReceivingCompareSummaryItems(first?.summary as Record<string, unknown> | undefined)
})
const compareRows = computed<ComparePreviewRow[]>(() => {
if (!comparePreview.value) return []
const first = comparePreview.value.comparisons?.[0]
if (!first) return []
const records = [
...(comparePreview.value.comparison ?? []),
...(comparePreview.value.entry_only ?? []),
...(comparePreview.value.receiving_only ?? []),
...(first.comparison ?? []),
...(first.entry_only ?? []),
...(first.receiving_only ?? []),
]
return records.map((record, index) => mapCompareRow(record, index))
})

View File

@ -318,9 +318,12 @@ export function canDirectInboundOperate(status: unknown): boolean {
return !['COMPLETED', 'CANCELLED'].includes(upper) && upper !== '已完成' && upper !== '已作废'
}
/** 是否允许绑定收货(未完成、未作废) */
/** 是否允许绑定收货(仅 CREATED / 已创建 状态可操作) */
export function canBindEntryOrder(status: unknown): boolean {
return canDirectInboundOperate(status)
if (status === null || status === undefined || status === '') return false
const normalized = String(status).trim()
const upper = normalized.toUpperCase()
return upper === 'CREATED' || normalized === '已创建'
}
/** storage.entry.list 虚拟 where 字段(需原样传 boolean,不能包 operator) */