716 lines
23 KiB
Vue
716 lines
23 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="storage-stockout"
|
||
width="220px"
|
||
: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">
|
||
<order-toolbar-button-group
|
||
:buttons="stockoutToolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="出库单列表"
|
||
default-align="center"
|
||
table-id="storage-stockout-list"
|
||
:enable-column-config="true"
|
||
: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-order_status="{ row }">
|
||
<el-tag v-if="row.order_status" :type="statusConfig[row.order_status as keyof typeof statusConfig]?.tagType || 'info'" size="small">
|
||
{{ statusConfig[row.order_status as keyof typeof statusConfig]?.text || row.order_status }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-sync_status="{ row }">
|
||
<el-tag v-if="row.sync_status" :type="syncStatusConfig[row.sync_status as keyof typeof syncStatusConfig]?.tagType || 'info'" size="small">
|
||
{{ syncStatusConfig[row.sync_status as keyof typeof syncStatusConfig]?.text || row.sync_status }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<el-button
|
||
v-if="row.order_status === 'CREATED' || row.order_status === 'PENDING'"
|
||
type="success"
|
||
link
|
||
size="small"
|
||
:loading="row._stockoutLoading"
|
||
@click.stop="handleSingleRowStockout(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 v-if="selectedStockoutId" class="lower-level" :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="logs" />
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<KeepAlive>
|
||
<component
|
||
:is="activeComponent"
|
||
:id="selectedStockoutId"
|
||
:row="selectedRow"
|
||
@refresh="loadData"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-else class="no-selection" :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="STOCKOUT"
|
||
dialog-title="批量打印出库单"
|
||
queue-no-field="stockout_order_code"
|
||
document-label="出库单"
|
||
:fetch-print-data="fetchPrintData"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed } 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 OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import * as XLSX from 'xlsx'
|
||
import * as indexApi from '@/api/index/index'
|
||
import * as stockoutApi from '@/api/storage.stockout/stockout' //现有的对应 API
|
||
|
||
import {
|
||
availableFields,
|
||
entryColums,
|
||
statusConfig,
|
||
syncStatusConfig,
|
||
stockoutToolbarButtons,
|
||
formatStockoutData,
|
||
formatStockoutListItems,
|
||
} from './stockout-config'
|
||
|
||
import stockoutdetail from './component/stockoutdetail.vue'
|
||
import product from './component/product.vue'
|
||
import log from './component/log.vue'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const {
|
||
splitStackRef,
|
||
beginSplitDrag,
|
||
lowerPaneStyle,
|
||
upperPaneStyle
|
||
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden'
|
||
}))
|
||
|
||
const detailVisible = ref(true)
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
const route = useRoute()
|
||
|
||
// 初始条件(用于 URL 预设)
|
||
const initialConditions = ref<any>(null)
|
||
|
||
// 保存原始条件(可能包含 operator 等信息)
|
||
const currentConditionRaw = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(availableFields)))
|
||
|
||
const activeTab = ref('details')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const exportLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const columns = ref(entryColums)
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedStockoutId = ref<number | string | null>(null)
|
||
const printDialogVisible = ref(false)
|
||
|
||
// ── 工具栏状态 ──
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value,
|
||
exportLoading: exportLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
hasNoSelection: !hasSelection.value
|
||
}))
|
||
|
||
const buttonLabelMap = computed(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean((buttonLoadingMap.value as Record<string, boolean>)[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean((buttonDisabledMap.value as Record<string, boolean>)[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
handleExportWaybill: () => { void handleExport('waybill') },
|
||
handleExportItem: () => { void handleExport('item') },
|
||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||
toggleDetailVisible: () => toggleDetailVisible(),
|
||
handleCreateStockout: () => handleCreateStockout(),
|
||
handleImport: () => handleImport(),
|
||
handleOpenPrintDialog: () => { void handleOpenPrintDialog() },
|
||
confirmBatchCancel: () => { void confirmBatchCancel() }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const quickSearch = ref('')
|
||
const currentSort = reactive({ prop: '', order: '' })
|
||
const currentCondition = ref<any>(null)
|
||
|
||
const componentMap: Record<string, any> = {
|
||
details: stockoutdetail,
|
||
product: product,
|
||
logs: log
|
||
}
|
||
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedStockoutId.value) || null
|
||
})
|
||
|
||
onMounted(() => {
|
||
// 先加载筛选相关数据,保证 ScanBox 的选项可用
|
||
loadFilterData()
|
||
|
||
// 支持从 URL 预设筛选(例如 ?id=xxx 或 ?delivery_order_code=xxx 或 ?q=xxx)
|
||
const idParam = route.query.id || route.query.delivery_order_code || route.query.q
|
||
const id = Array.isArray(idParam) ? idParam[0] : idParam
|
||
if (id) {
|
||
// 与 receiving 页面一致,设置 ScanBox 的初始条件用于在 UI 中显示
|
||
initialConditions.value = {
|
||
type: 'custom',
|
||
conditions: {
|
||
delivery_order_code: { value: String(id), operator: 'eq', field: 'delivery_order_code', type: 'text' }
|
||
}
|
||
}
|
||
|
||
// 使用包含 operator 的完整条件触发搜索,避免丢失操作符
|
||
handleConditionChange(initialConditions.value)
|
||
} else {
|
||
loadData()
|
||
}
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
// 优先使用由 ScanBox 提交并经过规范化的条件(包含 operator 等信息)
|
||
const where = currentCondition.value || {}
|
||
const params: any = {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where,
|
||
sort: currentSort.prop ? { sortField: currentSort.prop, sortOrder: currentSort.order === 'ascending' ? 'ASC' : 'DESC' } : undefined
|
||
}
|
||
|
||
if (quickSearch.value) {
|
||
params.where = { ...(params.where || {}), delivery_order_code: quickSearch.value }
|
||
}
|
||
|
||
const res: any = await stockoutApi.stockoutList(params)
|
||
if (res && (res.code === 200 || res.code === 1 || res.flag === 'success')) {
|
||
const data = res.data || res
|
||
list.value = formatStockoutData(data.list || [])
|
||
pagination.currentPage = data.pagination?.page || data.pagination?.currentPage || pagination.currentPage
|
||
pagination.pageSize = data.pagination?.pageSize || pagination.pageSize
|
||
pagination.total = 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 {
|
||
// 与 receiving 页面一致,按业务类型加载 store 列表和 presetTree,避免 ScanBox options 不匹配
|
||
const [storesRes, presetRes]: any = await Promise.all([
|
||
indexApi.loadStores(),
|
||
indexApi.fastWhereTree('stockout')
|
||
])
|
||
if (storesRes && storesRes.code === 200) {
|
||
const f = availableFieldsRef.find((i: any) => i.value === 'store_id')
|
||
if (f) f.options = storesRes.stores || []
|
||
}
|
||
if (presetRes && presetRes.code === 200) {
|
||
presetTree.value = presetRes.presetTree || []
|
||
}
|
||
} catch (e) {
|
||
console.error('加载筛选配置失败', e)
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
// 保存原始条件
|
||
currentConditionRaw.value = condition
|
||
|
||
// 将条件规范化为后端期望结构:{ operator, value, type }
|
||
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() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleConditionClear = () => {
|
||
currentConditionRaw.value = null
|
||
currentCondition.value = null
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditionRaw.value = null
|
||
currentCondition.value = null
|
||
pagination.currentPage = 1
|
||
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
|
||
}
|
||
|
||
// ── 打印出库单 ──
|
||
async function handleOpenPrintDialog() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先选择要打印的出库单')
|
||
return
|
||
}
|
||
|
||
// 仅“已完成”状态的出库单可打印
|
||
const invalidRows = selectionRows.value.filter(
|
||
row => String(row.order_status || '').toUpperCase() !== 'COMPLETED'
|
||
)
|
||
if (invalidRows.length > 0) {
|
||
ElMessage.warning(`只有“已完成”状态的单据才能打印。当前选中包含 ${invalidRows.length} 个非已完成单据。`)
|
||
return
|
||
}
|
||
|
||
printDialogVisible.value = true
|
||
}
|
||
|
||
async function fetchPrintData(row: any, _index: number) {
|
||
const formData: any = {
|
||
stockout_order_code: row.stockout_order_code || '',
|
||
express_code: row.express_code || '',
|
||
express_codes: row.express_codes || '',
|
||
order_type: row.order_type || '',
|
||
source_type: row.source_type || '',
|
||
order_status: row.order_status || '',
|
||
sync_status: row.sync_status || '',
|
||
store_name: row.store_name || row['store.remask'] || row['store.store_remask'] || '',
|
||
total_order_lines: row.total_order_lines ?? '',
|
||
remark: row.remark || '',
|
||
order_create_time: row.order_create_time || '',
|
||
created_at: row.created_at || '',
|
||
updated_at: row.updated_at || '',
|
||
details: []
|
||
}
|
||
|
||
try {
|
||
const res: any = await stockoutApi.stockoutListItems({ id: Number(row.id) })
|
||
if (res && (res.code === 200 || res.code === 1 || res.flag === 'success')) {
|
||
const payload = res.data || res
|
||
const order = payload.order || {}
|
||
const rows = Array.isArray(payload.list)
|
||
? payload.list
|
||
: Array.isArray(payload.items)
|
||
? payload.items
|
||
: []
|
||
formData.details = formatStockoutListItems(rows)
|
||
Object.assign(formData, {
|
||
stockout_order_code: order.stockout_order_code || formData.stockout_order_code,
|
||
express_code: order.express_code ?? formData.express_code,
|
||
express_codes: order.express_codes ?? formData.express_codes,
|
||
order_type: order.order_type ?? formData.order_type,
|
||
source_type: order.source_type ?? formData.source_type,
|
||
order_status: order.order_status ?? formData.order_status,
|
||
store_name: order.store_name ?? formData.store_name,
|
||
total_order_lines: order.total_order_lines ?? formData.total_order_lines,
|
||
remark: order.remark ?? formData.remark,
|
||
order_create_time: order.order_create_time ?? formData.order_create_time
|
||
})
|
||
}
|
||
} catch (e) {
|
||
console.error('加载出库单打印明细失败', e)
|
||
}
|
||
|
||
return formData
|
||
}
|
||
|
||
// 将 scan-box 返回的条件标准化为后端推荐结构:{ operator, value, type }
|
||
function normalizeToWhere(condition: any) {
|
||
if (!condition) return {}
|
||
|
||
// 如果是字符串或简单值,默认映射为单号模糊查询(出库单号为 delivery_order_code)
|
||
if (typeof condition === 'string' || typeof condition === 'number') {
|
||
return { delivery_order_code: { operator: 'like', value: condition, type: 'text' } }
|
||
}
|
||
|
||
const getFieldConfig = (key: string) => {
|
||
return availableFields.find((f: any) => 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'
|
||
|
||
if (c && typeof c === 'object' && !Array.isArray(c)) {
|
||
if ('operator' in c || 'value' in c || 'type' in c) {
|
||
return {
|
||
operator: c.operator || (Array.isArray(c.value) ? 'in' : (fieldType === 'daterange' ? 'between' : 'eq')),
|
||
value: c.value,
|
||
type: c.type || mapType(fieldType, c.value)
|
||
}
|
||
}
|
||
}
|
||
|
||
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 }
|
||
}
|
||
|
||
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
|
||
}
|
||
|
||
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 {}
|
||
}
|
||
|
||
async function handleRowClick(row: any) {
|
||
selectedStockoutId.value = row?.id || null
|
||
}
|
||
|
||
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 handleCreateStockout() {
|
||
ElMessage.info('新建出库单功能')
|
||
}
|
||
|
||
/** 单行一键出库 */
|
||
async function handleSingleRowStockout(row: any) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要一键出库出库单「${row.stockout_order_code || row.id}」吗?确认后状态将变更为"已完成"。请确保已填写运单号。`,
|
||
'一键出库',
|
||
{ type: 'warning', confirmButtonText: '确认', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
row._stockoutLoading = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutConfirm({ id: row.id })
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
const data = res?.data || res
|
||
if (data?.expressCode) {
|
||
row.express_code = data.expressCode
|
||
}
|
||
if (data?.expressCodes) {
|
||
row.express_codes = data.expressCodes
|
||
}
|
||
ElMessage.success('出库成功')
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '出库失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '出库失败')
|
||
} finally {
|
||
row._stockoutLoading = false
|
||
}
|
||
}
|
||
|
||
async function confirmBatchCancel() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先选择要作废的出库单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(`确定要批量作废 ${selectionRows.value.length} 个出库单吗?`, '确认', { type: 'warning' })
|
||
// 调用 API
|
||
ElMessage.success('批量作废成功')
|
||
loadData()
|
||
} catch (e) {}
|
||
}
|
||
|
||
async function handleExport(mode: 'waybill' | 'item' = 'waybill') {
|
||
const sourceRows = selectionRows.value.length ? selectionRows.value : list.value
|
||
if (!sourceRows.length) {
|
||
ElMessage.warning('当前无数据可导出')
|
||
return
|
||
}
|
||
exportLoading.value = true
|
||
try {
|
||
const exportColumns = columns.value.filter((col: any) => col.prop && col.label)
|
||
|
||
if (mode === 'waybill') {
|
||
const headers = exportColumns.map((col: any) => col.label)
|
||
const data = sourceRows.map((row: any) =>
|
||
exportColumns.map((col: any) => {
|
||
const val = row[col.prop]
|
||
if (col.prop === 'order_status') {
|
||
return statusConfig[val as keyof typeof statusConfig]?.text || val || ''
|
||
}
|
||
if (col.prop === 'sync_status') {
|
||
return syncStatusConfig[val as keyof typeof syncStatusConfig]?.text || val || ''
|
||
}
|
||
return val === null || val === undefined ? '' : val
|
||
})
|
||
)
|
||
const ws = XLSX.utils.aoa_to_sheet([headers, ...data])
|
||
const wb = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(wb, ws, '出库单列表')
|
||
XLSX.writeFile(wb, `出库单列表_${Date.now()}.xlsx`)
|
||
ElMessage.success('导出成功')
|
||
return
|
||
}
|
||
|
||
const detailRows: any[] = []
|
||
for (const row of sourceRows) {
|
||
try {
|
||
const res: any = await stockoutApi.stockoutListItems({ id: row.id })
|
||
const items = res?.data?.list || res?.list || res?.data || []
|
||
const listData = Array.isArray(items) ? items : []
|
||
listData.forEach((item: any) => {
|
||
detailRows.push({
|
||
'出库单号': row.stockout_order_code || row.id,
|
||
'商品编码': item.item_code || item.product_code || '',
|
||
'商品名称': item.item_name || item.product_name || '',
|
||
'计划数量': item.plan_qty ?? item.quantity ?? '',
|
||
'实发数量': item.actual_qty ?? item.shipped_qty ?? '',
|
||
'库位': item.space_id || item.space_name || '',
|
||
'备注': item.remark || ''
|
||
})
|
||
})
|
||
} catch (e) {
|
||
console.warn(`获取出库单 ${row.id} 明细失败`, e)
|
||
}
|
||
}
|
||
|
||
if (!detailRows.length) {
|
||
ElMessage.warning('未获取到可导出的出库明细')
|
||
return
|
||
}
|
||
|
||
const ws = XLSX.utils.json_to_sheet(detailRows)
|
||
const wb = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(wb, ws, '出库明细')
|
||
XLSX.writeFile(wb, `出库明细_${Date.now()}.xlsx`)
|
||
ElMessage.success('导出成功')
|
||
} catch (e) {
|
||
console.error('导出失败:', e)
|
||
ElMessage.error('导出失败')
|
||
} finally {
|
||
exportLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleExportAction(action: string) {
|
||
void handleExport(action === 'handleExportItem' ? 'item' : 'waybill')
|
||
}
|
||
|
||
function handleImport() {
|
||
ElMessage.info('导入功能')
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
.order-sub-container .main-content .lower-level .detail-container {
|
||
padding: 10px;
|
||
overflow: auto;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 14px;
|
||
}
|
||
</style>
|