336 lines
9.8 KiB
Vue
336 lines
9.8 KiB
Vue
<template>
|
||
<el-drawer
|
||
v-model="visible"
|
||
size="780px"
|
||
:title="drawerTitle"
|
||
append-to-body
|
||
destroy-on-close
|
||
@closed="onClosed"
|
||
>
|
||
<div v-loading="starting">
|
||
<el-descriptions :column="2" border size="small" class="mb12">
|
||
<el-descriptions-item label="任务ID" :span="2">{{ asyncTaskId || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="客户">{{ filterText.customers }}</el-descriptions-item>
|
||
<el-descriptions-item label="提货时间">{{ filterText.time }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag size="small" :type="statusTagType">{{ statusLabel }}</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="进度">{{ progress.percent || 0 }}%</el-descriptions-item>
|
||
</el-descriptions>
|
||
|
||
<el-progress
|
||
:percentage="Math.min(100, Math.max(0, Number(progress.percent) || 0))"
|
||
:status="progressStatus"
|
||
:stroke-width="12"
|
||
striped
|
||
:striped-flow="running"
|
||
class="mb12"
|
||
/>
|
||
|
||
<div class="summary-line">
|
||
已扫描 {{ progress.scanned || 0 }}
|
||
/ 本地已有 {{ progress.matched || 0 }}
|
||
/ 本地缺失 {{ progress.missing || 0 }}
|
||
/ 状态不一致 {{ progress.statusMismatch || 0 }}
|
||
</div>
|
||
<div v-if="progress.message" class="msg-line">{{ progress.message }}</div>
|
||
<div v-if="progress.error" class="err-line">{{ progress.error }}</div>
|
||
|
||
<el-alert
|
||
class="mb12"
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
title="比对转单号 + 订单状态:1) 上游有转单号、本地没有;2) 两端都有但 order_status 不一致。异步分页扫描,结果已写入操作记录。"
|
||
/>
|
||
|
||
<div class="json-panel__head">
|
||
<span>状态不一致(样本 {{ statusMismatchCount }})</span>
|
||
<el-button
|
||
type="primary"
|
||
link
|
||
:disabled="!canFillMismatch"
|
||
@click="fillMismatchToSearch"
|
||
>回填到单号搜索</el-button>
|
||
</div>
|
||
<el-table
|
||
v-if="statusMismatchRows.length"
|
||
:data="statusMismatchRows"
|
||
border
|
||
size="small"
|
||
max-height="320"
|
||
class="mb12"
|
||
>
|
||
<el-table-column type="index" width="55" label="#" />
|
||
<el-table-column prop="transferNo" label="转单号" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="upstreamStatusLabel" label="上游状态" width="110" />
|
||
<el-table-column prop="localStatusLabel" label="本地状态" width="110" />
|
||
</el-table>
|
||
<el-empty
|
||
v-else-if="!running"
|
||
description="暂无状态不一致"
|
||
/>
|
||
|
||
<div class="json-panel__head">
|
||
<span>缺失转单号(样本 {{ missingCount }})</span>
|
||
<el-button
|
||
type="primary"
|
||
link
|
||
:disabled="!canFillSearch"
|
||
@click="fillToSearch"
|
||
>回填到单号搜索</el-button>
|
||
</div>
|
||
<el-table
|
||
v-if="missingRows.length"
|
||
:data="missingRows"
|
||
border
|
||
size="small"
|
||
max-height="280"
|
||
>
|
||
<el-table-column type="index" width="55" label="#" />
|
||
<el-table-column prop="transferNo" label="转单号" min-width="220" show-overflow-tooltip />
|
||
</el-table>
|
||
<el-empty
|
||
v-else-if="!running"
|
||
description="暂无缺失转单号"
|
||
/>
|
||
|
||
</div>
|
||
</el-drawer>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ElMessage } from 'element-plus'
|
||
import { compareOrderSourceByFilter, getOrderSourceCompareProgress } from '@/api/monitor/orderSource'
|
||
|
||
const emit = defineEmits(['fill-search'])
|
||
|
||
const visible = ref(false)
|
||
const starting = ref(false)
|
||
const asyncTaskId = ref('')
|
||
const query = ref({})
|
||
const progress = ref({})
|
||
let timer = null
|
||
|
||
const filterText = computed(() => {
|
||
const q = query.value || {}
|
||
const codes = Array.isArray(q.customerCodes) ? q.customerCodes.filter(Boolean) : []
|
||
const keywords = Array.isArray(q.customerKeywords) ? q.customerKeywords.filter(Boolean) : []
|
||
return {
|
||
customers: keywords.join(', ') || codes.join(', ') || '-',
|
||
time: (q.beginTime || '-') + ' ~ ' + (q.endTime || '-')
|
||
}
|
||
})
|
||
|
||
const running = computed(() => {
|
||
const st = (progress.value?.status || '').toUpperCase()
|
||
return st === 'PENDING' || st === 'RUNNING' || starting.value
|
||
})
|
||
|
||
const drawerTitle = computed(() => {
|
||
if (running.value) return '订单比对任务进行中'
|
||
const st = (progress.value?.status || '').toUpperCase()
|
||
if (st === 'SUCCESS') return '订单比对完成'
|
||
if (st === 'FAIL') return '订单比对失败'
|
||
return '订单比对任务'
|
||
})
|
||
|
||
const statusLabel = computed(() => {
|
||
const st = (progress.value?.status || '').toUpperCase()
|
||
if (st === 'PENDING') return '排队中'
|
||
if (st === 'RUNNING') return '扫描中'
|
||
if (st === 'SUCCESS') return '完成'
|
||
if (st === 'FAIL') return '失败'
|
||
return st || '-'
|
||
})
|
||
|
||
const statusTagType = computed(() => {
|
||
const st = (progress.value?.status || '').toUpperCase()
|
||
if (st === 'SUCCESS') return 'success'
|
||
if (st === 'FAIL') return 'danger'
|
||
if (st === 'RUNNING' || st === 'PENDING') return 'warning'
|
||
return 'info'
|
||
})
|
||
|
||
const progressStatus = computed(() => {
|
||
const st = (progress.value?.status || '').toUpperCase()
|
||
if (st === 'SUCCESS') return 'success'
|
||
if (st === 'FAIL') return 'exception'
|
||
return undefined
|
||
})
|
||
|
||
const orderStatusMap = {
|
||
'0': '待提货',
|
||
'1': '已提货',
|
||
'2': '已收货',
|
||
'3': '运输中',
|
||
'4': '派送中',
|
||
'5': '已签收',
|
||
'6': '已完成',
|
||
'7': '已取消',
|
||
'8': '异常',
|
||
'9': '退件中',
|
||
'10': '已退件'
|
||
}
|
||
|
||
function labelStatus(v) {
|
||
const k = v == null ? '' : String(v).trim()
|
||
if (!k) return '-'
|
||
return orderStatusMap[k] || k
|
||
}
|
||
|
||
function normalizeMismatchList(raw) {
|
||
if (!Array.isArray(raw)) return []
|
||
return raw.map(row => {
|
||
if (row == null) return null
|
||
if (typeof row === 'string') {
|
||
return { transferNo: row, upstreamStatus: null, localStatus: null }
|
||
}
|
||
return {
|
||
transferNo: row.transferNo || row.transfer_no || '',
|
||
upstreamStatus: row.upstreamStatus ?? row.upstream_status ?? null,
|
||
localStatus: row.localStatus ?? row.local_status ?? null
|
||
}
|
||
}).filter(Boolean)
|
||
}
|
||
|
||
const statusMismatchRows = computed(() => {
|
||
const samples = normalizeMismatchList(progress.value?.statusMismatchSamples)
|
||
if (samples.length) {
|
||
return samples.map(row => ({
|
||
transferNo: row.transferNo,
|
||
upstreamStatusLabel: labelStatus(row.upstreamStatus),
|
||
localStatusLabel: labelStatus(row.localStatus)
|
||
}))
|
||
}
|
||
// fallback: flat transfer_no list when map samples missing
|
||
const flat = progress.value?.statusMismatchTransferNos || []
|
||
return (Array.isArray(flat) ? flat : []).map(tn => ({
|
||
transferNo: tn,
|
||
upstreamStatusLabel: '-',
|
||
localStatusLabel: '-'
|
||
}))
|
||
})
|
||
|
||
const statusMismatchCount = computed(() => {
|
||
const n = Number(progress.value?.statusMismatch)
|
||
if (!Number.isNaN(n) && n > 0) return n
|
||
return statusMismatchRows.value.length
|
||
})
|
||
|
||
const missingRows = computed(() => {
|
||
const list = progress.value?.missingTransferNos || []
|
||
return (Array.isArray(list) ? list : []).map(tn => ({ transferNo: tn }))
|
||
})
|
||
|
||
const missingCount = computed(() => {
|
||
const n = Number(progress.value?.missing)
|
||
if (!Number.isNaN(n) && n > 0) return n
|
||
return missingRows.value.length
|
||
})
|
||
|
||
const canFillSearch = computed(() => {
|
||
return !running.value && missingRows.value.length > 0
|
||
})
|
||
|
||
const canFillMismatch = computed(() => {
|
||
return !running.value && statusMismatchRows.value.length > 0
|
||
})
|
||
|
||
function fillToSearch() {
|
||
const list = missingRows.value.map(r => String(r.transferNo || '').trim()).filter(Boolean)
|
||
if (!list.length) {
|
||
ElMessage.warning('暂无可回填的缺失转单号')
|
||
return
|
||
}
|
||
const truncated = !!(progress.value?.missingTruncated) || (Number(progress.value?.missing || 0) > list.length)
|
||
emit('fill-search', { transferNos: list, truncated })
|
||
visible.value = false
|
||
}
|
||
|
||
function fillMismatchToSearch() {
|
||
const list = statusMismatchRows.value.map(r => String(r.transferNo || '').trim()).filter(Boolean)
|
||
if (!list.length) {
|
||
ElMessage.warning('暂无可回填的状态不一致转单号')
|
||
return
|
||
}
|
||
const truncated = !!(progress.value?.statusMismatchTruncated)
|
||
|| (Number(progress.value?.statusMismatch || 0) > list.length)
|
||
emit('fill-search', { transferNos: list, truncated })
|
||
visible.value = false
|
||
}
|
||
|
||
function clearTimer() {
|
||
if (timer) {
|
||
clearInterval(timer)
|
||
timer = null
|
||
}
|
||
}
|
||
|
||
function poll() {
|
||
if (!asyncTaskId.value) return
|
||
getOrderSourceCompareProgress(asyncTaskId.value).then(res => {
|
||
progress.value = res.data || {}
|
||
const st = (progress.value.status || '').toUpperCase()
|
||
if (st === 'SUCCESS' || st === 'FAIL') {
|
||
clearTimer()
|
||
}
|
||
}).catch(() => {})
|
||
}
|
||
|
||
function open(q) {
|
||
query.value = q || {}
|
||
asyncTaskId.value = ''
|
||
progress.value = {}
|
||
visible.value = true
|
||
starting.value = true
|
||
clearTimer()
|
||
compareOrderSourceByFilter(query.value).then(res => {
|
||
asyncTaskId.value = res.data?.asyncTaskId || ''
|
||
if (!asyncTaskId.value) {
|
||
ElMessage.error('启动比对任务失败')
|
||
return
|
||
}
|
||
progress.value = { status: 'PENDING', percent: 0, message: 'queued', scanned: 0, matched: 0, missing: 0, statusMismatch: 0 }
|
||
poll()
|
||
timer = setInterval(poll, 1500)
|
||
}).catch(() => {
|
||
ElMessage.error('启动比对任务失败')
|
||
}).finally(() => {
|
||
starting.value = false
|
||
})
|
||
}
|
||
|
||
function onClosed() {
|
||
clearTimer()
|
||
}
|
||
|
||
defineExpose({ open })
|
||
</script>
|
||
|
||
<style scoped>
|
||
.mb12 { margin-bottom: 12px; }
|
||
.summary-line {
|
||
margin-bottom: 6px;
|
||
font-weight: 600;
|
||
}
|
||
.msg-line {
|
||
margin-bottom: 8px;
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 12px;
|
||
}
|
||
.err-line {
|
||
margin-bottom: 8px;
|
||
color: #f56c6c;
|
||
word-break: break-all;
|
||
}
|
||
.json-panel__head {
|
||
margin: 12px 0 6px;
|
||
font-weight: 600;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 8px;
|
||
}
|
||
</style>
|