feat(order): 新增「配送异常」视图,回传平台失败可看原因并重试
订单页左侧「配送」下面新增「配送异常」tab: - 数据 = 配送表 + external_send_status IN (2 待重试, 3 同步异常),不用再进配送页自己筛 - 新增「回传失败原因」列(红色 + tooltip 全文),状态列保留「第 N 次」 - 行内「重试」按钮(单条重试),批量重试仍走原 resend_external - tab 上带红色数量徽标(待重试 + 同步异常),重试后自动刷新 - 导出:配送异常视图导出时按 2,3 过滤;导出面板新增「回传平台状态」多选 后端导出补充 external_send_status 过滤(与列表接口同口径)。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
498543b9d7
commit
91e90cc7e2
@ -751,6 +751,19 @@ const EXPORT_TYPES = {
|
||||
{ key: 'remark', label: '备注', type: 'text' },
|
||||
{ key: 'shop_id', label: '店铺', type: 'shop' },
|
||||
{ key: 'warehouse_id', label: '仓库', type: 'warehouse' },
|
||||
{
|
||||
key: 'external_send_status',
|
||||
label: '回传平台状态',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '待同步外部', value: '0' },
|
||||
{ label: '已同步外部', value: '1' },
|
||||
{ label: '同步失败待重试', value: '2' },
|
||||
{ label: '同步异常', value: '3' },
|
||||
],
|
||||
multiple: true,
|
||||
placeholder: '配送视图用;配送异常=2,3',
|
||||
},
|
||||
{ key: 'created_from', label: '创建时间起', type: 'date' },
|
||||
{ key: 'created_to', label: '创建时间止', type: 'date' },
|
||||
{ key: 'archived_from', label: '归档时间起', type: 'date' },
|
||||
@ -791,6 +804,11 @@ const EXPORT_TYPES = {
|
||||
// 电商平台(多选)与平台单号(多个精确匹配),与列表接口同口径
|
||||
whereIn(wh, 't.source_platform_code', csvValues(f.platform_codes, 50).map(code => code.toUpperCase()));
|
||||
whereIn(wh, 't.oaid_order_source_code', csvValues(f.platform_order_nos, 200));
|
||||
// 外部发货同步状态(配送视图/配送异常视图用:0待同步 1已同步 2待重试 3异常,支持逗号多选)
|
||||
const sendStatuses = csvValues(f.external_send_status, 10)
|
||||
.map(value => Number(value))
|
||||
.filter(value => Number.isInteger(value));
|
||||
if (sendStatuses.length) whereIn(wh, 't.external_send_status', sendStatuses);
|
||||
if (String(f.exclude_unbound) === '1') {
|
||||
wh.raw(
|
||||
'NOT EXISTS (SELECT 1 FROM order_status_items oi WHERE oi.order_id = t.id ' +
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import OrderStatusPanel from './StatusPanel.vue'
|
||||
import { ORDER_STAGE_TABS, type OrderStage } from '@/api/orderStatus'
|
||||
import { getExternalSendCounts } from '@/api/externalSendSync'
|
||||
import { useOrderSyncTask } from '@/composables/useOrderSyncTask'
|
||||
|
||||
/**
|
||||
@ -10,9 +11,37 @@ import { useOrderSyncTask } from '@/composables/useOrderSyncTask'
|
||||
* 订单按状态分表存储,页面按状态分视图管理:
|
||||
* 左侧 tab 切换 5 个视图(待审核 / 异常 / 委外中 / 配送 / 历史),
|
||||
* 历史为归档表且只读;tab 懒加载,首次切到才请求列表。
|
||||
* 「配送异常」= 配送视图里回传外部打单平台失败的单(待重试 / 异常),方便直接看原因并重试。
|
||||
* 一键拉单进行中时卡片头部持续显示进度(弹窗关闭后台执行也不会丢进度)。
|
||||
*/
|
||||
const active = ref<OrderStage>('pending')
|
||||
const active = ref<OrderStage | 'delivery_exception'>('pending')
|
||||
|
||||
/** 外部打单回传失败数量(配送异常 tab 徽标) */
|
||||
const deliverySendFailed = ref(0)
|
||||
async function refreshDeliverySendCounts() {
|
||||
try {
|
||||
const res = await getExternalSendCounts()
|
||||
const counts = res.data.data
|
||||
deliverySendFailed.value = (counts.retry || 0) + (counts.exception || 0)
|
||||
} catch {
|
||||
// 统计失败不影响列表
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧 tab:常规状态视图 + 紧随「配送」的「配送异常」视图
|
||||
* (配送异常复用配送表,只是固定筛「待重试 / 同步异常」)
|
||||
*/
|
||||
const stageTabs = computed(() => {
|
||||
const tabs: Array<{ key: string; label: string; status: OrderStage; view?: 'delivery_exception' }> = []
|
||||
for (const tab of ORDER_STAGE_TABS) {
|
||||
tabs.push({ key: tab.key, label: tab.label, status: tab.key })
|
||||
if (tab.key === 'delivery') {
|
||||
tabs.push({ key: 'delivery_exception', label: '配送异常', status: 'delivery', view: 'delivery_exception' })
|
||||
}
|
||||
}
|
||||
return tabs
|
||||
})
|
||||
|
||||
const { task, isRunning, progress, progressText, refreshRunning, stopPolling } = useOrderSyncTask()
|
||||
|
||||
@ -26,6 +55,12 @@ const syncHint = computed(() => {
|
||||
|
||||
onMounted(() => {
|
||||
refreshRunning().catch(() => {})
|
||||
refreshDeliverySendCounts().catch(() => {})
|
||||
})
|
||||
|
||||
/** 切到「配送」/「配送异常」时刷新徽标数量(重试后能立刻看到变化) */
|
||||
watch(active, value => {
|
||||
if (value === 'delivery' || value === 'delivery_exception') refreshDeliverySendCounts().catch(() => {})
|
||||
})
|
||||
|
||||
onBeforeUnmount(stopPolling)
|
||||
@ -54,13 +89,23 @@ onBeforeUnmount(stopPolling)
|
||||
|
||||
<el-tabs v-model="active" tab-position="left" class="order-tabs">
|
||||
<el-tab-pane
|
||||
v-for="t in ORDER_STAGE_TABS"
|
||||
v-for="t in stageTabs"
|
||||
:key="t.key"
|
||||
:name="t.key"
|
||||
:label="t.label"
|
||||
lazy
|
||||
>
|
||||
<OrderStatusPanel :status="t.key" />
|
||||
<template #label>
|
||||
<span class="tab-label">
|
||||
{{ t.label }}
|
||||
<el-badge
|
||||
v-if="t.key === 'delivery_exception' && deliverySendFailed"
|
||||
:value="deliverySendFailed"
|
||||
type="danger"
|
||||
class="tab-badge"
|
||||
/>
|
||||
</span>
|
||||
</template>
|
||||
<OrderStatusPanel :status="t.status" :view="t.view" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
@ -104,6 +149,15 @@ onBeforeUnmount(stopPolling)
|
||||
min-width: 34px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
/* 左侧 tab 徽标(配送异常的失败数量) */
|
||||
.tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.tab-badge :deep(.el-badge__content) {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.order-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
|
||||
@ -58,14 +58,18 @@ import {
|
||||
* 删除仅在「已取消」视图提供:待审核 / 待推送 / 异常等视图的订单需先取消再删除,
|
||||
* 避免绕过状态机把在途单据直接抹掉。
|
||||
*/
|
||||
const props = defineProps<{ status: OrderStage }>()
|
||||
const props = defineProps<{ status: OrderStage; view?: 'delivery_exception' }>()
|
||||
|
||||
const isHistory = computed(() => props.status === 'history')
|
||||
/** 异常视图:状态恒为「异常」,列表不再重复展示状态列,并把异常原因提到前面标红 */
|
||||
const isException = computed(() => props.status === 'exception')
|
||||
/** 配送异常视图:配送表里「回传外部失败」的单(待重试 2 / 异常 3),复用配送视图的筛选与重试 */
|
||||
const isDeliveryException = computed(() => props.view === 'delivery_exception')
|
||||
/** 配送视图:外卖打单订单需要把发货结果同步回平台,这里提供筛选 / 异常数量 / 批量重试 */
|
||||
const isDelivery = computed(() => props.status === 'delivery')
|
||||
const stageMeta = computed(() => ORDER_STAGE_META[props.status])
|
||||
const isDelivery = computed(() => props.status === 'delivery' || isDeliveryException.value)
|
||||
const stageMeta = computed(() => (isDeliveryException.value
|
||||
? { label: '配送异常', tag: 'danger' as const }
|
||||
: ORDER_STAGE_META[props.status]))
|
||||
|
||||
/* -------------------- 筛选条件(默认一行简单条件,可展开为完整条件) -------------------- */
|
||||
const expanded = ref(false)
|
||||
@ -83,7 +87,7 @@ const query = reactive({
|
||||
receiver: '',
|
||||
address: '',
|
||||
remark: '',
|
||||
external_send_status: '' as number | '',
|
||||
external_send_status: '' as string,
|
||||
createdRange: [] as string[],
|
||||
archivedRange: [] as string[],
|
||||
})
|
||||
@ -103,12 +107,40 @@ async function fetchExternalSendCounts() {
|
||||
|
||||
/** 点异常数量 → 直接筛选异常订单 */
|
||||
function filterExternalSend(status: number) {
|
||||
query.external_send_status = status
|
||||
query.external_send_status = String(status)
|
||||
query.page = 1
|
||||
search()
|
||||
fetchExternalSendCounts()
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条重试回传(配送异常视图行内按钮)
|
||||
* @param {Object} row 列表行
|
||||
* @return {Promise<void>} 无返回值
|
||||
*/
|
||||
async function retryOneExternalSend(row: OrderStatusItem) {
|
||||
const id = Number(row.id)
|
||||
if (!id) return
|
||||
try {
|
||||
await ElMessageBox.confirm(confirmText('resend_external', 1), '重试同步外部发货', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
const res = await retryExternalSend([ id ])
|
||||
const result = res.data.data
|
||||
if (result.success) {
|
||||
ElMessage.success('已重新同步发货')
|
||||
} else {
|
||||
ElMessage.warning(`同步失败:${result.failed} 条,原因见列表「回传失败原因」`)
|
||||
}
|
||||
await fetchList()
|
||||
await fetchExternalSendCounts()
|
||||
}
|
||||
|
||||
/** 「含未绑定商品订单」开关(默认关闭:不显示含未绑定商品的订单) */
|
||||
const showUnboundOrders = ref(false)
|
||||
|
||||
@ -144,8 +176,10 @@ const { loading, list, total, elapsed, fetchList, search, handlePageChange, hand
|
||||
}
|
||||
// 待审核默认只看「商品都已绑定」的订单,开关打开才包含未绑定商品的订单
|
||||
if (props.status === 'pending' && !showUnboundOrders.value) params.exclude_unbound = 1
|
||||
if (isDelivery.value && query.external_send_status !== '') {
|
||||
params.external_send_status = query.external_send_status
|
||||
if (isDelivery.value) {
|
||||
// 配送异常视图固定只看「待重试 + 异常」,其余配送视图走下拉筛选
|
||||
const sendStatus = isDeliveryException.value ? '2,3' : query.external_send_status
|
||||
if (sendStatus) params.external_send_status = sendStatus
|
||||
}
|
||||
return getOrderStatusList(params as never)
|
||||
},
|
||||
@ -183,7 +217,7 @@ const exportFilters = computed(() => ({
|
||||
archived_from: query.archivedRange[0],
|
||||
archived_to: query.archivedRange[1],
|
||||
exclude_unbound: props.status === 'pending' && !showUnboundOrders.value ? 1 : '',
|
||||
external_send_status: isDelivery.value ? query.external_send_status : '',
|
||||
external_send_status: isDeliveryException.value ? '2,3' : (isDelivery.value ? query.external_send_status : ''),
|
||||
}))
|
||||
|
||||
/* -------------------- 筛选项数据源(状态枚举 / 店铺 / 归档阈值) -------------------- */
|
||||
@ -771,7 +805,8 @@ onBeforeUnmount(() => {
|
||||
size="small"
|
||||
effect="dark"
|
||||
class="external-send-tag"
|
||||
@click="filterExternalSend(3)"
|
||||
:class="{ 'is-static': isDeliveryException }"
|
||||
@click="isDeliveryException ? undefined : filterExternalSend(3)"
|
||||
>
|
||||
同步异常 {{ externalSendCounts.exception }}
|
||||
</el-tag>
|
||||
@ -781,12 +816,13 @@ onBeforeUnmount(() => {
|
||||
size="small"
|
||||
effect="plain"
|
||||
class="external-send-tag"
|
||||
@click="filterExternalSend(2)"
|
||||
:class="{ 'is-static': isDeliveryException }"
|
||||
@click="isDeliveryException ? undefined : filterExternalSend(2)"
|
||||
>
|
||||
待重试 {{ externalSendCounts.retry }}
|
||||
</el-tag>
|
||||
<el-tag
|
||||
v-if="externalSendCounts.pending"
|
||||
v-if="externalSendCounts.pending && !isDeliveryException"
|
||||
type="info"
|
||||
size="small"
|
||||
effect="plain"
|
||||
@ -1012,6 +1048,13 @@ onBeforeUnmount(() => {
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 配送异常视图:失败原因单独成列,避免被状态列挤成省略号 -->
|
||||
<el-table-column v-if="isDeliveryException" label="回传失败原因" min-width="260" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.external_send_error" class="cell-error">{{ row.external_send_error }}</span>
|
||||
<span v-else class="muted">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="!isException" prop="remark" label="备注 / 异常原因" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" width="150">
|
||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||
@ -1025,6 +1068,16 @@ onBeforeUnmount(() => {
|
||||
<el-table-column label="操作" :width="rowActions.length > 3 ? 220 : 150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openDetail(row)">查看</el-button>
|
||||
<!-- 配送异常:单条直接重试,不用先勾选再走批量 -->
|
||||
<el-button
|
||||
v-if="isDeliveryException"
|
||||
link
|
||||
type="warning"
|
||||
size="small"
|
||||
@click="retryOneExternalSend(row)"
|
||||
>
|
||||
重试
|
||||
</el-button>
|
||||
<el-button
|
||||
v-for="action in rowActions"
|
||||
:key="action"
|
||||
@ -1232,6 +1285,12 @@ onBeforeUnmount(() => {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cell-error {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.external-send-tag.is-static {
|
||||
cursor: default;
|
||||
}
|
||||
.filter-bar {
|
||||
flex: 0 0 auto;
|
||||
margin-bottom: 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user