1
This commit is contained in:
parent
4c9636b1ee
commit
a680b9e9b2
@ -0,0 +1,440 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="批量导入包材"
|
||||
align-center
|
||||
width="1020px"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<div class="batch-import-toolbar">
|
||||
<input
|
||||
ref="importInputRef"
|
||||
type="file"
|
||||
accept=".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
style="display: none"
|
||||
@change="handleFileChange"
|
||||
/>
|
||||
<el-button @click="triggerFileSelect">选择Excel</el-button>
|
||||
<el-button @click="downloadTemplate">下载模板</el-button>
|
||||
<el-button @click="clearData">清除数据</el-button>
|
||||
<el-button :loading="retryLoading" @click="retryFailedRows">只重试失败</el-button>
|
||||
<el-button type="primary" :loading="importLoading" @click="submitBatchImport">导入</el-button>
|
||||
<span class="picker-hint">已选文件:{{ fileName || '未选择' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="picker-table-wrap">
|
||||
<UpperTable
|
||||
:data="previewRows"
|
||||
:show-selection="false"
|
||||
:pagination="{ currentPage: 1, pageSize: 200, total: previewRows.length }"
|
||||
:columns="previewColumns"
|
||||
>
|
||||
<template #column-row_no="{ row }">
|
||||
{{ row.row_no }}
|
||||
</template>
|
||||
<template #column-material_code="{ row }">
|
||||
<span :class="{ 'cell-required-empty': !row.material_code && row.import_status !== '成功' }">
|
||||
{{ row.material_code || '--' }}
|
||||
</span>
|
||||
</template>
|
||||
<template #column-material_name="{ row }">
|
||||
<span :class="{ 'cell-required-empty': !row.material_name && row.import_status !== '成功' }">
|
||||
{{ row.material_name || '--' }}
|
||||
</span>
|
||||
</template>
|
||||
<template #column-length="{ row }">
|
||||
{{ formatCellNumber(row.length) }}
|
||||
</template>
|
||||
<template #column-width="{ row }">
|
||||
{{ formatCellNumber(row.width) }}
|
||||
</template>
|
||||
<template #column-height="{ row }">
|
||||
{{ formatCellNumber(row.height) }}
|
||||
</template>
|
||||
<template #column-weight="{ row }">
|
||||
{{ formatCellNumber(row.weight) }}
|
||||
</template>
|
||||
<template #column-cost_price="{ row }">
|
||||
{{ formatCellNumber(row.cost_price) }}
|
||||
</template>
|
||||
<template #column-status="{ row }">
|
||||
{{ formatStatusLabel(row.status) }}
|
||||
</template>
|
||||
<template #column-import_status="{ row }">
|
||||
<el-tag v-if="row.import_status === '成功'" type="success" size="small">成功</el-tag>
|
||||
<el-tag v-else-if="row.import_status === '失败'" type="danger" size="small">失败</el-tag>
|
||||
<el-tag v-else type="info" size="small">待导入</el-tag>
|
||||
</template>
|
||||
<template #column-import_message="{ row }">
|
||||
{{ row.import_message || '--' }}
|
||||
</template>
|
||||
<template #column-retry_action="{ row }">
|
||||
<el-button
|
||||
v-if="row.import_status === '失败'"
|
||||
type="primary"
|
||||
link
|
||||
size="small"
|
||||
:loading="row._retrying"
|
||||
@click="retrySingleRow(row)"
|
||||
>
|
||||
重试
|
||||
</el-button>
|
||||
<span v-else>--</span>
|
||||
</template>
|
||||
</UpperTable>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import * as XLSX from 'xlsx'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import { packageMaterialCreate } from '@/api/setting.packagematerial/packagematerial'
|
||||
import type { PackageMaterialRecord } from '../package-material-config'
|
||||
|
||||
const visible = defineModel<boolean>({ default: false })
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: []
|
||||
}>()
|
||||
|
||||
const importInputRef = ref<HTMLInputElement | null>(null)
|
||||
const importLoading = ref(false)
|
||||
const retryLoading = ref(false)
|
||||
const fileName = ref('')
|
||||
|
||||
interface ImportPreviewRow extends PackageMaterialRecord {
|
||||
row_no: number
|
||||
import_status: string
|
||||
import_message: string
|
||||
_retrying?: boolean
|
||||
}
|
||||
|
||||
const previewRows = ref<ImportPreviewRow[]>([])
|
||||
|
||||
const previewColumns = [
|
||||
{ prop: 'row_no', label: '行号', width: '70' },
|
||||
{ prop: 'material_code', label: '包材编码', minWidth: '120' },
|
||||
{ prop: 'material_name', label: '包材名称', minWidth: '140' },
|
||||
{ prop: 'material_type', label: '包材类型', minWidth: '110' },
|
||||
{ prop: 'spec', label: '规格', minWidth: '110' },
|
||||
{ prop: 'length', label: '长度', width: '80' },
|
||||
{ prop: 'width', label: '宽度', width: '80' },
|
||||
{ prop: 'height', label: '高度', width: '80' },
|
||||
{ prop: 'weight', label: '重量', width: '80' },
|
||||
{ prop: 'cost_price', label: '成本价', width: '90' },
|
||||
{ prop: 'status', label: '状态', width: '70' },
|
||||
{ prop: 'import_status', label: '导入状态', width: '100' },
|
||||
{ prop: 'import_message', label: '结果说明', minWidth: '180' },
|
||||
{ prop: 'retry_action', label: '操作', width: '80' }
|
||||
]
|
||||
|
||||
watch(visible, (opened) => {
|
||||
if (!opened) {
|
||||
fileName.value = ''
|
||||
previewRows.value = []
|
||||
}
|
||||
})
|
||||
|
||||
function triggerFileSelect() {
|
||||
importInputRef.value?.click()
|
||||
}
|
||||
|
||||
function downloadTemplate() {
|
||||
const headers = [
|
||||
'包材编码',
|
||||
'包材名称',
|
||||
'包材类型',
|
||||
'规格',
|
||||
'长度',
|
||||
'宽度',
|
||||
'高度',
|
||||
'重量',
|
||||
'成本价',
|
||||
'状态'
|
||||
]
|
||||
const sample = ['PM001', '示例纸箱', '纸箱', '60×40×30cm', 60, 40, 30, 0.5, 2.5, '启用']
|
||||
const ws = XLSX.utils.aoa_to_sheet([headers, sample])
|
||||
ws['!cols'] = headers.map(() => ({ wch: 16 }))
|
||||
const wb = XLSX.utils.book_new()
|
||||
XLSX.utils.book_append_sheet(wb, ws, '批量导入包材')
|
||||
XLSX.writeFile(wb, `包材导入模板_${Date.now()}.xlsx`)
|
||||
}
|
||||
|
||||
function clearData() {
|
||||
previewRows.value = []
|
||||
fileName.value = ''
|
||||
if (importInputRef.value) {
|
||||
importInputRef.value.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
function pickImportValue(row: Record<string, any>, keys: string[]): string {
|
||||
for (const key of keys) {
|
||||
if (Object.prototype.hasOwnProperty.call(row, key)) {
|
||||
const v = row[key]
|
||||
if (v !== null && v !== undefined && String(v).trim() !== '') {
|
||||
return String(v).trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function toImportNumber(val: any): number | undefined {
|
||||
const text = String(val ?? '').trim()
|
||||
if (!text) return undefined
|
||||
const num = Number(text)
|
||||
return Number.isFinite(num) ? num : undefined
|
||||
}
|
||||
|
||||
function parseStatus(val: string): number {
|
||||
const text = val.trim()
|
||||
if (['1', '启用', 'enable', 'enabled', 'active', '是', 'yes', 'true'].some(
|
||||
(s) => s.toLowerCase() === text.toLowerCase()
|
||||
)) {
|
||||
return 1
|
||||
}
|
||||
if (['0', '停用', 'disable', 'disabled', 'inactive', '否', 'no', 'false'].some(
|
||||
(s) => s.toLowerCase() === text.toLowerCase()
|
||||
)) {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
function formatCellNumber(val: any): string {
|
||||
if (val === null || val === undefined || val === '') return '--'
|
||||
const num = Number(val)
|
||||
return Number.isFinite(num) ? String(num) : '--'
|
||||
}
|
||||
|
||||
function formatStatusLabel(status: any): string {
|
||||
return status === 0 ? '停用' : '启用'
|
||||
}
|
||||
|
||||
async function parseExcelFile(file: File) {
|
||||
const buffer = await file.arrayBuffer()
|
||||
const workbook = XLSX.read(buffer, { type: 'array' })
|
||||
const sheetName = workbook.SheetNames[0]
|
||||
if (!sheetName) {
|
||||
ElMessage.warning('Excel 中没有可读取的工作表')
|
||||
return []
|
||||
}
|
||||
const sheet = workbook.Sheets[sheetName]
|
||||
if (!sheet) {
|
||||
ElMessage.warning('工作表读取失败')
|
||||
return []
|
||||
}
|
||||
|
||||
const rawRows = XLSX.utils.sheet_to_json<Record<string, any>>(sheet, { defval: '' })
|
||||
const result: ImportPreviewRow[] = []
|
||||
|
||||
for (let index = 0; index < rawRows.length; index += 1) {
|
||||
const row = rawRows[index] || {}
|
||||
|
||||
const materialCode = pickImportValue(row, ['包材编码', 'material_code', 'materialCode'])
|
||||
const materialName = pickImportValue(row, ['包材名称', 'material_name', 'materialName'])
|
||||
|
||||
// 跳过空行
|
||||
if (!materialCode && !materialName) continue
|
||||
|
||||
const materialType = pickImportValue(row, ['包材类型', 'material_type', 'materialType'])
|
||||
const spec = pickImportValue(row, ['规格', 'spec'])
|
||||
const length = toImportNumber(pickImportValue(row, ['长度', 'length']))
|
||||
const width = toImportNumber(pickImportValue(row, ['宽度', 'width']))
|
||||
const height = toImportNumber(pickImportValue(row, ['高度', 'height']))
|
||||
const weight = toImportNumber(pickImportValue(row, ['重量', 'weight']))
|
||||
const costPrice = toImportNumber(pickImportValue(row, ['成本价', 'cost_price', 'costPrice']))
|
||||
const status = parseStatus(pickImportValue(row, ['状态', 'status']))
|
||||
|
||||
result.push({
|
||||
row_no: index + 2,
|
||||
material_code: materialCode,
|
||||
material_name: materialName,
|
||||
material_type: materialType || undefined,
|
||||
spec: spec || undefined,
|
||||
length,
|
||||
width,
|
||||
height,
|
||||
weight,
|
||||
cost_price: costPrice,
|
||||
status,
|
||||
import_status: '待导入',
|
||||
import_message: ''
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
async function handleFileChange(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input?.files?.[0]
|
||||
input.value = ''
|
||||
if (!file) return
|
||||
|
||||
const lowerName = file.name.toLowerCase()
|
||||
if (!lowerName.endsWith('.xlsx')) {
|
||||
ElMessage.warning('仅支持上传 .xlsx 文件')
|
||||
return
|
||||
}
|
||||
|
||||
fileName.value = file.name
|
||||
|
||||
try {
|
||||
const rows = await parseExcelFile(file)
|
||||
if (!rows.length) {
|
||||
ElMessage.warning('未解析到有效数据行,请检查 Excel 内容')
|
||||
return
|
||||
}
|
||||
previewRows.value = rows
|
||||
ElMessage.success(`已解析 ${rows.length} 条包材数据`)
|
||||
} catch (error) {
|
||||
console.error('解析 Excel 失败', error)
|
||||
ElMessage.error('解析 Excel 失败')
|
||||
previewRows.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function buildCreatePayload(row: ImportPreviewRow) {
|
||||
const payload: Record<string, unknown> = {
|
||||
material_code: row.material_code,
|
||||
material_name: row.material_name,
|
||||
status: row.status
|
||||
}
|
||||
if (row.material_type) payload.material_type = row.material_type
|
||||
if (row.spec) payload.spec = row.spec
|
||||
if (row.length !== undefined && row.length !== null) payload.length = row.length
|
||||
if (row.width !== undefined && row.width !== null) payload.width = row.width
|
||||
if (row.height !== undefined && row.height !== null) payload.height = row.height
|
||||
if (row.weight !== undefined && row.weight !== null) payload.weight = row.weight
|
||||
if (row.cost_price !== undefined && row.cost_price !== null) payload.cost_price = row.cost_price
|
||||
return payload
|
||||
}
|
||||
|
||||
async function importSingleRow(row: ImportPreviewRow): Promise<boolean> {
|
||||
try {
|
||||
const payload = buildCreatePayload(row)
|
||||
const res: any = await packageMaterialCreate(payload as any)
|
||||
const ok = res && [0, 1, 200].includes(res.code)
|
||||
if (ok) {
|
||||
row.import_status = '成功'
|
||||
row.import_message = res?.message || '创建成功'
|
||||
return true
|
||||
}
|
||||
row.import_status = '失败'
|
||||
row.import_message = res?.message || '创建失败'
|
||||
return false
|
||||
} catch (error: any) {
|
||||
row.import_status = '失败'
|
||||
row.import_message = error?.message || '创建失败'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitBatchImport() {
|
||||
if (!previewRows.value.length) {
|
||||
ElMessage.warning('请先选择 Excel 文件')
|
||||
return
|
||||
}
|
||||
|
||||
// 基础校验
|
||||
const pendingRows = previewRows.value.filter((r) => r.import_status !== '成功')
|
||||
for (const row of pendingRows) {
|
||||
if (!row.material_code) {
|
||||
ElMessage.warning(`第 ${row.row_no} 行缺少包材编码,请修正后重试`)
|
||||
return
|
||||
}
|
||||
if (!row.material_name) {
|
||||
ElMessage.warning(`第 ${row.row_no} 行缺少包材名称,请修正后重试`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
importLoading.value = true
|
||||
let successCount = 0
|
||||
try {
|
||||
for (const row of pendingRows) {
|
||||
const ok = await importSingleRow(row)
|
||||
if (ok) successCount += 1
|
||||
}
|
||||
ElMessage.success(`导入完成:成功 ${successCount} 条,共 ${pendingRows.length} 条`)
|
||||
if (successCount > 0) {
|
||||
emit('success')
|
||||
}
|
||||
} finally {
|
||||
importLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function retryFailedRows() {
|
||||
const failedRows = previewRows.value.filter((r) => r.import_status === '失败')
|
||||
if (!failedRows.length) {
|
||||
ElMessage.warning('当前没有失败行可重试')
|
||||
return
|
||||
}
|
||||
|
||||
retryLoading.value = true
|
||||
let successCount = 0
|
||||
try {
|
||||
for (const row of failedRows) {
|
||||
const ok = await importSingleRow(row)
|
||||
if (ok) successCount += 1
|
||||
}
|
||||
ElMessage.success(`重试完成:成功 ${successCount} 条,共 ${failedRows.length} 条`)
|
||||
if (successCount > 0) {
|
||||
emit('success')
|
||||
}
|
||||
} finally {
|
||||
retryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function retrySingleRow(row: ImportPreviewRow) {
|
||||
row._retrying = true
|
||||
try {
|
||||
const ok = await importSingleRow(row)
|
||||
if (ok) {
|
||||
ElMessage.success(`第 ${row.row_no} 行重试成功`)
|
||||
emit('success')
|
||||
}
|
||||
} finally {
|
||||
row._retrying = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.batch-import-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.picker-hint {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.picker-table-wrap {
|
||||
max-height: 480px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.cell-required-empty {
|
||||
color: #f56c6c;
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
@ -29,7 +29,10 @@
|
||||
</el-button>
|
||||
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag>
|
||||
</div>
|
||||
<el-button type="success" size="small" @click="openCreate">新增包材</el-button>
|
||||
<div class="toolbar-right">
|
||||
<el-button type="success" size="small" @click="openCreate">新增包材</el-button>
|
||||
<el-button type="warning" size="small" plain @click="openBatchImport">批量导入</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="upper-wrapper">
|
||||
@ -186,6 +189,8 @@
|
||||
<el-button type="primary" :loading="saving" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<BatchImportDialog v-model="batchImportVisible" @success="onBatchImportSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -195,6 +200,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import BatchImportDialog from './component/BatchImportDialog.vue'
|
||||
import {
|
||||
packageMaterialCreate,
|
||||
packageMaterialDelete,
|
||||
@ -240,6 +246,7 @@ const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogMode = ref<'create' | 'edit'>('create')
|
||||
const batchImportVisible = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const formData = reactive({
|
||||
id: undefined as number | undefined,
|
||||
@ -518,6 +525,14 @@ function handleBatchDelete() {
|
||||
.catch(() => undefined)
|
||||
}
|
||||
|
||||
function openBatchImport() {
|
||||
batchImportVisible.value = true
|
||||
}
|
||||
|
||||
function onBatchImportSuccess() {
|
||||
loadList()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadList()
|
||||
})
|
||||
@ -558,6 +573,13 @@ onMounted(() => {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.upper-wrapper {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
|
||||
@ -77,6 +77,7 @@
|
||||
<el-tabs v-model="activeTab" class="detail-tab">
|
||||
<el-tab-pane label="订单明细" name="detail" />
|
||||
<el-tab-pane label="商品明细" name="items" />
|
||||
<el-tab-pane label="快递信息" name="express" />
|
||||
<el-tab-pane label="履约记录" name="fulfillment" />
|
||||
<el-tab-pane label="订单日志" name="logs" />
|
||||
</el-tabs>
|
||||
@ -89,6 +90,9 @@
|
||||
<div v-else-if="activeTab === 'items'" :key="`items-${selectedOrderId}`" class="detail-page order-detail-wrapper">
|
||||
<order-items-detail-panel :key="selectedOrderId" :row="selectedRow" :detail-request="fetchArchiveOrderDetail" />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'express'" :key="`express-${selectedOrderId}`" class="detail-page">
|
||||
<express-waybill-panel :key="selectedOrderId" :row="selectedRow" table-type="archive" />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'fulfillment'" class="detail-page">
|
||||
<p>履约历程加载中...</p>
|
||||
</div>
|
||||
@ -141,6 +145,7 @@ import {
|
||||
} from './config/order-common-config'
|
||||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.vue'
|
||||
import ExpressWaybillPanel from './component/ExpressWaybillPanel.vue'
|
||||
import log from './component/log.vue'
|
||||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||||
import { createOrderPageExport } from './utils/order-page-export'
|
||||
|
||||
@ -211,7 +211,7 @@
|
||||
clearable
|
||||
placeholder="请选择省"
|
||||
:disabled="isPreviewRowLocked(row)"
|
||||
@change="(code: any) => handlePreviewProvinceChange(row, code)"
|
||||
@change="onProvinceChange(row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in provinceOptions"
|
||||
@ -231,7 +231,7 @@
|
||||
clearable
|
||||
placeholder="请选择市"
|
||||
:disabled="isPreviewRowLocked(row) || !row.province_code"
|
||||
@change="(code: any) => handlePreviewCityChange(row, code)"
|
||||
@change="onCityChange(row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in getRowCityOptions(row)"
|
||||
@ -251,7 +251,7 @@
|
||||
clearable
|
||||
placeholder="请选择区"
|
||||
:disabled="isPreviewRowLocked(row) || !row.city_code"
|
||||
@change="(code: any) => handlePreviewAreaChange(row, code)"
|
||||
@change="onAreaChange(row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in getRowAreaOptions(row)"
|
||||
@ -861,6 +861,18 @@ function handlePreviewAreaChange(row: ImportPreviewRow, code: string) {
|
||||
markPreviewRowDirty(row)
|
||||
}
|
||||
|
||||
function onProvinceChange(row: ImportPreviewRow) {
|
||||
handlePreviewProvinceChange(row, row.province_code)
|
||||
}
|
||||
|
||||
function onCityChange(row: ImportPreviewRow) {
|
||||
handlePreviewCityChange(row, row.city_code)
|
||||
}
|
||||
|
||||
function onAreaChange(row: ImportPreviewRow) {
|
||||
handlePreviewAreaChange(row, row.area_code)
|
||||
}
|
||||
|
||||
function resolvePreviewRowRegionCodes(row: Pick<ImportPreviewRow, 'province' | 'city' | 'area'>) {
|
||||
return resolveRegionCodesFromNames({
|
||||
province_name: row.province,
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="logistics_name" label="物流公司" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="logistics_interface_name" label="快递接口" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="称重(kg)" width="110" align="right">
|
||||
<template #default="{ row }">
|
||||
{{ formatWeight(row.weighing_weight) }}
|
||||
|
||||
@ -656,7 +656,7 @@ export const pendingOrderDetailSections: OrderDetailSectionConfig[] = [
|
||||
{ prop: 'sys_platform_name', label: '来源' },
|
||||
{ prop: 'sys_platform_code', label: '平台编码', tag: true },
|
||||
{ prop: 'source_platform_name', label: '来源平台名' },
|
||||
{ prop: 'source_order_codes', label: '来源单号' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号' },
|
||||
{ prop: 'shop_nick', label: '店铺名称' },
|
||||
{ prop: 'buyer_nick', label: '买家昵称' },
|
||||
{ prop: 'seller_nick', label: '卖家昵称' },
|
||||
@ -1063,7 +1063,7 @@ export const deliveryColumns = [
|
||||
{ prop: 'sys_logistics_name', label: '系统快递', width: '120' },
|
||||
{ prop: 'express_numbers', label: '运单号', width: '160', formatter: waybillCodesFormatter },
|
||||
{ prop: 'waybill_codes', label: '运单号', width: '150', formatter: waybillCodesFormatter },
|
||||
{ prop: 'source_order_codes', label: '来源单号', width: '140' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号', width: '140' },
|
||||
{ prop: 'is_urgency', label: '是否紧急', width: '80' },
|
||||
{ prop: 'invoice_flag', label: '发票', width: '80' },
|
||||
{ prop: 'weight_type', label: '重量类型', width: '90' },
|
||||
@ -1246,7 +1246,7 @@ export const reviewOrderDetail = [
|
||||
{ prop: 'invoice_flag', label: '发票标记' },
|
||||
{ prop: 'sync_status', label: '同步状态' },
|
||||
{ prop: 'inspection_status', label: '审核状态' },
|
||||
{ prop: 'source_order_codes', label: '来源单号' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号' },
|
||||
{ prop: 'pay_no', label: '支付单号' },
|
||||
|
||||
// 金额与商品
|
||||
@ -1388,6 +1388,7 @@ export const pendingCloums = [
|
||||
{ prop: 'pay_time', label: '支付时间', width: '160', formatter: orderTimeFormatter },
|
||||
{ prop: 'place_order_time', label: '时效', width: '165', formatter: orderTimeFormatter },
|
||||
{ prop: 'sys_platform_name', label: '来源', width: '120' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号', width: '140' },
|
||||
{ prop: 'logistics_name', label: '快递', width: '120' },
|
||||
{ prop: 'remark', label: '留言', width: '160' },
|
||||
]
|
||||
@ -1402,7 +1403,7 @@ export const ORDER_LIST_FIELD_LABELS: Record<string, string> = {
|
||||
order_code: '发货单号',
|
||||
sys_platform_code: '平台编码',
|
||||
total_amount: '订单金额',
|
||||
source_order_codes: '来源单号',
|
||||
source_order_codes: '平台交易单号',
|
||||
order_type: '订单类型',
|
||||
buyer_nick: '买家昵称',
|
||||
pre_delivery_order_code: '前置单号',
|
||||
@ -1457,7 +1458,7 @@ export const pendingOrderDetail = [
|
||||
{ prop: 'sync_status', label: '同步状态' },
|
||||
{ prop: 'is_urgency', label: '是否紧急' },
|
||||
{ prop: 'invoice_flag', label: '发票标记' },
|
||||
{ prop: 'source_order_codes', label: '来源单号' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号' },
|
||||
{ prop: 'pay_no', label: '支付单号' },
|
||||
|
||||
// 金额与商品
|
||||
|
||||
@ -162,6 +162,7 @@
|
||||
<el-tabs v-model="activeTab" class="detail-tab">
|
||||
<el-tab-pane label="订单明细" name="detail" />
|
||||
<el-tab-pane label="商品明细" name="items" />
|
||||
<el-tab-pane label="快递信息" name="express" />
|
||||
<el-tab-pane label="订单日志" name="logs" />
|
||||
</el-tabs>
|
||||
</div>
|
||||
@ -178,6 +179,9 @@
|
||||
<div v-else-if="activeTab === 'items'" :key="`items-${selectedOrderId}`" class="detail-page order-detail-wrapper">
|
||||
<order-items-detail-panel :key="selectedOrderId" :row="selectedRow" :detail-request="fetchDeliveryOrderDetail" />
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'express'" :key="`express-${selectedOrderId}`" class="detail-page">
|
||||
<express-waybill-panel :key="selectedOrderId" :row="selectedRow" table-type="dispatch" />
|
||||
</div>
|
||||
<div v-else :key="`logs-${selectedOrderId}`" class="detail-page order-log-wrapper">
|
||||
<log :key="selectedOrderId" :data="selectedRow" />
|
||||
</div>
|
||||
@ -237,6 +241,7 @@ import {
|
||||
} from './config/order-common-config'
|
||||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.vue'
|
||||
import ExpressWaybillPanel from './component/ExpressWaybillPanel.vue'
|
||||
import log from './component/log.vue'
|
||||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||||
import WavePlatformPrintPreviewDialog from '@/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue'
|
||||
|
||||
@ -168,7 +168,7 @@
|
||||
<el-tab-pane label="商品明细" name="items" />
|
||||
<!-- <el-tab-pane label="配货信息" name="picking" /> -->
|
||||
<el-tab-pane label="订单日志" name="logs" />
|
||||
<el-tab-pane label="运单作业" name="waybill" />
|
||||
<el-tab-pane label="快递信息" name="waybill" />
|
||||
<!-- <el-tab-pane label="归档订单" name="archive" /> -->
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
@ -426,7 +426,6 @@
|
||||
:error-message="platformPrintErrorMessage"
|
||||
:payload="platformPrintPayload"
|
||||
:request-meta="platformPrintRequestMeta"
|
||||
enable-printer-picker
|
||||
@refresh="handlePlatformPrintDialogRefresh"
|
||||
@print-success="handlePlatformPrintListRefresh"
|
||||
/>
|
||||
|
||||
@ -13,21 +13,23 @@
|
||||
</div>
|
||||
<div v-else-if="payload" ref="printRootRef" class="wave-print-body">
|
||||
<div class="wave-print-settings-bar">
|
||||
<el-select
|
||||
v-model="printSettings.station"
|
||||
placeholder="请选择打印台"
|
||||
size="small"
|
||||
:loading="stationLoading"
|
||||
@change="handleStationChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in stationOptions"
|
||||
:key="item.stationId"
|
||||
:label="item.name"
|
||||
:value="item.stationId"
|
||||
/>
|
||||
</el-select>
|
||||
<template v-if="enablePrinterPicker">
|
||||
<template v-if="printMode === 'station'">
|
||||
<el-select
|
||||
v-model="printSettings.station"
|
||||
placeholder="请选择打印台"
|
||||
size="small"
|
||||
:loading="stationLoading"
|
||||
@change="handleStationChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in stationOptions"
|
||||
:key="item.stationId"
|
||||
:label="item.name"
|
||||
:value="item.stationId"
|
||||
/>
|
||||
</el-select>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-select
|
||||
v-model="printSettings.defaultPrinter"
|
||||
placeholder="请选择默认打印机"
|
||||
@ -50,7 +52,7 @@
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<section v-if="enablePrinterPicker && uniqueExpressList.length > 0" class="wave-print-express-printers">
|
||||
<section v-if="printMode === 'browser' && uniqueExpressList.length > 0" class="wave-print-express-printers">
|
||||
<div class="wave-print-express-printers__header">
|
||||
<span class="wave-print-express-printers__title">快递打印机(留空则使用默认打印机)</span>
|
||||
</div>
|
||||
@ -202,21 +204,32 @@
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visibleProxy = false">关闭</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="stationPrinting"
|
||||
:disabled="!payload || !printSettings.station || !hasWaveGroups"
|
||||
@click="printToStation"
|
||||
>
|
||||
打印到打印台
|
||||
</el-button>
|
||||
<el-button
|
||||
:loading="browserPrinting"
|
||||
:disabled="!payload || !hasWaveGroups"
|
||||
@click="printReport"
|
||||
>
|
||||
浏览器打印
|
||||
</el-button>
|
||||
<el-button-group>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="printMode === 'station' ? stationPrinting : browserPrinting"
|
||||
:disabled="!payload || (printMode === 'station' ? (!printSettings.station || !hasWaveGroups) : !hasWaveGroups)"
|
||||
@click="handlePrint"
|
||||
>
|
||||
打印
|
||||
</el-button>
|
||||
<el-dropdown trigger="click" @command="handlePrintModeSwitch">
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="!payload"
|
||||
>▾</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="station" :class="{ 'is-active': printMode === 'station' }">
|
||||
打印到打印台 {{ printMode === 'station' ? '✓' : '' }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="browser" :class="{ 'is-active': printMode === 'browser' }">
|
||||
浏览器打印 {{ printMode === 'browser' ? '✓' : '' }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-button-group>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@ -237,7 +250,6 @@ import {
|
||||
buildWaveGroupsForNotifyLock,
|
||||
collectWavePlatformPrintComponents,
|
||||
fetchConnectedComponentPrinters,
|
||||
parseExpressPrinterMapFromStationDetail,
|
||||
sendWavePlatformBrowserPrint,
|
||||
type BrowserWavePrintItemResult
|
||||
} from '../config/print'
|
||||
@ -270,8 +282,6 @@ const props = defineProps<{
|
||||
errorMessage: string
|
||||
payload: WavePlatformPrintDataPayload | null
|
||||
requestMeta: { warehouse_id: number; wave_ids: Array<number | string> } | null
|
||||
/** 散单波次等场景:展示本机打印机选择 */
|
||||
enablePrinterPicker?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@ -281,6 +291,10 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const printRootRef = ref<HTMLElement | null>(null)
|
||||
|
||||
// 模块级缓存:打印台列表不常变,弹窗关闭再打开时复用
|
||||
let _cachedStationOptions: StationOption[] | null = null
|
||||
|
||||
/** 下拉值使用打印台主键 stationId(print.send express 的 printStationId);computer_id_legacy 用于迁移旧版本地存储 */
|
||||
type StationOption = {
|
||||
stationId: string
|
||||
@ -306,7 +320,40 @@ const printSettings = reactive({
|
||||
defaultPrinter: '' as string
|
||||
})
|
||||
|
||||
const enablePrinterPicker = computed(() => props.enablePrinterPicker === true)
|
||||
const WAVE_PRINT_MODE_KEY = 'wave_platform_print_mode'
|
||||
const printMode = ref(loadPrintMode())
|
||||
|
||||
function loadPrintMode(): string {
|
||||
try {
|
||||
return localStorage.getItem(WAVE_PRINT_MODE_KEY) || 'station'
|
||||
} catch {
|
||||
return 'station'
|
||||
}
|
||||
}
|
||||
|
||||
function savePrintMode(mode: string) {
|
||||
try {
|
||||
localStorage.setItem(WAVE_PRINT_MODE_KEY, mode)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
function handlePrintModeSwitch(mode: string) {
|
||||
printMode.value = mode
|
||||
savePrintMode(mode)
|
||||
if (mode === 'browser') {
|
||||
loadPrinterOptions()
|
||||
}
|
||||
}
|
||||
|
||||
function handlePrint() {
|
||||
if (printMode.value === 'station') {
|
||||
printToStation()
|
||||
} else {
|
||||
printReport()
|
||||
}
|
||||
}
|
||||
|
||||
const visibleProxy = computed({
|
||||
get: () => props.modelValue,
|
||||
@ -367,9 +414,8 @@ watch(
|
||||
void (async () => {
|
||||
resetExpressPrinterOverrides()
|
||||
await loadStationOptions()
|
||||
if (enablePrinterPicker.value) {
|
||||
if (printMode.value === 'browser') {
|
||||
await loadPrinterOptions()
|
||||
await applyStationPrinterDefaults()
|
||||
}
|
||||
})()
|
||||
} else {
|
||||
@ -384,11 +430,10 @@ watch(
|
||||
// 父级刷新到新 payload 后,清空本地已解锁过滤,确保页面展示后端最新状态
|
||||
unlockedPlatformKeys.value = new Set()
|
||||
unlockingPlatformKey.value = ''
|
||||
if (props.modelValue && enablePrinterPicker.value) {
|
||||
if (props.modelValue && printMode.value === 'browser') {
|
||||
void (async () => {
|
||||
resetExpressPrinterOverrides()
|
||||
await loadPrinterOptions()
|
||||
await applyStationPrinterDefaults()
|
||||
})()
|
||||
}
|
||||
}
|
||||
@ -762,6 +807,13 @@ function mapStationRow(item: Record<string, any>): StationOption {
|
||||
async function loadStationOptions() {
|
||||
stationLoading.value = true
|
||||
try {
|
||||
// 优先使用缓存,避免弹窗每次打开都请求
|
||||
if (_cachedStationOptions) {
|
||||
stationOptions.value = _cachedStationOptions
|
||||
const savedStation = getSavedStationId()
|
||||
if (savedStation) printSettings.station = savedStation
|
||||
return
|
||||
}
|
||||
const stations: any = await stationApi.getList({ page: 1, pageSize: 100, where: {} })
|
||||
if (!isApiSuccess(stations)) {
|
||||
stationOptions.value = []
|
||||
@ -771,6 +823,7 @@ async function loadStationOptions() {
|
||||
}
|
||||
const rawList = extractPrintStationRows(stations)
|
||||
stationOptions.value = rawList.filter((x) => x && typeof x === 'object').map((item: any) => mapStationRow(item))
|
||||
_cachedStationOptions = stationOptions.value
|
||||
|
||||
// 初始化默认打印台:优先本地存储,其次当前值,最后回退到首项
|
||||
const savedStation = getSavedStationId()
|
||||
@ -822,9 +875,8 @@ async function handleStationChange(val: string | number) {
|
||||
return
|
||||
}
|
||||
saveStationId(stationId)
|
||||
if (enablePrinterPicker.value) {
|
||||
if (printMode.value === 'browser') {
|
||||
await loadComputerPrintersForStation(stationId).then((names) => mergePrinterOptionNames(names))
|
||||
await applyStationPrinterDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
@ -848,25 +900,32 @@ function mergePrinterOptionNames(names: string[]) {
|
||||
printerOptions.value = [...merged.values()].sort((a, b) => a.label.localeCompare(b.label, 'zh-CN'))
|
||||
}
|
||||
|
||||
const _printerCache = new Map<string, Promise<string[]>>()
|
||||
|
||||
async function loadComputerPrintersForStation(stationId: string): Promise<string[]> {
|
||||
const station = stationOptions.value.find((item) => item.stationId === stationId)
|
||||
const computerId = String(station?.computer_id_legacy || '').trim()
|
||||
if (!computerId) return []
|
||||
try {
|
||||
const res: any = await stationApi.getComputerPrinter(computerId)
|
||||
if (!isApiSuccess(res)) return []
|
||||
const root = res?.data
|
||||
const printerList = Array.isArray(root) ? root : Array.isArray(root?.list) ? root.list : []
|
||||
return printerList
|
||||
.map((item: any) => String(item?.name ?? item?.printerName ?? item ?? '').trim())
|
||||
.filter(Boolean)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
// 缓存 Promise 防止并发竞态,同一 computerId 并发调用共享同一个请求
|
||||
if (_printerCache.has(computerId)) return _printerCache.get(computerId)!
|
||||
const promise = (async () => {
|
||||
try {
|
||||
const res: any = await stationApi.getComputerPrinter(computerId)
|
||||
if (!isApiSuccess(res)) return [] as string[]
|
||||
const root = res?.data
|
||||
const printerList = Array.isArray(root) ? root : Array.isArray(root?.list) ? root.list : []
|
||||
return printerList
|
||||
.map((item: any) => String(item?.name ?? item?.printerName ?? item ?? '').trim())
|
||||
.filter(Boolean)
|
||||
} catch {
|
||||
return [] as string[]
|
||||
}
|
||||
})()
|
||||
_printerCache.set(computerId, promise)
|
||||
return promise
|
||||
}
|
||||
|
||||
async function loadPrinterOptions() {
|
||||
if (!enablePrinterPicker.value) return
|
||||
printerLoading.value = true
|
||||
try {
|
||||
usePrinterComponentStore().refreshFromRuntime()
|
||||
@ -902,34 +961,6 @@ async function loadPrinterOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
async function applyStationPrinterDefaults() {
|
||||
const stationId = String(printSettings.station || '').trim()
|
||||
if (!stationId) return
|
||||
|
||||
const { defaultPrinter, expressPrinterMap } = await loadStationPrinterBindings(stationId)
|
||||
mergePrinterOptionNames([defaultPrinter, ...Object.values(expressPrinterMap)])
|
||||
|
||||
const computerPrinters = await loadComputerPrintersForStation(stationId)
|
||||
mergePrinterOptionNames(computerPrinters)
|
||||
|
||||
const saved = getSavedDefaultPrinter()
|
||||
if (saved && printerOptions.value.some((item) => item.value === saved)) {
|
||||
printSettings.defaultPrinter = saved
|
||||
} else if (defaultPrinter) {
|
||||
printSettings.defaultPrinter = defaultPrinter
|
||||
}
|
||||
|
||||
uniqueExpressList.value.forEach((item) => {
|
||||
const code = item.sys_logistics_code
|
||||
const name = item.sys_logistics_name
|
||||
const mapped = (code && expressPrinterMap[code]) || (name && expressPrinterMap[name]) || ''
|
||||
if (mapped) {
|
||||
expressPrinterOverrides[item.key] = mapped
|
||||
mergePrinterOptionNames([mapped])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleDefaultPrinterChange(val: string | number) {
|
||||
const printer = String(val || '').trim()
|
||||
if (!printer) {
|
||||
@ -1073,54 +1104,6 @@ function clearSavedStationId() {
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapPrintStationRecord(data: unknown): Record<string, unknown> {
|
||||
if (!data || typeof data !== 'object') return {}
|
||||
const root = data as Record<string, unknown>
|
||||
if (root.data && typeof root.data === 'object' && !Array.isArray(root.data)) {
|
||||
return root.data as Record<string, unknown>
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
async function loadStationPrinterBindings(stationId: string) {
|
||||
console.log('[wave browser print] loadStationPrinterBindings: 开始', { stationId })
|
||||
const fallback = stationOptions.value.find((item) => item.stationId === stationId)
|
||||
const fallbackDefault = fallback?.default_printer_name ?? ''
|
||||
try {
|
||||
const res: any = await stationApi.getItem(stationId)
|
||||
if (!isApiSuccess(res)) {
|
||||
console.log('[wave browser print] loadStationPrinterBindings: API 失败,使用 fallback', {
|
||||
stationId,
|
||||
fallbackDefault,
|
||||
})
|
||||
return {
|
||||
defaultPrinter: fallbackDefault,
|
||||
expressPrinterMap: {} as Record<string, string>
|
||||
}
|
||||
}
|
||||
const parsed = parseExpressPrinterMapFromStationDetail(unwrapPrintStationRecord(res?.data ?? res))
|
||||
console.log('[wave browser print] loadStationPrinterBindings: 成功', {
|
||||
stationId,
|
||||
defaultPrinter: parsed.defaultPrinter || fallbackDefault,
|
||||
expressPrinterMap: parsed.expressPrinterMap,
|
||||
})
|
||||
return {
|
||||
defaultPrinter: parsed.defaultPrinter || fallbackDefault,
|
||||
expressPrinterMap: parsed.expressPrinterMap
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('[wave browser print] loadStationPrinterBindings: 异常,使用 fallback', {
|
||||
stationId,
|
||||
fallbackDefault,
|
||||
error,
|
||||
})
|
||||
return {
|
||||
defaultPrinter: fallbackDefault,
|
||||
expressPrinterMap: {} as Record<string, string>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function printReport() {
|
||||
console.log('[wave browser print] printReport: 用户点击浏览器打印')
|
||||
|
||||
@ -1168,23 +1151,15 @@ async function printReport() {
|
||||
console.log('[wave browser print] printReport: 刷新打印组件 runtime 状态')
|
||||
usePrinterComponentStore().refreshFromRuntime()
|
||||
|
||||
const hasStation = String(printSettings.station || '').trim().length > 0
|
||||
const { defaultPrinter: stationDefaultPrinter, expressPrinterMap: stationExpressMap } = hasStation
|
||||
? await loadStationPrinterBindings(printSettings.station)
|
||||
: { defaultPrinter: '', expressPrinterMap: {} as Record<string, string> }
|
||||
const userDefaultPrinter = String(printSettings.defaultPrinter || '').trim()
|
||||
const expressPrinterMap = buildEffectiveExpressPrinterMap({})
|
||||
|
||||
const userDefaultPrinter = String(printSettings.defaultPrinter || stationDefaultPrinter || '').trim()
|
||||
const expressPrinterMap = enablePrinterPicker.value
|
||||
? buildEffectiveExpressPrinterMap(stationExpressMap)
|
||||
: stationExpressMap
|
||||
|
||||
if (enablePrinterPicker.value && !userDefaultPrinter && !Object.keys(expressPrinterMap).length) {
|
||||
if (!userDefaultPrinter && !Object.keys(expressPrinterMap).length) {
|
||||
ElMessage.warning('请选择默认打印机,或为各快递指定打印机')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[wave browser print] printReport: 打印机映射来源', {
|
||||
hasStation,
|
||||
userDefaultPrinter,
|
||||
expressPrinterMapKeys: Object.keys(expressPrinterMap),
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user