liufumingren 401a282186 1
2026-06-12 12:17:23 +08:00

1694 lines
58 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="storage-receiving-container" :style="{ height: containerHeight }">
<scan-box ref="scanBox" width="250px" :tree-props="{ children: 'children', label: 'label' }" :auto-submit="false"
:initial-conditions="initialConditions" :preset-tree="presetTree" :available-fields="availableFieldsRef"
@condition-change="handleConditionChange" @reset="handleConditionReset" @condition-clear="handleConditionClear"
@submit="handleSubmit" />
<div class="main-content">
<div class="toolbar">
<div class="toolbar-left">
<el-button size="small" type="primary" @click="loadData">刷新</el-button>
<el-button size="small" type="primary" @click="handleCreateReceiving">添加收货单</el-button>
<!-- <el-button type="success" size="small" icon="el-icon-delete" @click="confirmcomplete" title="入库单入库"
:disabled="!hasSelection" class="toolbar-btn">
入库单入库
</el-button> -->
<el-button size="small" :loading="exportLoading" @click="handleExport">导出</el-button>
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
<el-button size="small" @click="toggleDetailVisible">{{ detailVisible ? '隐藏详情' : '显示详情' }}</el-button>
<el-button type="primary" size="small" icon="el-icon-delete" @click="confirmcomplete" title="一键入库"
:disabled="!hasSelection" class="toolbar-btn">
完成收货
</el-button>
<el-button size="small" :disabled="!hasSelection" @click="confirmBatchCancel">批量作废</el-button>
<el-button type="warning" size="small" :disabled="!hasSelection" @click="handleRejectReceiving">批量驳回</el-button>
<el-button type="primary" size="small" :disabled="!hasSelection" :loading="reviewLoading" @click="handleReviewReceiving">批量审核</el-button>
<el-button type="success" size="small" :disabled="selectionRows.length !== 1" :loading="quickPutawayLoading" @click="handleQuickPutaway">快捷入库</el-button>
<el-button type="info" size="small" icon="el-icon-printer" @click="handleOpenPrintDialog" title="打印收货单"
:disabled="!hasSelection" class="toolbar-btn">
打印收货单
</el-button>
</div>
<!-- <div class="toolbar-right">
<el-input size="small" placeholder="搜索收货单号" v-model="quickSearch" style="width:220px" @keyup.enter.native="onQuickSearch" />
</div> -->
</div>
<div class="split-stack" ref="splitStackRef">
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
<upper-table ref="upperTable" title="收货单列表" :enable-column-config="true" table-id="storage-receiving-list" :data="list" :columns="columns" :table-size="tableSize"
:pagination="pagination" :show-index="true" :show-actions="true" :show-selection="true" :loading="loading"
:queryTime="queryTime" @current-change="handleRowClick" @page-change="handlePageChange"
@page-size-change="handlePageSizeChange" @sort-change="handleSortChange" @refresh="loadData"
@selection-change="onSelectionChange">
<template #column-status="{ row }">
<el-tag v-if="row.status" :type="statusConfig[row.status as keyof typeof statusConfig]?.tagType || 'info'"
size="small">
{{ statusConfig[row.status as keyof typeof statusConfig]?.text || row.status }}
</el-tag>
</template>
<template #column-detail_status="{ row }">
<el-tag v-if="row.detail_status"
:type="detailStatusConfig[row.detail_status as keyof typeof detailStatusConfig]?.tagType || 'info'"
size="small">
{{ detailStatusConfig[row.detail_status as keyof typeof detailStatusConfig]?.text || row.detail_status }}
</el-tag>
</template>
<template #column-storage_status="{ row }">
<el-tag v-if="row.storage_status"
:type="storageStatusConfig[row.storage_status as keyof typeof storageStatusConfig]?.tagType || 'info'"
size="small">
{{ storageStatusConfig[row.storage_status as keyof typeof storageStatusConfig]?.text || row.storage_status
}}
</el-tag>
</template>
<template #column-is_review="{ row }">
<el-tag :type="row.is_review === 1 || row.is_review === true ? 'success' : 'info'" size="small">
{{ row.is_review === 1 || row.is_review === true ? '已审核' : '未审核' }}
</el-tag>
</template>
<template #column-delivery_method="{ row }">
<el-tag v-if="row.delivery_method"
:type="deliveryMethodConfig[row.delivery_method as keyof typeof deliveryMethodConfig]?.tagType || 'info'"
size="small">
{{ deliveryMethodConfig[row.delivery_method as keyof typeof deliveryMethodConfig]?.text ||
row.delivery_method }}
</el-tag>
</template>
<template #column-loading_method="{ row }">
<el-tag v-if="row.loading_method"
:type="loadingMethodConfig[row.loading_method as keyof typeof loadingMethodConfig]?.tagType || 'info'"
size="small">
{{ loadingMethodConfig[row.loading_method as keyof typeof loadingMethodConfig]?.text || row.loading_method
}}
</el-tag>
</template>
<template #column-actions="{ row }">
<el-button
v-if="row.status === 'completed' && row.detail_status === 'all_matched' && (row.is_review === 1 || row.is_review === true) && row.storage_status !== 'all'"
type="success"
link
size="small"
@click.stop="openMatchPutawayDialog(row)"
>
匹配入库
</el-button>
</template>
<template #empty>
<div class="empty-tip">暂无收货单</div>
</template>
</upper-table>
</div>
<template v-if="detailVisible">
<div
class="pane-resizer"
title="拖动调整列表与详情区域高度"
@mousedown="beginSplitDrag"
/>
<div class="lower-level" v-if="selectedReceivingId" :class="tableSize" :style="lowerPaneStyle">
<div class="detail-header">
<el-tabs v-model="activeTab" class="detail-tab">
<el-tab-pane label="收货明细" name="details" />
<el-tab-pane label="商品明细" name="product" />
<el-tab-pane label="入库记录" name="storage" />
<el-tab-pane label="操作日志" name="logs" />
</el-tabs>
</div>
<div class="detail-container">
<KeepAlive>
<component
:is="activeComponent"
class="receiving-detail-pane"
:id="selectedReceivingId"
:row="selectedRow"
:product-data="productData"
:product-total="productTotal"
:loading="productLoading"
@refresh-product="loadProductData"
@page-change="handleProductPageChange"
@page-size-change="handleProductSizeChange"
/>
</KeepAlive>
</div>
</div>
<div class="no-selection" v-else :style="lowerPaneStyle">
<div class="empty-tip">
<p>请从上方列表中选择一项查看详情</p>
</div>
</div>
</template>
</div>
</div>
<batch-receiving-print-dialog
v-model="printDialogVisible"
:selection-rows="selectionRows"
business-type="RECEIPT"
/>
<!-- 新建收货单对话框 -->
<el-dialog v-model="createDialogVisible" title="新建收货单" width="600px" align-center
@closed="handleCreateDialogClosed">
<el-form :model="createForm" label-width="100px" size="small">
<el-row :gutter="20">
<el-col v-for="field in addReceivingFieldsRef" :key="field.prop" :span="field.type === 'textarea' ? 24 : 12">
<el-form-item>
<template #label>
<span>{{ field.label }}</span>
<span v-if="['delivery_method','loading_method'].includes(field.prop)" style="color: #f56c6c; margin-left:6px">*</span>
</template>
<el-select v-if="field.type === 'select'" v-model="createForm[field.prop]"
:placeholder="'请选择' + field.label" style="width: 100%" :filterable="field.filterable">
<el-option v-for="opt in field.options" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
<el-input v-else-if="field.type === 'textarea'" v-model="createForm[field.prop]" type="textarea" :rows="3"
:placeholder="'请输入' + field.label" />
<el-input v-else v-model="createForm[field.prop]" :placeholder="'请输入' + field.label" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button size="small" @click="createDialogVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="createLoading" @click="submitCreateReceiving">确定</el-button>
</template>
</el-dialog>
<!-- 驳回收货单对话框 -->
<el-dialog v-model="rejectDialogVisible" title="批量驳回收货单" width="480px" align-center>
<el-form label-width="80px" size="small">
<el-form-item label="驳回理由">
<el-input
v-model="rejectRemark"
type="textarea"
:rows="3"
placeholder="请输入驳回理由(选填,将覆盖原备注)"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button size="small" @click="rejectDialogVisible = false">取消</el-button>
<el-button size="small" type="warning" :loading="rejectLoading" @click="submitRejectReceiving">确认驳回</el-button>
</template>
</el-dialog>
<!-- 匹配入库:左右结构,左选收货单,右对比明细 -->
<el-dialog
v-model="matchPutawayDialogVisible"
title="匹配入库"
width="92vw"
align-center
append-to-body
destroy-on-close
@closed="resetMatchPutawayDialog"
>
<div class="match-putaway-dialog">
<div class="match-left-panel">
<div class="match-panel-title">入库单列表</div>
<el-table
ref="matchEntryTableRef"
:data="matchEntryList"
v-loading="matchEntryListLoading"
highlight-current-row
border
size="small"
height="100%"
@current-change="onMatchEntrySelect"
>
<el-table-column prop="entry_order_code" label="入库单号" min-width="160" show-overflow-tooltip />
<el-table-column label="来源" width="80" align="center">
<template #default="{ row: e }">{{ entrySourceLabel(e.source_type) }}</template>
</el-table-column>
<el-table-column label="入库状态" width="90" align="center">
<template #default="{ row: e }">
<el-tag size="small" :type="entryOrderStatusTag(e.order_status)">
{{ entryOrderStatusLabel(e.order_status) }}
</el-tag>
</template>
</el-table-column>
</el-table>
</div>
<div class="match-right-panel">
<div class="match-panel-title">
明细对比
<span style="font-weight:400;color:#909399;margin-left:8px;font-size:12px">
收货单 {{ matchPutawayReceivingRow?.receiving_number || '—' }}
<template v-if="matchSelectedEntryOrder"> ← → 入库单 {{ matchSelectedEntryOrder.entry_order_code }}</template>
</span>
<el-tag
v-if="matchSelectedEntryOrder && matchComparisonRows.length"
size="small"
:type="matchComparisonSummary.type"
style="margin-left:10px"
>
{{ matchComparisonSummary.text }}
</el-tag>
</div>
<el-table
:data="matchComparisonRows"
v-loading="matchReceivingDetailsLoading || matchEntryDetailsLoading"
border
size="small"
height="100%"
row-key="stockId"
>
<el-table-column prop="productName" label="商品名称" min-width="150" show-overflow-tooltip />
<el-table-column prop="barcode" label="条码" width="130" show-overflow-tooltip />
<el-table-column prop="itemCode" label="商品编码" width="130" show-overflow-tooltip />
<el-table-column label="收货数量" width="90" align="center">
<template #default="{ row: r }">{{ r.receivingQty ?? '--' }}</template>
</el-table-column>
<el-table-column label="收货箱数" width="80" align="center">
<template #default="{ row: r }">{{ r.receivingBoxes ?? '--' }}</template>
</el-table-column>
<el-table-column label="入库应收" width="90" align="center">
<template #default="{ row: r }">{{ r.entryPlanQty ?? '--' }}</template>
</el-table-column>
<el-table-column label="入库实收" width="90" align="center">
<template #default="{ row: r }">{{ r.entryReceivedQty ?? '--' }}</template>
</el-table-column>
<el-table-column label="匹配" width="70" align="center">
<template #default="{ row: r }">
<el-tag size="small" :type="r.matched ? 'success' : 'info'">
{{ r.matched ? '已匹配' : '未匹配' }}
</el-tag>
</template>
</el-table-column>
</el-table>
</div>
</div>
<template #footer>
<div class="match-putaway-footer">
<span class="match-selection-tip">{{ matchSelectedEntryOrder ? '已选:' + matchSelectedEntryOrder.entry_order_code : '未选择入库单' }}</span>
<div>
<el-button size="small" @click="matchPutawayDialogVisible = false">取消</el-button>
<el-button
size="small"
type="primary"
:loading="matchPutawaySubmitLoading"
:disabled="!matchSelectedEntryOrder"
@click="submitMatchPutaway"
>
确认匹配入库
</el-button>
</div>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, computed, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import BatchReceivingPrintDialog from '@/components/BatchReceivingPrintDialog.vue'
import Details from './component/DetailsPanel.vue'
import StorageComp from './component/Storage.vue'
import Logs from './component/Logs.vue'
import Product from './component/Product.vue'
import * as indexApi from '@/api/index/index'
import * as receivingApi from '@/api/storage_receiving/receiving'
import * as entryApi from '@/api/storage.entry/entry'
import * as inventoryApi from '@/api/storage.inventory/inventory'
import { useSettingsStore } from '@/stores/modules/settings'
import {
receivingColumns,
availableFields,
formatReceivingData,
statusConfig,
detailStatusConfig,
storageStatusConfig,
deliveryMethodConfig,
loadingMethodConfig,
addReceivingFields
} from './receiving-config'
import * as XLSX from 'xlsx'
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
const scanBox = ref<any>(null)
const route = useRoute()
// 用于将初始条件传入 ScanBox(用于根据 URL 参数填充)
const initialConditions = ref<any>(null)
const upperTable = ref<any>(null)
const presetTree = ref<any[]>([])
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(availableFields)))
const addReceivingFieldsRef = reactive(JSON.parse(JSON.stringify(addReceivingFields)))
const settingsStore = useSettingsStore()
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
const {
splitStackRef,
beginSplitDrag,
lowerPaneStyle,
upperPaneStyle,
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
const upperPaneFullStyle = computed(() => ({
flex: '1 1 auto',
minHeight: '0',
overflow: 'hidden',
}))
const activeTab = ref('details')
const list = ref<any[]>([])
const loading = ref(false)
const exportLoading = ref(false)
const quickPutawayLoading = ref(false)
const queryTime = ref(0)
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const tableSize = ref('small')
const columns = ref(receivingColumns)
const selectionRows = ref<any[]>([])
const hasSelection = ref(false)
const selectedReceivingId = ref<number | string | null>(null)
const detailVisible = ref(true)
const quickSearch = ref('')
const currentSort = reactive({ prop: '', order: '' })
const currentCondition = ref<any>(null)
// 保存原始条件(可能包含 operator 等信息)
const currentConditionRaw = ref<any>(null)
const componentMap: Record<string, any> = {
details: Details,
storage: StorageComp,
logs: Logs,
product: Product
}
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
const selectedRow = computed(() => {
return list.value.find((i: any) => i.id === selectedReceivingId.value) || null
})
function toggleDetailVisible() {
detailVisible.value = !detailVisible.value
}
onMounted(() => {
// 先加载筛选相关数据(例如 store options、presetTree),保证 ScanBox options 可用
loadFilterData()
// 如果 URL 带有 id 参数,则构建初始筛选条件并应用
const idParam = route.query.id || route.query.receiving_number || route.query.q
const id = Array.isArray(idParam) ? idParam[0] : idParam
if (id) {
// 设置 ScanBox 的初始条件以在 UI 中显示
initialConditions.value = {
type: 'custom',
conditions: {
receiving_number: { value: String(id), operator: 'eq', field: 'receiving_number', type: 'text' }
}
}
// 直接使用包含 operator 的完整条件触发搜索(避免丢失 operator)
handleConditionChange(initialConditions.value)
} else {
// 无 URL 参数时正常加载列表
loadData()
}
})
async function loadData() {
if (loading.value) return
loading.value = true
const start = Date.now()
try {
// 直接使用 handleConditionChange 保存的完整条件(含 operator),避免丢失操作符信息
const where = currentCondition.value || {}
// console.log('当前筛选条件:', where)
// 固定条件:入库状态只显示待入库或部分入库(始终强制,不受预设或用户筛选覆盖)
where.storage_status = { operator: 'in', value: ['none', 'partial'], type: 'select' }
const params: any = {
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
where,
order: currentSort.prop ? { [currentSort.prop]: currentSort.order === 'ascending' ? 'ASC' : 'DESC' } : undefined
}
if (quickSearch.value) {
params.where.receiving_number = { operator: 'like', value: quickSearch.value, type: 'text' }
}
const res: any = await receivingApi.getReceivingList(params)
if (res && res.code === 200) {
// console.log('API 返回数据:', res.data.list)
list.value = formatReceivingData(res.data.list || [])
pagination.currentPage = res.data.pagination?.currentPage || pagination.currentPage
pagination.pageSize = res.data.pagination?.pageSize || pagination.pageSize
pagination.total = res.data.pagination?.total || (res.data.pagination?.total || 0)
} else {
ElMessage.error(res?.message || '加载失败')
}
} catch (e) {
console.error(e)
ElMessage.error('加载收货单失败')
} finally {
loading.value = false
queryTime.value = Date.now() - start
}
}
async function loadFilterData() {
try {
const [storesRes, presetRes]: any = await Promise.all([indexApi.loadStores({ type: 'receiving' }), indexApi.fastWhereTree('receiving')])
if (storesRes && storesRes.code === 200) {
const stores = storesRes.stores || []
const f = availableFieldsRef.find((i: any) => i.value === 'store_id')
if (f) f.options = stores
const af = addReceivingFieldsRef.find((i: any) => i.prop === 'store_id')
if (af) af.options = stores
}
if (presetRes && presetRes.code === 200) {
// console.log('筛选配置', presetRes)
presetTree.value = presetRes.presetTree || []
}
} catch (e) {
console.error('加载筛选配置失败', e)
}
}
function normalizeToWhere(condition: any) {
if (!condition) return {}
// 如果是字符串或简单值,直接返回为收货单号查询(默认模糊)
if (typeof condition === 'string' || typeof condition === 'number') {
return { receiving_number: { operator: 'like', value: condition, type: 'text' } }
}
// 获取字段定义的辅助函数
const getFieldConfig = (key: string) => {
return availableFields.find(f => f.value === key)
}
// 映射类型到规范格式
const mapType = (type: string, value: any) => {
if (type === 'daterange' || Array.isArray(value)) return 'daterange'
if (type === 'number' || typeof value === 'number') return 'number'
if (type === 'boolean' || typeof value === 'boolean') return 'boolean'
return 'text'
}
const processConditionValue = (k: string, c: any) => {
const config = getFieldConfig(k)
const fieldType = config?.type || 'text'
// 如果 c 本身已经是规范的对象结构 { value, operator, type }
if (c && typeof c === 'object' && !Array.isArray(c)) {
const op = c.operator || (fieldType === 'daterange' ? 'between' : 'eq')
const type = c.type || mapType(fieldType, c.value)
// isnull / isnotnull 无需值,直接传递
if (['isnull', 'isnotnull'].includes(op)) {
return { operator: op, value: null, type }
}
const val = c.value !== undefined ? c.value : c
// 空值跳过(非 isnull/isnotnull)
if (val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)) return null
// daterange 强制 type=daterange, operator=between
if (fieldType === 'daterange' || type === 'daterange') {
return { operator: 'between', value: val, type: 'daterange' }
}
return { operator: op, value: val, type }
}
// 简单空值跳过
if (c === null || c === undefined || c === '' || (Array.isArray(c) && c.length === 0)) return null
// 处理简单值
const simpleOp = fieldType === 'daterange' ? 'between' : 'eq'
const simpleType = mapType(fieldType, c)
return { operator: simpleOp, value: c, type: simpleType }
}
// 如果来自 ScanBox 的 preset(包含 conditions)
if (condition.conditions && typeof condition.conditions === 'object') {
const where: any = {}
Object.keys(condition.conditions).forEach(k => {
const result = processConditionValue(k, condition.conditions[k])
if (result) where[k] = result
})
return where
}
// 普通自定义条件对象,键 -> { value, operator, ... } 或 键 -> 简单值
if (typeof condition === 'object') {
const where: any = {}
Object.keys(condition).forEach(k => {
const result = processConditionValue(k, condition[k])
if (result) where[k] = result
})
return where
}
return {}
}
function handleConditionChange(condition: any) {
// 保留原始条件(含 operator)以备需要
currentConditionRaw.value = condition
// 将复杂条件规范化为后端期望的 where 映射
currentCondition.value = normalizeToWhere(condition)
pagination.currentPage = 1
loadData()
}
function handleSortChange({ prop, order }: any) {
currentSort.prop = prop
currentSort.order = order
pagination.currentPage = 1
loadData()
}
function handleSubmit() {
// condition-change 在 submit 之前已触发并更新了 currentCondition,直接加载即可
pagination.currentPage = 1
loadData()
}
const handleConditionClear = () => {
currentCondition.value = null // 清空已保存的条件
pagination.currentPage = 1
loadData()
}
function handleConditionReset() {
currentCondition.value = null // 清空已保存的条件
pagination.currentPage = 1
// 如果 ScanBox 提供 reset/clear 方法,调用以清空筛选条件
if (scanBox.value?.reset) {
scanBox.value.reset()
} else if (scanBox.value?.clear) {
scanBox.value.clear()
}
loadData()
}
function onSelectionChange(rows: any[]) {
selectionRows.value = rows || []
hasSelection.value = selectionRows.value.length > 0
}
const productData = ref<any[]>([])
const productLoading = ref(false)
const productTotal = ref(0)
const productPagination = reactive({ currentPage: 1, pageSize: 20 })
// 用于取消过期请求的版本号,解决快速切换行时的竞态条件
const productLoadVersion = ref(0)
async function handleRowClick(row: any) {
selectedReceivingId.value = row?.id || null
// 切换行时立即清空明细数据,并递增版本号使旧请求结果失效
productData.value = []
productTotal.value = 0
if (!selectedReceivingId.value) {
return
}
// 重置分页
productPagination.currentPage = 1
loadProductData()
}
async function loadProductData() {
const version = ++productLoadVersion.value
productLoading.value = true
try {
const params = {
id: selectedReceivingId.value,
pagination: {
page: productPagination.currentPage,
pageSize: productPagination.pageSize
}
}
const res: any = await receivingApi.getReceivingDetail(params)
// 版本不匹配说明用户已切换到其他行,丢弃此响应避免覆盖新数据
if (version !== productLoadVersion.value) return
if (res && res.code === 200 && res.data) {
// 兼容多种返回结构:res.data.receiving.details / res.data.list / res.data.details
const receivingData = res.data.receiving || {}
const details = Array.isArray(receivingData.details)
? receivingData.details
: Array.isArray(res.data.list)
? res.data.list
: Array.isArray(res.data.details)
? res.data.details
: []
const total = receivingData.pagination?.total ?? res.data.pagination?.total ?? details.length
productData.value = details
productTotal.value = total
} else {
productData.value = []
productTotal.value = 0
}
} catch (e) {
if (version !== productLoadVersion.value) return
console.error('获取收货单详情失败', e)
productData.value = []
productTotal.value = 0
} finally {
if (version === productLoadVersion.value) {
productLoading.value = false
}
}
}
function handleProductPageChange(page: number) {
productPagination.currentPage = page
loadProductData()
}
function handleProductSizeChange(size: number) {
productPagination.pageSize = size
productPagination.currentPage = 1
loadProductData()
}
function handlePageChange(page: number) {
pagination.currentPage = page
loadData()
}
function handlePageSizeChange(size: number) {
pagination.pageSize = size
pagination.currentPage = 1
loadData()
}
function onQuickSearch() {
pagination.currentPage = 1
loadData()
}
function openColumnConfigPanel() {
upperTable.value?.openColumnConfig?.()
}
function handleCreateReceiving() {
// 重置表单并打开对话框
Object.keys(createForm).forEach(key => createForm[key] = '')
createDialogVisible.value = true
}
// 新建收货单相关
const createDialogVisible = ref(false)
const createLoading = ref(false)
const createForm = reactive<any>({
store_id: '',
delivery_method: '',
loading_method: '',
license_plate: '',
tracking_number: '',
total_boxes: '',
total_pallets: '',
remark: ''
})
function handleCreateDialogClosed() {
Object.keys(createForm).forEach(key => createForm[key] = '')
}
async function submitCreateReceiving() {
// 仅校验指定的必填字段:到货方式与装卸方式
const requiredProps = ['delivery_method', 'loading_method']
for (const prop of requiredProps) {
const val = createForm[prop]
const field = addReceivingFieldsRef.find((f: any) => f.prop === prop)
const label = field ? field.label : prop
if (val === null || val === undefined || val === '') {
ElMessage.warning(`请填写${label}`)
return
}
}
const payload: any = {
delivery_method: String(createForm.delivery_method || '').trim(),
loading_method: String(createForm.loading_method || '').trim()
}
const storeId = Number(createForm.store_id)
if (Number.isFinite(storeId) && storeId > 0) {
payload.store_id = storeId
}
const totalBoxes = Number(createForm.total_boxes)
if (String(createForm.total_boxes || '').trim() !== '' && Number.isFinite(totalBoxes)) {
payload.total_boxes = totalBoxes
}
const totalPallets = Number(createForm.total_pallets)
if (String(createForm.total_pallets || '').trim() !== '' && Number.isFinite(totalPallets)) {
payload.total_pallets = totalPallets
}
const licensePlate = String(createForm.license_plate || '').trim()
if (licensePlate) payload.license_plate = licensePlate
const trackingNumber = String(createForm.tracking_number || '').trim()
if (trackingNumber) payload.tracking_number = trackingNumber
const remark = String(createForm.remark || '').trim()
if (remark) payload.remark = remark
createLoading.value = true
try {
const res: any = await receivingApi.createReceiving(payload)
// console.log('新建收货单返回结果:', res)
if (res && res.code === 200) {
const receivingNumber = res?.data?.receiving_number || res?.data?.receivingNumber || ''
ElMessage.success(receivingNumber ? `新建收货单成功:${receivingNumber}` : '新建收货单成功')
createDialogVisible.value = false
loadData()
} else {
ElMessage.error(res?.message || '新建失败')
}
} catch (e) {
console.error('新建收货单出错:', e)
ElMessage.error('新建收货单失败')
} finally {
createLoading.value = false
}
}
// 打印相关
const printDialogVisible = ref(false)
async function handleOpenPrintDialog() {
if (!selectionRows.value.length) {
ElMessage.warning('请先选择要打印的收货单')
return
}
// 校验收货状态,只有“已完成”的才能打印
const invalidRows = selectionRows.value.filter(row => row.status !== 'completed')
if (invalidRows.length > 0) {
ElMessage.warning(`只有“已完成”状态的单据才能打印。当前选中包含 ${invalidRows.length} 个非已完成单据。`)
return
}
printDialogVisible.value = true
}
async function confirmcomplete() {
if (!selectionRows.value.length) {
ElMessage.warning('请先选择要操作的收货单')
return
}
try {
await ElMessageBox.confirm(`确定要批量完成 ${selectionRows.value.length} 个收货单的收货吗?`, '确认完成', { type: 'success' })
for (const row of selectionRows.value) {
// console.log('正在执行完成收货,请求数据:', { id: row.id, type: 'complete' })
// 传递 id 标识单号,以及 type: 'complete' 来表示完成收货操作(补全请求数据)
const res: any = await receivingApi.completeReceiving({ id: row.id, type: 'complete' })
// console.log('完成收货接口返回数据:', res)
if (res && res.code === 200) {
ElMessage.success(`收货单 ${row.receiving_number} 已完成`)
} else {
ElMessage.error(`收货单 ${row.receiving_number} 操作失败: ${res.message || '系统错误'}`)
}
}
selectionRows.value = []
loadData()
} catch (e) {
if (e !== 'cancel') {
console.error('完成收货操作出错:', e)
// ElMessage.error('操作执行失败')
}
}
}
async function confirmBatchCancel() {
if (!selectionRows.value.length) {
ElMessage.warning('请先选择要操作的收货单')
return
}
try {
await ElMessageBox.confirm(`确定要批量作废 ${selectionRows.value.length} 个收货单吗?`, '确认作废', { type: 'warning' })
const ids = selectionRows.value.map(row => row.id)
const res: any = await receivingApi.batchCancelReceiving({ ids })
if (res && res.code === 200) {
ElMessage.success('批量作废成功')
} else {
ElMessage.error(res.message || '批量作废失败')
}
selectionRows.value = []
loadData()
} catch (e) {
if (e !== 'cancel') {
console.error('批量作废操作出错:', e)
// ElMessage.error('操作执行失败')
}
}
}
// 审核收货单相关
const reviewLoading = ref(false)
async function handleReviewReceiving() {
if (!selectionRows.value.length) {
ElMessage.warning('请先选择要审核的收货单')
return
}
try {
await ElMessageBox.confirm(
`确定要批量审核 ${selectionRows.value.length} 个收货单吗?\n审核后将会直接通知货主且不可撤销。`,
'确认审核',
{ type: 'warning' }
)
} catch {
return
}
reviewLoading.value = true
try {
const ids = selectionRows.value.map(row => row.id)
const res: any = await receivingApi.reviewReceiving({ ids })
if (res && res.code === 200) {
ElMessage.success(`已成功审核 ${res.data?.count ?? ids.length} 个收货单`)
selectionRows.value = []
loadData()
} else {
ElMessage.error(res?.message || '批量审核失败')
}
} catch (e) {
console.error('批量审核出错:', e)
ElMessage.error('审核操作执行失败')
} finally {
reviewLoading.value = false
}
}
// 驳回收货单相关
const rejectDialogVisible = ref(false)
const rejectLoading = ref(false)
const rejectRemark = ref('')
function handleRejectReceiving() {
if (!selectionRows.value.length) {
ElMessage.warning('请先选择要驳回的收货单')
return
}
rejectRemark.value = ''
rejectDialogVisible.value = true
}
async function submitRejectReceiving() {
rejectLoading.value = true
try {
const ids = selectionRows.value.map(row => row.id)
const payload: any = { ids }
if (rejectRemark.value) payload.remark = rejectRemark.value
const res: any = await receivingApi.rejectReceiving(payload)
if (res && res.code === 200) {
ElMessage.success(`已成功驳回 ${res.data?.count ?? ids.length} 个收货单`)
rejectDialogVisible.value = false
selectionRows.value = []
loadData()
} else {
ElMessage.error(res?.message || '驳回失败')
}
} catch (e) {
console.error('驳回收货单出错:', e)
ElMessage.error('驳回操作执行失败')
} finally {
rejectLoading.value = false
}
}
/** 入库单列表 order_status,与 storage.entry.list 一致 */
const ENTRY_ORDER_STATUS_OPTIONS = [
{ label: '待入库', value: 'PENDING' },
{ label: '入库中', value: 'PARTIAL' },
{ label: '部分收货', value: 'PARTIAL_RECEIVED' }
]
const matchPutawayDialogVisible = ref(false)
const matchPutawayReceivingRow = ref<any>(null)
const matchPutawayContextHint = ref('')
const matchEntryList = ref<any[]>([])
const matchEntryListLoading = ref(false)
const matchEntryStoreOptions = ref<any[]>([])
const matchEntryFilterOrderStatus = ref('')
/** 货主筛选值(在 fetchMatchEntryList 中作为后端查询条件使用) */
const matchEntryFilterStoreId = ref<number | string | undefined>(undefined)
const matchEntryPagination = reactive({ page: 1, pageSize: 10, total: 0 })
const matchEntryTableRef = ref<any>(null)
const matchPutawaySubmitLoading = ref(false)
// 对比视图相关
const matchReceivingDetails = ref<any[]>([])
const matchReceivingDetailsLoading = ref(false)
const matchSelectedEntryOrder = ref<any>(null)
const matchEntryDetails = ref<any[]>([])
const matchEntryDetailsLoading = ref(false)
type ComparisonRow = {
stockId: string
productName: string
barcode: string
itemCode: string
receivingQty: string | number
receivingBoxes: string | number
entryPlanQty: string | number
entryReceivedQty: string | number
matched: boolean
}
const matchComparisonRows = computed<ComparisonRow[]>(() => {
const receiving = matchReceivingDetails.value
const entries = matchEntryDetails.value
const stockMap = new Map<string, any>()
// 以入库单明细为主,建立 stock_id 索引
for (const e of entries) {
const sid = String(e.stock_id || e.item_id || e.item_code || '')
if (!sid) continue
stockMap.set(sid, { receiving: null, entry: e })
}
// 收货明细匹配到对应入库单明细
for (const r of receiving) {
const sid = String(r.system_product_id || r.stock_id || r.item_code || '')
if (!sid) continue
const existing = stockMap.get(sid)
if (existing) {
existing.receiving = r
} else {
stockMap.set(sid, { receiving: r, entry: null })
}
}
// 生成对比行:以入库单为主,确保所有入库单商品都显示
const rows: ComparisonRow[] = []
for (const e of entries) {
const sid = String(e.stock_id || e.item_id || e.item_code || '')
const pair = sid ? stockMap.get(sid) : null
const recv = pair?.receiving || null
rows.push({
stockId: sid || `e_${rows.length}`,
productName: e.item_name || recv?.product_name || '—',
barcode: recv?.barcode || '—',
itemCode: e.item_code || recv?.item_code || '—',
receivingQty: recv?.actual_quantity ?? '—',
receivingBoxes: recv?.box_quantity ?? '—',
entryPlanQty: e.count ?? e.plan_qty ?? '—',
entryReceivedQty: e.received_quantity ?? '—',
matched: !!recv
})
}
// 追加仅在收货明细中存在、入库单中没有的商品
for (const r of receiving) {
const sid = String(r.system_product_id || r.stock_id || r.item_code || '')
if (!sid) continue
const pair = stockMap.get(sid)
if (pair?.entry) continue // 已在上面处理
rows.push({
stockId: sid,
productName: r.product_name || r.item_name || '—',
barcode: r.barcode || '—',
itemCode: r.item_code || '—',
receivingQty: r.actual_quantity ?? '—',
receivingBoxes: r.box_quantity ?? '—',
entryPlanQty: '—',
entryReceivedQty: '—',
matched: false
})
}
return rows
})
const matchComparisonSummary = computed(() => {
const rows = matchComparisonRows.value
if (!rows.length) return { text: '无匹配商品', type: 'info' as const }
const matched = rows.filter(r => r.matched).length
if (matched === 0) return { text: '无匹配商品', type: 'danger' as const }
if (matched === rows.length) return { text: '全部一致', type: 'success' as const }
return { text: '部分一致', type: 'warning' as const }
})
async function onMatchEntrySelect(row: any) {
matchSelectedEntryOrder.value = row
matchEntryDetails.value = []
if (!row?.id) return
matchEntryDetailsLoading.value = true
try {
const res: any = await entryApi.getEntryDetail({ id: row.id })
if (res && res.code === 200 && res.data?.entryOrder) {
const entryOrder = res.data.entryOrder
const items = entryOrder.items || []
matchEntryDetails.value = items.map((item: any) => ({
...item,
item_name: item.stock?.item_name || item.item_name || '',
item_code: item.item_code || item.stock?.item_code || '',
stock_id: item.stock_id || item.stock?.id || '',
count: item.count ?? item.plan_qty ?? 0,
received_quantity: item.received_quantity ?? item.confirm_quantity ?? 0
}))
} else {
matchEntryDetails.value = []
}
} catch {
matchEntryDetails.value = []
} finally {
matchEntryDetailsLoading.value = false
}
}
function entryOrderStatusLabel(status: string) {
const o = ENTRY_ORDER_STATUS_OPTIONS.find(i => i.value === status)
return o?.label || status || '--'
}
function entryOrderStatusTag(status: string) {
const map: Record<string, string> = {
CREATED: 'info',
PENDING: 'warning',
PARTIAL: 'primary',
PARTIAL_RECEIVED: 'primary',
COMPLETED: 'success',
CANCELLED: 'danger'
}
return map[status] || 'info'
}
function entrySourceLabel(sourceType: string) {
const map: Record<string, string> = { QM: '奇门', API: '接口', WMS: '系统' }
return map[sourceType] || sourceType || '—'
}
/**
* 将 index.loadStores / ScanBox 等处的货主项统一为下拉可用的 { value, label }。
* 兼容 { value, label }、{ id, store_remask }、{ store_id, store_name } 等形态。
*/
function normalizeStoreOptionsForSelect(stores: any[]): { value: number; label: string }[] {
if (!Array.isArray(stores)) return []
const out: { value: number; label: string }[] = []
for (const s of stores) {
const rawVal = s?.value ?? s?.id ?? s?.store_id
if (rawVal === undefined || rawVal === null || rawVal === '') continue
const num = typeof rawVal === 'number' ? rawVal : Number(rawVal)
const value = Number.isFinite(num) ? num : (rawVal as number)
const label =
(s?.label != null && String(s.label).trim() !== '' && String(s.label)) ||
(s?.store_remask != null && String(s.store_remask)) ||
(s?.name != null && String(s.name)) ||
(s?.store_name != null && String(s.store_name)) ||
String(value)
out.push({ value: value as number, label })
}
return out
}
async function ensureMatchEntryStores() {
const storeField = availableFieldsRef.find((i: any) => i.value === 'store_id')
const fromScan = Array.isArray(storeField?.options) ? storeField.options : []
if (fromScan.length) {
matchEntryStoreOptions.value = normalizeStoreOptionsForSelect(fromScan)
return
}
if (matchEntryStoreOptions.value.length) return
try {
const res: any = await indexApi.loadStores({ type: 'receiving' })
if (res && res.code === 200) {
const raw = res.stores ?? res.data?.stores ?? []
matchEntryStoreOptions.value = normalizeStoreOptionsForSelect(raw)
}
} catch (e) {
console.error('加载货主列表失败', e)
}
}
function resetMatchPutawayDialog() {
matchPutawayReceivingRow.value = null
matchPutawayContextHint.value = ''
matchEntryList.value = []
matchEntryFilterStoreId.value = undefined
matchEntryFilterOrderStatus.value = ''
matchEntryPagination.page = 1
matchEntryPagination.total = 0
matchReceivingDetails.value = []
matchSelectedEntryOrder.value = null
matchEntryDetails.value = []
}
async function openMatchPutawayDialog(row: any) {
if (!row?.id) {
ElMessage.warning('缺少收货单信息')
return
}
const sid = row.store_id
if (sid == null || sid === '' || !Number.isFinite(Number(sid))) {
ElMessage.warning('该收货单未设置货主,请先在详情中设置货主后再匹配入库')
return
}
matchPutawayReceivingRow.value = row
matchPutawayContextHint.value = `收货单:${row.receiving_number || row.id}`
matchPutawayDialogVisible.value = true
matchEntryList.value = []
matchEntryFilterStoreId.value = Number(sid)
matchEntryFilterOrderStatus.value = ''
matchEntryPagination.page = 1
matchSelectedEntryOrder.value = null
matchEntryDetails.value = []
// 加载收货明细
matchReceivingDetailsLoading.value = true
try {
const res: any = await receivingApi.getReceivingDetail({
id: row.id,
pagination: { page: 1, pageSize: 1000 }
})
if (res && res.code === 200 && res.data) {
const d = res.data.receiving || {}
matchReceivingDetails.value = Array.isArray(d.details) ? d.details
: Array.isArray(res.data.list) ? res.data.list
: Array.isArray(res.data.details) ? res.data.details : []
} else {
matchReceivingDetails.value = []
}
} catch {
matchReceivingDetails.value = []
} finally {
matchReceivingDetailsLoading.value = false
}
await fetchMatchEntryList()
}
async function fetchMatchEntryList() {
matchEntryListLoading.value = true
try {
const where: Record<string, any> = {}
if (matchEntryFilterStoreId.value !== '' && matchEntryFilterStoreId.value != null) {
const sid = Number(matchEntryFilterStoreId.value)
if (Number.isFinite(sid)) {
where.store_id = {
operator: 'eq',
value: sid,
type: 'number'
}
}
}
if (matchEntryFilterOrderStatus.value) {
where.order_status = {
operator: 'eq',
value: matchEntryFilterOrderStatus.value,
type: 'text'
}
} else {
// 未选择时固定过滤:只显示待入库/入库中/部分收货
where.order_status = {
operator: 'in',
value: ['PENDING', 'PARTIAL', 'PARTIAL_RECEIVED'],
type: 'select'
}
}
const res: any = await entryApi.getEntryList({
pagination: {
page: matchEntryPagination.page,
pageSize: matchEntryPagination.pageSize
},
where: Object.keys(where).length ? where : {}
})
if (res && res.code === 200 && res.data) {
matchEntryList.value = res.data.list || []
matchEntryPagination.total = res.data.pagination?.total ?? 0
} else {
matchEntryList.value = []
matchEntryPagination.total = 0
if (res?.message) ElMessage.error(res.message)
}
} catch (e) {
console.error('加载入库单列表失败', e)
ElMessage.error('加载入库单列表失败')
matchEntryList.value = []
matchEntryPagination.total = 0
} finally {
matchEntryListLoading.value = false
await nextTick()
matchEntryTableRef.value?.setCurrentRow?.(undefined)
}
}
async function submitMatchPutaway() {
const row = matchPutawayReceivingRow.value
const receivingId = row?.id != null ? Number(row.id) : NaN
if (!Number.isFinite(receivingId) || receivingId <= 0) {
ElMessage.warning('缺少收货单ID')
return
}
const entry = matchSelectedEntryOrder.value
if (!entry?.id) {
ElMessage.warning('请选择一条入库单')
return
}
const entryId = Number(entry.id)
if (!Number.isFinite(entryId) || entryId <= 0) return
try {
await ElMessageBox.confirm(
`将对收货单「${row?.receiving_number || receivingId}」与入库单「${entry.entry_order_code || entryId}」执行匹配入库(按 SKU 数量匹配)。确定继续?`,
'确认匹配入库',
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }
)
} catch {
return
}
matchPutawaySubmitLoading.value = true
try {
const res: any = await inventoryApi.matchPutaway({
receiving_ids: [receivingId],
entry_order_ids: [entryId]
})
if (res && (res.code === 200 || res.flag === 'success' || res.status === 'success')) {
ElMessage.success(res.message || '匹配入库已提交')
matchPutawayDialogVisible.value = false
loadData()
} else {
ElMessage.error(res?.message || res?.msg || '匹配入库失败')
}
} catch (e: any) {
ElMessage.error(e?.message || '匹配入库请求失败')
} finally {
matchPutawaySubmitLoading.value = false
}
}
function printReceiving() {
if (!selectionRows.value.length) {
ElMessage.warning('请选择要打印的收货单')
return
}
const payload = selectionRows.value.map(r => ({ ...r, businessId: r.receiving_number }))
// 简单打印:在新窗口显示 JSON,后续可替换为正式打印组件
const w = window.open('', '_blank')
if (w) {
w.document.write(`<pre>${JSON.stringify(payload, null, 2)}</pre>`)
w.document.close()
}
}
async function handleQuickPutaway() {
if (selectionRows.value.length !== 1) {
ElMessage.warning('请仅选择一条收货单进行快捷入库')
return
}
// 校验收货单状态:要求收货单已完成(completed)且所有明细已匹配系统商品(all_matched)
const errors: string[] = []
const validRows: any[] = []
selectionRows.value.forEach(row => {
const isCompleted = (row.status || '').toLowerCase() === 'completed'
const isAllMatched = (row.detail_status || '').toLowerCase() === 'all_matched'
if (!isCompleted) {
errors.push(`收货单【${row.receiving_number}】未完成(当前状态:${row.status || '未知'})`)
} else if (!isAllMatched) {
errors.push(`收货单【${row.receiving_number}】明细未全部匹配(当前明细状态:${row.detail_status || '未全部匹配'})`)
} else {
validRows.push(row)
}
})
if (errors.length > 0) {
ElMessageBox.alert(
`<div style="max-height: 300px; overflow: auto;">${errors.join('<br/>')}</div>`,
'校验未通过,无法快捷入库',
{ confirmButtonText: '确定', dangerouslyUseHTMLString: true, type: 'error' }
)
return
}
try {
await ElMessageBox.confirm(
`确定对选中的 ${validRows.length} 条收货单执行快捷入库上架吗?`,
'快捷入库确认',
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }
)
} catch {
return
}
quickPutawayLoading.value = true
const failList: string[] = []
try {
for (const row of validRows) {
try {
const res = await receivingApi.quickPutaway({ receiving_id: row.id })
if (!res || (res.code !== 200 && res.flag !== 'success' && res.status !== 'success')) {
failList.push(`${row.receiving_number}:${res?.message || res?.msg || '接口返回失败'}`)
}
} catch (e: any) {
failList.push(`${row.receiving_number}:${e?.message || '请求异常'}`)
}
}
if (failList.length > 0) {
ElMessageBox.alert(
`<div style="max-height: 300px; overflow: auto;">${failList.join('<br/>')}</div>`,
`${failList.length} 条收货单处理失败`,
{ confirmButtonText: '确定', dangerouslyUseHTMLString: true, type: 'error' }
)
} else {
ElMessage.success('选中的收货单已全部快捷入库成功')
}
loadData()
} finally {
quickPutawayLoading.value = false
}
}
async function handleExport() {
if (selectionRows.value.length === 0) {
ElMessage.warning('请先勾选要导出的收货单')
return
}
exportLoading.value = true
try {
// 遍历勾选的收货单,每个收货单生成一个 excel 文件
for (const row of selectionRows.value) {
const productExportData: any[] = [] // 商品明细行
const receivingExportData: any[] = [] // 收货单摘要行(无明细时回退)
// 收货单摘要行(按 receivingColumns 字段)
receivingExportData.push({
'收货单号': row.receiving_number,
'收货状态': statusConfig[row.status as keyof typeof statusConfig]?.text || row.status || '',
'匹配状态': detailStatusConfig[row.detail_status as keyof typeof detailStatusConfig]?.text || row.detail_status || '',
'入库状态': storageStatusConfig[row.storage_status as keyof typeof storageStatusConfig]?.text || row.storage_status || '',
'货主': row.store_name || '',
'商品种类': row.total_items ?? '',
'总数量': row.total_quantity ?? '',
'总箱数': row.total_boxes ?? '',
'总托盘数': row.total_pallets ?? '',
'车牌号': row.license_plate || '',
'物流单号': row.tracking_number || '',
'来货方式': deliveryMethodConfig[row.delivery_method as keyof typeof deliveryMethodConfig]?.text || row.delivery_method || '',
'装卸方式': loadingMethodConfig[row.loading_method as keyof typeof loadingMethodConfig]?.text || row.loading_method || '',
'创建人': row.creator_name || '',
'收货开始': row.receiving_start_time || '',
'收货结束': row.receiving_end_time || '',
'创建时间': row.created_at || '',
'备注': row.remark || ''
})
// 获取该收货单的商品明细
try {
const res: any = await receivingApi.getReceivingDetail({
id: row.id,
pagination: { page: 1, pageSize: 10000 }
})
if (res && res.code === 200 && res.data) {
// 兼容多种返回结构
const receivingData = res.data.receiving || {}
const list = Array.isArray(receivingData.details)
? receivingData.details
: Array.isArray(res.data.list)
? res.data.list
: Array.isArray(res.data.details)
? res.data.details
: []
// 按 productquick 列导出商品明细,附带收货单号作为关联
list.forEach((item: any) => {
productExportData.push({
'收货单号': row.receiving_number,
'货主': row.store_name || '',
'商品名称': item.product_name || '',
'条码': item.barcode || '',
'匹配状态': item.system_product_id ? '已匹配' : '未匹配',
'实收数量': item.actual_quantity ?? '',
'箱数': item.box_quantity ?? '',
'箱规': item.boxes_per_pallet ?? '',
'重量': item.weight ?? '',
'批次号': item.batch_number || '',
'生产日期': item.production_date || '',
'有效期': item.expiry_date || '',
'入库状态': storageStatusConfig[item.storage_status as keyof typeof storageStatusConfig]?.text || item.storage_status || '',
'库位': item.space_id || '',
'备注': item.remark || ''
})
})
}
} catch (e) {
console.warn(`获取收货单 ${row.receiving_number} 商品明细失败,跳过`, e)
}
// 优先导出商品明细;若该收货单无明细,则回退导出收货单摘要
const exportData = productExportData.length > 0 ? productExportData : receivingExportData
const sheetName = productExportData.length > 0 ? '收货单商品明细' : '收货单摘要'
if (exportData.length > 0) {
const ws = XLSX.utils.json_to_sheet(exportData)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, sheetName)
// 文件名使用收货单号
const fileName = `${row.receiving_number}.xlsx`
XLSX.writeFile(wb, fileName)
}
}
ElMessage.success('导出完成')
} catch (e) {
console.error('导出 Excel 失败:', e)
ElMessage.error('导出失败')
} finally {
exportLoading.value = false
}
}
</script>
<style scoped lang="scss">
.storage-receiving-container {
display: flex;
// height: calc(100vh - 100px); // 移除固定高度,由模板中的 :style 控制
width: 100%;
background-color: #f0f2f5;
.main-content {
flex: 1;
display: flex;
flex-direction: column;
padding: 10px;
overflow: hidden;
.toolbar {
padding: 5px;
border-bottom: 1px solid #ebeef5;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
}
.toolbar-right {
display: flex;
flex-direction: row;
gap: 15px;
height: 30px;
align-items: center;
}
.split-stack {
flex: 1 1 auto;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.pane-resizer {
flex: 0 0 6px;
min-height: 6px;
background: #e4e7ed;
cursor: row-resize;
flex-shrink: 0;
position: relative;
z-index: 2;
&:hover {
background: #dcdfe6;
}
}
.upper-wrapper {
/* 高度占比由 :style(upperPaneStyle / upperPaneFullStyle)控制 */
overflow: hidden;
}
/* upper-table-container 已在组件内支持弹性高度,此处确保撑满 upper-wrapper */
.upper-wrapper :deep(.upper-table-container) {
height: 100%;
}
.lower-level {
display: flex;
flex-direction: column;
border-top: 1px solid #ebeef5;
overflow: hidden;
background-color: #fff;
.detail-header {
flex-shrink: 0;
padding: 0 10px;
border-bottom: 1px solid #ebeef5;
background-color: #fafafa;
.detail-tab {
margin-bottom: -1px;
:deep(.el-tabs__header) {
margin: 0;
}
:deep(.el-tabs__item) {
height: 28px;
line-height: 28px;
font-size: 12px;
padding: 0 10px;
}
:deep(.el-tabs__nav-wrap::after) {
height: 1px;
}
}
}
.detail-container {
flex: 1;
min-height: 0;
overflow: hidden;
padding: 6px 10px;
display: flex;
flex-direction: column;
box-sizing: border-box;
:deep(.receiving-detail-pane) {
flex: 1;
min-height: 0;
min-width: 0;
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
}
}
}
.no-selection {
display: flex;
align-items: center;
justify-content: center;
color: #909399;
background-color: #fff;
padding: 10px;
.empty-tip {
text-align: center;
font-size: 13px;
line-height: 1.5;
max-width: 360px;
.el-icon {
font-size: 36px;
margin-bottom: 8px;
}
}
}
}
}
.match-putaway-dialog {
display: flex;
height: 65vh;
gap: 12px;
}
.match-left-panel {
width: 300px;
flex-shrink: 0;
display: flex;
flex-direction: column;
min-height: 0;
:deep(.el-table) { height: 100%; }
}
.match-right-panel {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
}
.match-right-panel > .el-table {
flex: 1;
}
.match-panel-title {
font-size: 13px;
font-weight: 600;
color: #303133;
margin-bottom: 6px;
flex-shrink: 0;
}
.match-putaway-dialog .match-hint {
margin: 0 0 8px;
font-size: 13px;
color: #606266;
}
.match-putaway-footer {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}
.match-selection-tip {
font-size: 12px;
color: #909399;
}
</style>