This commit is contained in:
liufumingren 2026-06-07 01:52:20 +08:00
parent faf5e76526
commit b561cf3a77
5 changed files with 198 additions and 44 deletions

View File

@ -86,6 +86,7 @@ export type PendingOrderCreateOrderParams = {
logistics_code?: string; logistics_code?: string;
logistics_name?: string; logistics_name?: string;
sys_platform_code?: string; sys_platform_code?: string;
shop_nick?: string;
source_platform_code?: string; source_platform_code?: string;
source_order_codes?: string; source_order_codes?: string;
order_type?: string; order_type?: string;

View File

@ -1441,6 +1441,11 @@ watch(
</script> </script>
<style scoped> <style scoped>
/* 表头居中 */
:deep(.el-table__header-wrapper th .cell) {
text-align: center;
}
/* 基础样式 */ /* 基础样式 */
.upper-table-container { .upper-table-container {
display: flex; display: flex;

View File

@ -6,6 +6,7 @@
align-center align-center
append-to-body append-to-body
destroy-on-close destroy-on-close
:before-close="handleBeforeClose"
@closed="resetImportOrderDialog" @closed="resetImportOrderDialog"
> >
<!-- <el-alert <!-- <el-alert
@ -31,6 +32,7 @@
<el-button type="primary" :loading="importOrderLoading" :disabled="parseImportFileLoading" @click="submitImportOrders"> <el-button type="primary" :loading="importOrderLoading" :disabled="parseImportFileLoading" @click="submitImportOrders">
确认创建 确认创建
</el-button> </el-button>
<el-button @click="handleCloseClick">关闭</el-button>
<el-select <el-select
v-model="defaultStoreId" v-model="defaultStoreId"
filterable filterable
@ -65,17 +67,6 @@
@row-click="handlePreviewRowClick" @row-click="handlePreviewRowClick"
@selection-change="handlePreviewSelectionChange" @selection-change="handlePreviewSelectionChange"
> >
<template #column-_issue="{ row }">
<div v-if="getRowIssues(row).length" class="issue-indicator">
<el-tooltip
:content="getRowIssues(row).join(';')"
placement="right"
effect="dark"
>
<span class="issue-text">{{ getRowIssues(row).length }}项异常</span>
</el-tooltip>
</div>
</template>
<template #column-delivery_order_code="{ row }"> <template #column-delivery_order_code="{ row }">
<div :class="{ 'cell-required-empty': row._orderExists }"> <div :class="{ 'cell-required-empty': row._orderExists }">
<el-input <el-input
@ -84,7 +75,7 @@
clearable clearable
placeholder="留空自动生成" placeholder="留空自动生成"
:disabled="isPreviewRowLocked(row)" :disabled="isPreviewRowLocked(row)"
@change="markPreviewRowDirty(row)" @change="(val: string) => handleDeliveryOrderCodeChange(row, val)"
/> />
</div> </div>
</template> </template>
@ -108,6 +99,16 @@
</el-select> </el-select>
</div> </div>
</template> </template>
<template #column-shop_nick="{ row }">
<el-input
v-model="row.shop_nick"
size="small"
clearable
placeholder="自定义店铺名称"
:disabled="isPreviewRowLocked(row)"
@change="markPreviewRowDirty(row)"
/>
</template>
<template #column-name="{ row }"> <template #column-name="{ row }">
<div :class="{ 'cell-required-empty': isRequiredFieldEmpty(row, 'name') }"> <div :class="{ 'cell-required-empty': isRequiredFieldEmpty(row, 'name') }">
<el-input <el-input
@ -251,23 +252,61 @@
</el-select> </el-select>
</template> </template>
<template #column-selected_items="{ row }"> <template #column-selected_items="{ row }">
<div :class="{ 'cell-required-empty': hasUnmatchedItems(row) }"> <div
<el-button :class="{ 'cell-required-empty': hasUnmatchedItems(row) }"
type="primary" class="selected-items-cell"
link >
size="small" <template v-if="row.selected_items.length">
:disabled="isPreviewRowLocked(row)" <el-tooltip
@click.stop="openSelectProductDialog(row)" placement="top"
> :show-after="300"
添加商品{{ row.selected_items.length ? `(${row.selected_items.length})` : '' }} :disabled="row.selected_items.length <= 1"
</el-button> >
<template #content>
<div class="selected-items-tooltip">
<div v-for="(item, idx) in row.selected_items" :key="idx">
{{ item.item_name || item.item_code }} × {{ item.plan_qty }}
</div>
</div>
</template>
<span
class="selected-items-summary"
:class="{ 'is-clickable': !isPreviewRowLocked(row) }"
@click.stop="isPreviewRowLocked(row) || openSelectProductDialog(row)"
>
{{ formatSelectedItemsSummary(row.selected_items) }}
</span>
</el-tooltip>
</template>
<template v-else>
<el-button
type="primary"
link
size="small"
:disabled="isPreviewRowLocked(row)"
@click.stop="openSelectProductDialog(row)"
>
添加商品
</el-button>
</template>
</div> </div>
</template> </template>
<template #column-import_status="{ row }"> <template #column-import_status="{ row }">
<el-tag v-if="row.import_status === '成功'" type="success" size="small">成功</el-tag> <div class="combined-status">
<el-tag v-else-if="row.import_status === '失败'" type="danger" size="small">失败</el-tag> <el-tag v-if="row.import_status === '成功'" type="success" size="small">成功</el-tag>
<el-tag v-else-if="row.import_status === '待创建'" type="info" size="small">待创建</el-tag> <el-tag v-else-if="row.import_status === '失败'" type="danger" size="small">失败</el-tag>
<span v-else>{{ row.import_status || '—' }}</span> <el-tag v-else-if="row.import_status === '待创建'" type="info" size="small">待创建</el-tag>
<span v-else>{{ row.import_status || '—' }}</span>
<template v-if="getRowIssues(row).length">
<el-tooltip
:content="getRowIssues(row).join(';')"
placement="right"
effect="dark"
>
<span class="issue-text">{{ getRowIssues(row).length }}项异常</span>
</el-tooltip>
</template>
</div>
</template> </template>
<template #column-row_action="{ row }"> <template #column-row_action="{ row }">
<el-button type="danger" link size="small" :disabled="isPreviewRowLocked(row)" @click="removeImportPreviewRow(row)"> <el-button type="danger" link size="small" :disabled="isPreviewRowLocked(row)" @click="removeImportPreviewRow(row)">
@ -289,7 +328,7 @@
</span> </span>
</template> </template>
</div> </div>
<div v-else class="address-panel-meta address-panel-meta--empty">请先勾选左侧订单行</div> <div v-else class="address-panel-meta address-panel-meta--empty">未勾选行时,识别地址将自动新建一行</div>
</div> </div>
<el-input <el-input
@ -299,20 +338,19 @@
resize="none" resize="none"
class="address-paste-input" class="address-paste-input"
placeholder="粘贴完整地址,如:张三 13800138000 广东省广州市天河区体育西路100号" placeholder="粘贴完整地址,如:张三 13800138000 广东省广州市天河区体育西路100号"
:disabled="!selectedPreviewRowsForAddress.length"
/> />
<div class="address-panel-actions"> <div class="address-panel-actions">
<el-button <el-button
type="primary" type="primary"
:loading="parseAddressLoading" :loading="parseAddressLoading"
:disabled="!selectedPreviewRowsForAddress.length || !addressPasteText.trim()" :disabled="!addressPasteText.trim()"
@click="handleParseAddress" @click="handleParseAddress"
> >
识别地址 识别地址
</el-button> </el-button>
<el-button <el-button
:disabled="!selectedPreviewRowsForAddress.length || !addressPasteText.trim()" :disabled="!addressPasteText.trim()"
@click="addressPasteText = ''" @click="addressPasteText = ''"
> >
清空 清空
@ -345,14 +383,14 @@
</div> --> </div> -->
<template #footer> <template #footer>
<el-button @click="visible = false">关闭</el-button> <el-button @click="handleCloseClick">关闭</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, nextTick, ref, watch } from 'vue' import { computed, nextTick, ref, watch } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import * as XLSX from 'xlsx' import * as XLSX from 'xlsx'
import UpperTable from '@/components/UpperTable/index.vue' import UpperTable from '@/components/UpperTable/index.vue'
import SelectProductDialog from './SelectProductDialog.vue' import SelectProductDialog from './SelectProductDialog.vue'
@ -405,6 +443,8 @@ type PreviewSelectedItem = SelectProductItem
type ImportPreviewRow = { type ImportPreviewRow = {
_rowKey: string _rowKey: string
_orderExists?: boolean _orderExists?: boolean
/** 触发 _orderExists 的原始订单号,用于判断用户是否已修改 */
_orderExistsCode?: string
row_no: number row_no: number
delivery_order_code: string delivery_order_code: string
store_id?: number store_id?: number
@ -422,15 +462,18 @@ type ImportPreviewRow = {
plan_qty: string plan_qty: string
logistics_code: string logistics_code: string
sys_platform_code: string sys_platform_code: string
shop_nick: string
import_status: string import_status: string
import_message: string import_message: string
} }
const importPreviewColumns = [ const importPreviewColumns = [
{ prop: 'row_no', label: '行号', width: '70', fixed: 'left' }, { prop: 'row_no', label: '行号', width: '70', fixed: 'left' },
{ prop: '_issue', label: '异常', width: '60', fixed: 'left' }, { prop: 'import_status', label: '状态', width: '110', fixed: 'left' },
{ prop: 'delivery_order_code', label: '订单号', minWidth: '140', fixed: 'left' }, { prop: 'delivery_order_code', label: '订单号', minWidth: '140', fixed: 'left' },
{ prop: 'selected_items', label: '商品', minWidth: '170' },
{ prop: 'store_id', label: '货主', minWidth: '160' }, { prop: 'store_id', label: '货主', minWidth: '160' },
{ prop: 'shop_nick', label: '店铺名称', minWidth: '120' },
{ prop: 'name', label: '收件人', minWidth: '100' }, { prop: 'name', label: '收件人', minWidth: '100' },
{ prop: 'mobile', label: '手机号', minWidth: '120' }, { prop: 'mobile', label: '手机号', minWidth: '120' },
{ prop: 'tel', label: '电话', minWidth: '120' }, { prop: 'tel', label: '电话', minWidth: '120' },
@ -438,10 +481,8 @@ const importPreviewColumns = [
{ prop: 'city', label: '城市*', minWidth: '120' }, { prop: 'city', label: '城市*', minWidth: '120' },
{ prop: 'area', label: '区/县*', minWidth: '120' }, { prop: 'area', label: '区/县*', minWidth: '120' },
{ prop: 'detail_address', label: '详细地址', minWidth: '150' }, { prop: 'detail_address', label: '详细地址', minWidth: '150' },
{ prop: 'selected_items', label: '商品', minWidth: '110' },
{ prop: 'logistics_code', label: '快递', minWidth: '140' }, { prop: 'logistics_code', label: '快递', minWidth: '140' },
{ prop: 'sys_platform_code', label: '平台', minWidth: '140' }, { prop: 'sys_platform_code', label: '平台', minWidth: '140' },
{ prop: 'import_status', label: '状态', width: '90' },
{ prop: 'import_message', label: '结果说明', minWidth: '180' }, { prop: 'import_message', label: '结果说明', minWidth: '180' },
{ prop: 'row_action', label: '操作', width: '70', fixed: 'right' } { prop: 'row_action', label: '操作', width: '70', fixed: 'right' }
] ]
@ -528,6 +569,7 @@ function createEmptyPreviewRowForm(): ImportPreviewRow {
plan_qty: '1', plan_qty: '1',
logistics_code: '', logistics_code: '',
sys_platform_code: '', sys_platform_code: '',
shop_nick: '',
import_status: '待创建', import_status: '待创建',
import_message: '' import_message: ''
} }
@ -701,6 +743,16 @@ function hasUnmatchedItems(row: ImportPreviewRow): boolean {
}) })
} }
function formatSelectedItemsSummary(items: PreviewSelectedItem[]): string {
return items
.map((item) => {
const name = item.item_name || item.item_code || '未知商品'
const qty = item.plan_qty || '1'
return `${name}×${qty}`
})
.join('、')
}
function getRowIssues(row: ImportPreviewRow): string[] { function getRowIssues(row: ImportPreviewRow): string[] {
const issues: string[] = [] const issues: string[] = []
if (row._orderExists) issues.push('订单号已存在') if (row._orderExists) issues.push('订单号已存在')
@ -711,7 +763,8 @@ function getRowIssues(row: ImportPreviewRow): string[] {
if (isRequiredFieldEmpty(row, 'city')) issues.push('城市未选择') if (isRequiredFieldEmpty(row, 'city')) issues.push('城市未选择')
if (isRequiredFieldEmpty(row, 'area')) issues.push('区/县未选择') if (isRequiredFieldEmpty(row, 'area')) issues.push('区/县未选择')
if (isRequiredFieldEmpty(row, 'detail_address')) issues.push('详细地址未填写') if (isRequiredFieldEmpty(row, 'detail_address')) issues.push('详细地址未填写')
if (hasUnmatchedItems(row)) issues.push('商品未匹配') if (!row.selected_items.length) issues.push('商品未选择')
else if (hasUnmatchedItems(row)) issues.push('商品未匹配')
return issues return issues
} }
@ -809,6 +862,7 @@ function mergeDuplicateOrderRows(rows: ImportPreviewRow[]): ImportPreviewRow[] {
if (!existing.area_code && row.area_code) existing.area_code = row.area_code if (!existing.area_code && row.area_code) existing.area_code = row.area_code
if (!existing.logistics_code && row.logistics_code) existing.logistics_code = row.logistics_code if (!existing.logistics_code && row.logistics_code) existing.logistics_code = row.logistics_code
if (!existing.sys_platform_code && row.sys_platform_code) existing.sys_platform_code = row.sys_platform_code if (!existing.sys_platform_code && row.sys_platform_code) existing.sys_platform_code = row.sys_platform_code
if (!existing.shop_nick && row.shop_nick) existing.shop_nick = row.shop_nick
} }
} }
return Array.from(map.values()) return Array.from(map.values())
@ -918,6 +972,7 @@ function getNextPreviewRowTemplate(copyFrom?: ImportPreviewRow): ImportPreviewRo
store_id: lastRow.store_id ?? defaultStoreId.value, store_id: lastRow.store_id ?? defaultStoreId.value,
logistics_code: lastRow.logistics_code, logistics_code: lastRow.logistics_code,
sys_platform_code: lastRow.sys_platform_code, sys_platform_code: lastRow.sys_platform_code,
shop_nick: lastRow.shop_nick,
selected_items: [], selected_items: [],
plan_qty: '1', plan_qty: '1',
import_status: '待创建', import_status: '待创建',
@ -960,6 +1015,49 @@ function markPreviewRowDirty(row: ImportPreviewRow) {
importOrderResult.value = null importOrderResult.value = null
} }
function handleDeliveryOrderCodeChange(row: ImportPreviewRow, newVal: string) {
const newCode = String(newVal || '').trim()
// 仅当订单号从原始冲突的代码变更为其他值时,才清除已存在标记
if (row._orderExists && row._orderExistsCode && row._orderExistsCode !== newCode) {
row._orderExists = false
row._orderExistsCode = undefined
}
markPreviewRowDirty(row)
}
function hasPendingRows(): boolean {
return importPreviewRows.value.some((row) => row.import_status === '待创建')
}
async function confirmClose(): Promise<boolean> {
if (!hasPendingRows()) return true
try {
await ElMessageBox.confirm(
'当前有待创建的订单数据,关闭后将丢失未保存的信息。是否确认关闭?',
'确认关闭',
{
confirmButtonText: '确认关闭',
cancelButtonText: '取消',
closeOnClickModal: false,
closeOnPressEscape: false
}
)
return true
} catch {
return false
}
}
async function handleBeforeClose(done: () => void) {
const ok = await confirmClose()
if (ok) done()
}
async function handleCloseClick() {
const ok = await confirmClose()
if (ok) visible.value = false
}
function resetImportOrderDialog() { function resetImportOrderDialog() {
importOrderFileName.value = '' importOrderFileName.value = ''
importPreviewRows.value = [] importPreviewRows.value = []
@ -1056,6 +1154,7 @@ function buildPreviewRow(row: Record<string, any>, rowNo: number): ImportPreview
plan_qty: planQty || '1', plan_qty: planQty || '1',
logistics_code: toImportString(pickImportValue(row, ['快递编码', 'logistics_code'])), logistics_code: toImportString(pickImportValue(row, ['快递编码', 'logistics_code'])),
sys_platform_code: toImportString(pickImportValue(row, ['系统平台编码', 'sys_platform_code', '平台编码'])), sys_platform_code: toImportString(pickImportValue(row, ['系统平台编码', 'sys_platform_code', '平台编码'])),
shop_nick: toImportString(pickImportValue(row, ['店铺名称', '店铺名', 'shop_nick', '店铺昵称'])),
import_status: '待创建', import_status: '待创建',
import_message: '' import_message: ''
} }
@ -1149,6 +1248,7 @@ async function parseImportPreviewFromFile(file: File) {
const code = String(row.delivery_order_code || '').trim() const code = String(row.delivery_order_code || '').trim()
if (code && existCodeSet.has(code)) { if (code && existCodeSet.has(code)) {
row._orderExists = true row._orderExists = true
row._orderExistsCode = code
} }
} }
} }
@ -1253,7 +1353,8 @@ function buildCreateOrderPayload(rows: ImportPreviewRow[]): PendingOrderCreateOr
items, items,
delivery_order_code: String(header.delivery_order_code || '').trim() || undefined, delivery_order_code: String(header.delivery_order_code || '').trim() || undefined,
logistics_code: String(header.logistics_code || '').trim() || undefined, logistics_code: String(header.logistics_code || '').trim() || undefined,
sys_platform_code: String(header.sys_platform_code || '').trim() || undefined sys_platform_code: String(header.sys_platform_code || '').trim() || undefined,
shop_nick: String(header.shop_nick || '').trim() || undefined
} }
} }
@ -1290,6 +1391,10 @@ function validatePreviewRowsBeforeSubmit(options?: { requireItemId?: boolean })
ElMessage.warning(`订单「${orderLabel}」:货主无效,请重新选择`) ElMessage.warning(`订单「${orderLabel}」:货主无效,请重新选择`)
return false return false
} }
if (header._orderExists) {
ElMessage.warning(`订单「${orderLabel}」:订单号已存在,请修改`)
return false
}
if (!String(header.name || '').trim()) { if (!String(header.name || '').trim()) {
ElMessage.warning(`订单「${orderLabel}」:请填写收件人`) ElMessage.warning(`订单「${orderLabel}」:请填写收件人`)
return false return false
@ -1583,11 +1688,6 @@ function applyParsedAddressToRow(row: ImportPreviewRow, data: PendingOrderParseA
} }
async function handleParseAddress() { async function handleParseAddress() {
const targetRows = selectedPreviewRowsForAddress.value
if (!targetRows.length) {
ElMessage.warning('请先勾选要填充地址的订单行')
return
}
const address = addressPasteText.value.trim() const address = addressPasteText.value.trim()
if (!address) { if (!address) {
ElMessage.warning('请粘贴地址') ElMessage.warning('请粘贴地址')
@ -1604,6 +1704,14 @@ async function handleParseAddress() {
} }
const data = extractPendingOrderParseAddressData(res) const data = extractPendingOrderParseAddressData(res)
let targetRows = selectedPreviewRowsForAddress.value
if (!targetRows.length) {
// 无选中行时自动新建一行
addImportPreviewRow()
targetRows = selectedPreviewRowsForAddress.value
}
for (const row of targetRows) { for (const row of targetRows) {
applyParsedAddressToRow(row, data) applyParsedAddressToRow(row, data)
} }
@ -1658,6 +1766,11 @@ function getStockItemCode(row: any) {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.combined-status {
display: flex;
align-items: center;
gap: 4px;
}
.issue-text { .issue-text {
display: inline-block; display: inline-block;
background: #f56c6c; background: #f56c6c;
@ -1677,6 +1790,25 @@ function getStockItemCode(row: any) {
white-space: nowrap; white-space: nowrap;
} }
.selected-items-cell {
line-height: 1.5;
}
.selected-items-summary {
display: inline;
line-height: 1.5;
word-break: break-all;
}
.selected-items-summary.is-clickable {
cursor: pointer;
}
.selected-items-summary.is-clickable:hover {
color: #409eff;
}
.selected-items-tooltip {
line-height: 1.8;
font-size: 12px;
}
:deep(.el-table__body tr.current-row > td) { :deep(.el-table__body tr.current-row > td) {
background-color: #d1e9ff !important; background-color: #d1e9ff !important;
} }

View File

@ -16,12 +16,13 @@
<div class="select-product-toolbar"> <div class="select-product-toolbar">
<el-input <el-input
v-model.trim="keyword" v-model="keyword"
placeholder="搜索商品编码/名称" placeholder="支持多个查询使用逗号分隔"
clearable clearable
size="small" size="small"
:disabled="!storeId" :disabled="!storeId"
@keyup.enter="handleSearch" @keyup.enter="handleSearch"
@input="normalizeKeyword"
/> />
<el-button type="primary" size="small" :disabled="!storeId" :loading="loading" @click="handleSearch"> <el-button type="primary" size="small" :disabled="!storeId" :loading="loading" @click="handleSearch">
查询 查询
@ -111,6 +112,20 @@ const emit = defineEmits<{
const loading = ref(false) const loading = ref(false)
const keyword = ref('') const keyword = ref('')
function normalizeKeyword() {
const raw = keyword.value
if (!raw) return
const normalized = raw
.replace(/[\r\n]+/g, ',')
.split(',')
.map((s) => s.trim())
.filter((s) => s !== '')
.join(',')
if (normalized !== raw) {
keyword.value = normalized
}
}
const defaultPlanQty = ref('1') const defaultPlanQty = ref('1')
const allRows = ref<any[]>([]) const allRows = ref<any[]>([])
const list = ref<any[]>([]) const list = ref<any[]>([])

View File

@ -688,6 +688,7 @@ export const reviewColums = [
{ prop: 'is_urgency', label: '紧急', width: '80' }, { prop: 'is_urgency', label: '紧急', width: '80' },
{ prop: 'logistics_name', label: '物流公司', width: '120' }, { prop: 'logistics_name', label: '物流公司', width: '120' },
{ prop: 'items_total', label: '商品总数', width: '100' }, { prop: 'items_total', label: '商品总数', width: '100' },
{ prop: 'items_count', label: '商品总类', width: '100' },
{ prop: 'total_amount', label: '订单金额', width: '110' }, { prop: 'total_amount', label: '订单金额', width: '110' },
{ prop: 'pay_time', label: '支付时间', width: '165', formatter: orderTimeFormatter }, { prop: 'pay_time', label: '支付时间', width: '165', formatter: orderTimeFormatter },
{ prop: 'operator_name', label: '审核人', width: '100' }, { prop: 'operator_name', label: '审核人', width: '100' },