500 lines
14 KiB
Vue
500 lines
14 KiB
Vue
<template>
|
|
<div class="entry-binding-relations">
|
|
<div class="header-actions">
|
|
<div class="left-actions">
|
|
<el-button size="small" :loading="loading" @click="loadBindingData">刷新</el-button>
|
|
</div>
|
|
<div class="right-actions">
|
|
<span class="summary-text">已绑定收货单 {{ receivingBindings.length }} 个</span>
|
|
<span class="summary-text">明细绑定 {{ itemBindingRows.length }} 条</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-loading="loading" class="binding-content">
|
|
<section class="binding-section">
|
|
<div class="section-title">绑定的收货单</div>
|
|
<el-table
|
|
:data="receivingBindings"
|
|
border
|
|
stripe
|
|
size="small"
|
|
row-key="rowKey"
|
|
empty-text="暂无绑定的收货单"
|
|
max-height="220"
|
|
>
|
|
<el-table-column
|
|
v-for="col in entryReceivingBindingColumns"
|
|
:key="col.prop"
|
|
:prop="col.prop"
|
|
:label="col.label"
|
|
:width="col.width"
|
|
:min-width="col.minWidth"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column label="操作" width="90" fixed="right" align="center">
|
|
<template #default="{ row }">
|
|
<el-button
|
|
link
|
|
type="primary"
|
|
size="small"
|
|
:loading="compareLoading && activeCompareReceivingId === row.receiving_id"
|
|
@click="loadComparePreview(row.receiving_id)"
|
|
>
|
|
对照
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</section>
|
|
|
|
<!-- <section class="binding-section">
|
|
<div class="section-title">明细绑定关系</div>
|
|
<el-table
|
|
:data="itemBindingRows"
|
|
border
|
|
stripe
|
|
size="small"
|
|
row-key="rowKey"
|
|
empty-text="暂无明细绑定关系"
|
|
max-height="280"
|
|
>
|
|
<el-table-column
|
|
v-for="col in entryItemBindingDetailColumns"
|
|
:key="col.prop"
|
|
:prop="col.prop"
|
|
:label="col.label"
|
|
:width="col.width"
|
|
:min-width="col.minWidth"
|
|
:align="col.align"
|
|
show-overflow-tooltip
|
|
/>
|
|
</el-table>
|
|
</section> -->
|
|
|
|
<section v-if="comparePreview" v-loading="compareLoading" class="binding-section">
|
|
<div class="section-title">
|
|
对照预览
|
|
<span v-if="comparePreview.receiving_number" class="section-subtitle">
|
|
{{ comparePreview.receiving_number }}
|
|
</span>
|
|
</div>
|
|
|
|
<div v-if="compareSummaryItems.length" class="summary-grid">
|
|
<div
|
|
v-for="item in compareSummaryItems"
|
|
:key="item.key"
|
|
class="summary-card"
|
|
:class="`summary-card--${item.cardType}`"
|
|
>
|
|
<div class="summary-value">{{ item.value }}</div>
|
|
<div class="summary-label">{{ item.label }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<el-table
|
|
:data="compareRows"
|
|
border
|
|
stripe
|
|
size="small"
|
|
row-key="rowKey"
|
|
empty-text="暂无对照数据"
|
|
max-height="260"
|
|
>
|
|
<el-table-column
|
|
v-for="col in entryBindingCompareColumns"
|
|
:key="col.prop"
|
|
:prop="col.prop"
|
|
:label="col.label"
|
|
:width="col.width"
|
|
:min-width="col.minWidth"
|
|
:align="col.align"
|
|
show-overflow-tooltip
|
|
>
|
|
<template v-if="col.prop === 'match_status_label'" #default="{ row }">
|
|
<el-tag size="small" :type="getReceivingCompareStatusTagType(row.match_status)">
|
|
{{ row.match_status_label }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, ref, watch, onActivated } from 'vue'
|
|
import { ElMessage } from 'element-plus'
|
|
import {
|
|
getEntryDetail,
|
|
receivingCompare,
|
|
type EntryAvailableReceivingDetail,
|
|
type EntryDetailItem,
|
|
type EntryOrderReceivingBinding,
|
|
type ReceivingCompareResponse,
|
|
type ReceivingCompareRow,
|
|
} from '@/api/storage.entry/entry'
|
|
import { formatDateTime } from '@/views/storage/receiving/receiving-config'
|
|
import {
|
|
buildReceivingCompareSummaryItems,
|
|
entryBindingCompareColumns,
|
|
entryItemBindingDetailColumns,
|
|
entryReceivingBindingColumns,
|
|
formatEntryBindingStatus,
|
|
formatReceivingCompareStatus,
|
|
formatReceivingOrderStatusLabel,
|
|
getReceivingCompareStatusTagType,
|
|
} from '../entry-config'
|
|
|
|
type ReceivingBindingRow = {
|
|
rowKey: string
|
|
receiving_id?: number
|
|
receiving_number: string
|
|
status_label: string
|
|
created_at: string
|
|
}
|
|
|
|
type ItemBindingRow = {
|
|
rowKey: string
|
|
warehouse_item_code: string
|
|
warehouse_item_name: string
|
|
entry_plan_qty: string | number
|
|
receiving_number: string
|
|
product_name: string
|
|
actual_quantity: string | number
|
|
receiving_allocated: string | number
|
|
available_quantity: string | number
|
|
binding_status_label: string
|
|
}
|
|
|
|
type ComparePreviewRow = {
|
|
rowKey: string
|
|
match_status?: string
|
|
match_status_label: string
|
|
item_name: string
|
|
entry_plan_qty: string | number
|
|
receiving_qty: string | number
|
|
receiving_allocated: string | number
|
|
}
|
|
|
|
const props = defineProps<{
|
|
id?: string | number
|
|
row?: Record<string, unknown> | null
|
|
entryDetailRefreshTick?: number
|
|
}>()
|
|
|
|
const loading = ref(false)
|
|
const compareLoading = ref(false)
|
|
const receivingBindings = ref<ReceivingBindingRow[]>([])
|
|
const itemBindingRows = ref<ItemBindingRow[]>([])
|
|
const comparePreview = ref<ReceivingCompareResponse | null>(null)
|
|
const activeCompareReceivingId = ref<number | null>(null)
|
|
|
|
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 = [
|
|
...(first.comparison ?? []),
|
|
...(first.entry_only ?? []),
|
|
...(first.receiving_only ?? []),
|
|
]
|
|
return records.map((record, index) => mapCompareRow(record, index))
|
|
})
|
|
|
|
watch(
|
|
() => [props.id, props.entryDetailRefreshTick] as const,
|
|
() => {
|
|
comparePreview.value = null
|
|
activeCompareReceivingId.value = null
|
|
if (props.id) {
|
|
void loadBindingData()
|
|
} else {
|
|
receivingBindings.value = []
|
|
itemBindingRows.value = []
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
onActivated(() => {
|
|
if (props.id) {
|
|
void loadBindingData()
|
|
}
|
|
})
|
|
|
|
function isApiSuccess(res: { code?: number; flag?: string } | null | undefined): boolean {
|
|
if (!res) return false
|
|
if (res.code === 200 || res.code === 1) return true
|
|
return res.flag === 'success'
|
|
}
|
|
|
|
function pickText(row: Record<string, unknown>, keys: string[], fallback = '—'): string {
|
|
for (const key of keys) {
|
|
const val = row[key]
|
|
if (val !== null && val !== undefined && val !== '') return String(val)
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
function pickQty(row: Record<string, unknown>, keys: string[]): string | number {
|
|
for (const key of keys) {
|
|
const val = row[key]
|
|
if (val !== null && val !== undefined && val !== '') return val as string | number
|
|
}
|
|
return '—'
|
|
}
|
|
|
|
function formatCell(value: unknown): string | number {
|
|
if (value === null || value === undefined || value === '') return '—'
|
|
return value as string | number
|
|
}
|
|
|
|
function mapReceivingBindingRow(binding: EntryOrderReceivingBinding, index: number): ReceivingBindingRow {
|
|
const receiving = (binding.receiving ?? {}) as Record<string, unknown>
|
|
const receivingId = Number(binding.receiving_id ?? receiving.id)
|
|
const status = receiving.status ?? receiving.storage_status
|
|
return {
|
|
rowKey: `recv-${binding.id ?? receivingId ?? index}`,
|
|
receiving_id: Number.isFinite(receivingId) && receivingId > 0 ? receivingId : undefined,
|
|
receiving_number: pickText(receiving, ['receiving_number'], `#${binding.receiving_id ?? index + 1}`),
|
|
status_label: formatReceivingOrderStatusLabel(status) || '—',
|
|
created_at: receiving.created_at ? formatDateTime(String(receiving.created_at)) : '—',
|
|
}
|
|
}
|
|
|
|
function mapItemBindingRow(
|
|
item: EntryDetailItem,
|
|
detail: EntryAvailableReceivingDetail,
|
|
itemIndex: number,
|
|
detailIndex: number
|
|
): ItemBindingRow {
|
|
const raw = detail as Record<string, unknown>
|
|
const allocated = raw.receiving_allocated ?? raw.allocated_quantity
|
|
const bindingStatus = raw.binding_status ?? raw.status
|
|
return {
|
|
rowKey: `${item.id ?? itemIndex}-${raw.receiving_detail_id ?? detailIndex}`,
|
|
warehouse_item_code: pickText(item as Record<string, unknown>, ['warehouse_item_code']),
|
|
warehouse_item_name: pickText(item as Record<string, unknown>, ['warehouse_item_name', 'item_name']),
|
|
entry_plan_qty: formatCell(item.count ?? item.total_planned),
|
|
receiving_number: pickText(raw, ['receiving_number']),
|
|
product_name: pickText(raw, ['product_name', 'warehouse_item_name', 'item_name']),
|
|
actual_quantity: formatCell(raw.actual_quantity),
|
|
receiving_allocated: formatCell(allocated),
|
|
available_quantity: formatCell(raw.available_quantity),
|
|
binding_status_label: formatEntryBindingStatus(bindingStatus),
|
|
}
|
|
}
|
|
|
|
function buildItemBindingRows(items: EntryDetailItem[]): ItemBindingRow[] {
|
|
const rows: ItemBindingRow[] = []
|
|
items.forEach((item, itemIndex) => {
|
|
const details = Array.isArray(item.available_receiving_details)
|
|
? item.available_receiving_details
|
|
: []
|
|
details.forEach((detail, detailIndex) => {
|
|
rows.push(mapItemBindingRow(item, detail, itemIndex, detailIndex))
|
|
})
|
|
})
|
|
return rows
|
|
}
|
|
|
|
function mapCompareRow(record: ReceivingCompareRow, index: number): ComparePreviewRow {
|
|
const raw = record as Record<string, unknown>
|
|
const matchStatus = String(raw.match_status ?? '').trim().toLowerCase()
|
|
return {
|
|
rowKey: `cmp-${index}-${matchStatus || 'row'}`,
|
|
match_status: matchStatus,
|
|
match_status_label: formatReceivingCompareStatus(raw.match_status),
|
|
item_name: pickText(raw, ['item_name', 'warehouse_item_name', 'product_name']),
|
|
entry_plan_qty: pickQty(raw, ['entry_plan_qty', 'plan_qty', 'count']),
|
|
receiving_qty: pickQty(raw, ['receiving_qty', 'receiving_quantity', 'actual_quantity', 'quantity']),
|
|
receiving_allocated: pickQty(raw, ['receiving_allocated', 'allocated_quantity']),
|
|
}
|
|
}
|
|
|
|
async function loadBindingData() {
|
|
const entryOrderId = Number(props.id)
|
|
if (!Number.isFinite(entryOrderId) || entryOrderId <= 0) {
|
|
receivingBindings.value = []
|
|
itemBindingRows.value = []
|
|
return
|
|
}
|
|
|
|
loading.value = true
|
|
try {
|
|
const res = await getEntryDetail({ id: entryOrderId })
|
|
if (!isApiSuccess(res)) {
|
|
throw new Error(res?.message || '获取绑定关系失败')
|
|
}
|
|
|
|
const entryOrder = res.entryOrder ?? res.data?.entryOrder
|
|
if (!entryOrder) {
|
|
throw new Error('入库单数据为空')
|
|
}
|
|
|
|
const bindings = Array.isArray(entryOrder.receivingBindings) ? entryOrder.receivingBindings : []
|
|
receivingBindings.value = bindings.map(mapReceivingBindingRow)
|
|
itemBindingRows.value = buildItemBindingRows(
|
|
Array.isArray(entryOrder.items) ? entryOrder.items : []
|
|
)
|
|
} catch (error) {
|
|
console.error('获取绑定关系失败:', error)
|
|
ElMessage.error('获取绑定关系失败')
|
|
receivingBindings.value = []
|
|
itemBindingRows.value = []
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function loadComparePreview(receivingId?: number) {
|
|
const entryOrderId = Number(props.id)
|
|
const normalizedReceivingId = Number(receivingId)
|
|
if (!Number.isFinite(entryOrderId) || entryOrderId <= 0) return
|
|
if (!Number.isFinite(normalizedReceivingId) || normalizedReceivingId <= 0) return
|
|
|
|
activeCompareReceivingId.value = normalizedReceivingId
|
|
compareLoading.value = true
|
|
try {
|
|
const res = await receivingCompare({
|
|
entry_order_id: entryOrderId,
|
|
receiving_id: normalizedReceivingId,
|
|
})
|
|
if (!isApiSuccess(res)) {
|
|
throw new Error(res?.message || '加载对照预览失败')
|
|
}
|
|
comparePreview.value =
|
|
res.data && typeof res.data === 'object' ? ({ ...res, ...res.data } as ReceivingCompareResponse) : res
|
|
} catch (error) {
|
|
console.error('加载对照预览失败:', error)
|
|
ElMessage.error('加载对照预览失败')
|
|
comparePreview.value = null
|
|
} finally {
|
|
compareLoading.value = false
|
|
}
|
|
}
|
|
|
|
defineExpose({
|
|
reload: loadBindingData,
|
|
})
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.entry-binding-relations {
|
|
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: 12px;
|
|
}
|
|
|
|
.summary-text {
|
|
font-size: 12px;
|
|
color: #606266;
|
|
}
|
|
}
|
|
|
|
.binding-content {
|
|
flex: 1;
|
|
min-height: 0;
|
|
overflow: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 14px;
|
|
-ms-overflow-style: none;
|
|
scrollbar-width: none;
|
|
|
|
&::-webkit-scrollbar {
|
|
display: none;
|
|
}
|
|
}
|
|
|
|
.binding-section {
|
|
.section-title {
|
|
margin-bottom: 8px;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: #303133;
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.section-subtitle {
|
|
margin-left: 8px;
|
|
font-size: 12px;
|
|
font-weight: 400;
|
|
color: #909399;
|
|
}
|
|
}
|
|
|
|
.summary-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
|
gap: 8px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.summary-card {
|
|
padding: 8px 10px;
|
|
border: 1px solid #ebeef5;
|
|
border-radius: 4px;
|
|
background: #fafafa;
|
|
|
|
.summary-value {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
line-height: 1.2;
|
|
color: #303133;
|
|
}
|
|
|
|
.summary-label {
|
|
margin-top: 4px;
|
|
font-size: 11px;
|
|
color: #909399;
|
|
}
|
|
|
|
&--success {
|
|
background: #f0f9eb;
|
|
border-color: #e1f3d8;
|
|
}
|
|
|
|
&--warning {
|
|
background: #fdf6ec;
|
|
border-color: #faecd8;
|
|
}
|
|
|
|
&--danger {
|
|
background: #fef0f0;
|
|
border-color: #fde2e2;
|
|
}
|
|
|
|
&--primary {
|
|
background: #ecf5ff;
|
|
border-color: #d9ecff;
|
|
}
|
|
}
|
|
}
|
|
</style>
|