From 55e06d51aa5eb59868d360095ec4fbd0007e6587 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 26 Jun 2026 09:22:43 +0800 Subject: [PATCH] 1 --- src/api/storage.entry/entry.ts | 65 +++-- .../component/BindReceivingToEntryDialog.vue | 271 +++++++++++------- .../entry/component/EntryBindingRelations.vue | 15 +- src/views/storage/entry/entry-config.ts | 7 +- 4 files changed, 217 insertions(+), 141 deletions(-) diff --git a/src/api/storage.entry/entry.ts b/src/api/storage.entry/entry.ts index 48c3663d..0a1a45b4 100644 --- a/src/api/storage.entry/entry.ts +++ b/src/api/storage.entry/entry.ts @@ -680,26 +680,26 @@ export function quickInbound(data: QuickInboundParams): Promise + /** 总体汇总统计 */ + total_summary?: ReceivingCompareSummary data?: Partial> } -/** 入库单与收货单商品对照 */ +/** 入库单与收货单商品对照(支持单个或多个收货单) */ export function receivingCompare( data: ReceivingCompareParams ): Promise { diff --git a/src/views/storage/entry/component/BindReceivingToEntryDialog.vue b/src/views/storage/entry/component/BindReceivingToEntryDialog.vue index f6549f31..c51ea9e3 100644 --- a/src/views/storage/entry/component/BindReceivingToEntryDialog.vue +++ b/src/views/storage/entry/component/BindReceivingToEntryDialog.vue @@ -23,6 +23,22 @@ 订单状态 {{ entryOrderStatusLabel }} + + 运单号 + {{ entryExpressCode }} + + + 物流公司 + {{ entryLogisticsName }} + + + 单据编号 + {{ entryPurchaseOrderCode }} + + + 备注 + {{ entryRemark }} +
@@ -56,6 +72,7 @@ v-for="row in compareRows" :key="row.rowKey" class="compare-row" + :class="{ 'compare-row--matched': row.matchStatus === 'matched' }" >
{ 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) { - 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): 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): 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[]> { - 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() + // 按 warehouse_item_code 跟踪最佳匹配状态:matched > entry_only + const itemMatchStatus = new Map() + + 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 + 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 + 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; diff --git a/src/views/storage/entry/component/EntryBindingRelations.vue b/src/views/storage/entry/component/EntryBindingRelations.vue index b29b9387..33610c5a 100644 --- a/src/views/storage/entry/component/EntryBindingRelations.vue +++ b/src/views/storage/entry/component/EntryBindingRelations.vue @@ -190,16 +190,19 @@ const itemBindingRows = ref([]) const comparePreview = ref(null) const activeCompareReceivingId = ref(null) -const compareSummaryItems = computed(() => - buildReceivingCompareSummaryItems(comparePreview.value?.summary as Record | undefined) -) +const compareSummaryItems = computed(() => { + const first = comparePreview.value?.comparisons?.[0] + return buildReceivingCompareSummaryItems(first?.summary as Record | undefined) +}) const compareRows = computed(() => { 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)) }) diff --git a/src/views/storage/entry/entry-config.ts b/src/views/storage/entry/entry-config.ts index c058ded6..7ab20eb7 100644 --- a/src/views/storage/entry/entry-config.ts +++ b/src/views/storage/entry/entry-config.ts @@ -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) */