725 lines
25 KiB
Vue
725 lines
25 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<!-- <scan-box
|
||
ref="scanBox"
|
||
:cache-key="props.scanBoxCacheKey"
|
||
:width="waveScanBoxConfig.width"
|
||
:tree-props="waveScanBoxConfig.treeProps"
|
||
:auto-submit="waveScanBoxConfig.autoSubmit"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/> -->
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<order-toolbar-button-group
|
||
:buttons="toolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
<div class="toolbar-right">
|
||
<!-- <span class="toolbar-switch-label">已选 {{ selectionRows.length }} 个订单</span> -->
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack">
|
||
<div class="upper-wrapper" :style="upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="不符合波次策略订单列表"
|
||
default-align="center"
|
||
:enable-column-config="true"
|
||
:column-config-schema-version="1"
|
||
:table-id="tableListId"
|
||
:data="list"
|
||
:row-key="getRowIdentity"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-selection="true"
|
||
:loading="fallbackOrderListLoading"
|
||
:queryTime="queryTime"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<template #column-store_name="{ row }">
|
||
<span>{{ row.store_name || row.shop_name || row.shop || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-sys_logistics_name="{ row }">
|
||
<span>{{ row.sys_logistics_name || row.logistics_name || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-items_count="{ row }">
|
||
<span>{{ row.items_count ?? row.item_count ?? '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-items_total="{ row }">
|
||
<span>{{ row.items_total ?? row.item_total ?? '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-item_snapshot="{ row }">
|
||
<span class="order-info-text">{{ getFallbackOrderItemSnapshotText(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-updated_at="{ row }">
|
||
{{ formatDateTime(row.updated_at || row.update_time || row.updated_time) }}
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无不符合波次策略订单</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<wave-strategy-quick-scan-progress-dialog
|
||
v-model="waveStrategyQuickScanDialogVisible"
|
||
:progress="waveStrategyQuickScanResult"
|
||
@update:model-value="handleWaveStrategyQuickScanDialogVisibleChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import {
|
||
waveScanBoxConfig,
|
||
fallbackOrderAvailableFields,
|
||
fallbackOrderColumns,
|
||
fallbackOrderToolbarButtons
|
||
} from './config/wave-config'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import WaveStrategyQuickScanProgressDialog from './component/WaveStrategyQuickScanProgressDialog.vue'
|
||
import * as indexApi from '@/api/index/index'
|
||
import {
|
||
orderWaveSingleFetchByIds,
|
||
orderWaveWaveStrategyFallbackOrderList,
|
||
orderWaveWaveStrategyQuickScan,
|
||
orderWaveWaveStrategyQuickScanTaskProgress
|
||
} from '@/api/order.wave/orderwave'
|
||
import type {
|
||
WaveStrategyFallbackOrderListResponse,
|
||
WaveStrategyFallbackOrderListRow,
|
||
WaveStrategyQuickScanResponse,
|
||
WaveStrategyQuickScanTaskProgressResponse
|
||
} from '@/api/order.wave/orderwave'
|
||
|
||
const props = withDefaults(defineProps<{
|
||
/** 与路由 path 组合,隔离 ScanBox 筛选缓存(波次各标签页须各不相同) */
|
||
scanBoxCacheKey?: string
|
||
}>(), {
|
||
scanBoxCacheKey: 'wave-order-sandan-fallback-orders'
|
||
})
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const fallbackOrderListLoading = ref(false)
|
||
const singleOrderSubmitting = ref(false)
|
||
const waveStrategyQuickScanSubmitting = ref(false)
|
||
const waveStrategyQuickScanDialogVisible = ref(false)
|
||
const waveStrategyQuickScanTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
|
||
const queryTime = ref(0)
|
||
const tableSize = ref('small')
|
||
const list = ref<WaveStrategyFallbackOrderListRow[]>([])
|
||
const selectionRows = ref<any[]>([])
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
const fallbackOrderOwnerOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const fallbackOrderLogisticsOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const fallbackOrderPlatformOptions = ref<Array<{ label: string; value: string }>>([])
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(fallbackOrderAvailableFields)))
|
||
const columns = ref(JSON.parse(JSON.stringify(fallbackOrderColumns)))
|
||
|
||
const waveStrategyQuickScanResult = reactive({
|
||
status: '',
|
||
taskId: '',
|
||
warehouseId: undefined as number | undefined,
|
||
state: '',
|
||
message: '',
|
||
acceptedAt: '',
|
||
totalOrderCount: 0,
|
||
processedOrderCount: 0,
|
||
matchedOrderCount: 0,
|
||
unmatchedOrderCount: 0,
|
||
progressPercent: 0,
|
||
startTime: '',
|
||
endTime: '',
|
||
durationMs: 0,
|
||
errorMessage: ''
|
||
})
|
||
|
||
const tableListId = computed(() => 'wave-management-fallback-order-list')
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
const toolbarButtons = fallbackOrderToolbarButtons
|
||
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: fallbackOrderListLoading.value,
|
||
waveStrategyQuickScanSubmitting: waveStrategyQuickScanSubmitting.value,
|
||
singleOrderSubmitting: singleOrderSubmitting.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
noSelection: selectionRows.value.length === 0
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.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) {
|
||
return defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => {
|
||
void loadData()
|
||
},
|
||
resetFallbackOrderCondition: () => resetFallbackOrderCondition(),
|
||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||
submitWaveStrategyQuickScan: () => {
|
||
void submitWaveStrategyQuickScan()
|
||
},
|
||
submitFallbackOrderFetchByIds: () => {
|
||
void submitFallbackOrderFetchByIds()
|
||
}
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||
|
||
function getRowIdentity(row: any) {
|
||
return String(row?.id ?? row?.order_id ?? row?.delivery_no ?? '')
|
||
}
|
||
|
||
function buildWhereConditions(rawConditions: Record<string, any>) {
|
||
const where: Record<string, any> = {}
|
||
Object.keys(rawConditions || {}).forEach((key) => {
|
||
const condition = rawConditions[key]
|
||
if (condition && typeof condition === 'object' && 'operator' in condition) {
|
||
const value = condition.value
|
||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||
return
|
||
}
|
||
where[key] = value
|
||
return
|
||
}
|
||
if (condition !== undefined && condition !== null && condition !== '') {
|
||
where[key] = Array.isArray(condition) ? condition[0] ?? '' : condition
|
||
}
|
||
})
|
||
return where
|
||
}
|
||
|
||
function sanitizeFallbackOrderWhere(where: Record<string, any>) {
|
||
const allowedFieldMap: Record<string, string> = {
|
||
id: 'id',
|
||
delivery_no: 'delivery_no',
|
||
deliveryNo: 'delivery_no',
|
||
tracking_no: 'tracking_no',
|
||
trackingNo: 'tracking_no',
|
||
items_count_min: 'items_count_min',
|
||
items_count_max: 'items_count_max',
|
||
items_total_min: 'items_total_min',
|
||
items_total_max: 'items_total_max',
|
||
sys_logistics_name: 'sys_logistics_name',
|
||
store_name: 'store_name',
|
||
owner_name: 'owner_name',
|
||
province: 'province',
|
||
sys_platform_name: 'sys_platform_name'
|
||
}
|
||
const nextWhere: Record<string, any> = {}
|
||
Object.keys(where || {}).forEach((key) => {
|
||
if (key === 'warehouse_id' || key === 'warehouseId') return
|
||
const normalizedKey = allowedFieldMap[key]
|
||
if (!normalizedKey) return
|
||
const value = where[key]
|
||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) return
|
||
nextWhere[normalizedKey] = value
|
||
})
|
||
return nextWhere
|
||
}
|
||
|
||
function buildPayload() {
|
||
return {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where: sanitizeFallbackOrderWhere(buildWhereConditions(scanBox.value?.getConditions?.() || {}))
|
||
}
|
||
}
|
||
|
||
async function loadData() {
|
||
fallbackOrderListLoading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const res = await orderWaveWaveStrategyFallbackOrderList(buildPayload()) as
|
||
WaveStrategyFallbackOrderListResponse & { code?: number; message?: string; data?: Partial<WaveStrategyFallbackOrderListResponse> }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '获取不符合波次策略订单失败')
|
||
}
|
||
const responseList = Array.isArray(res.list)
|
||
? res.list
|
||
: Array.isArray(res.data?.list)
|
||
? res.data.list
|
||
: []
|
||
const responsePagination = res.pagination || res.data?.pagination || {}
|
||
list.value = responseList
|
||
pagination.currentPage = responsePagination.page || pagination.currentPage
|
||
pagination.pageSize = responsePagination.pageSize || pagination.pageSize
|
||
pagination.total = responsePagination.total || 0
|
||
} catch (error: any) {
|
||
console.error('fetch fallback order list failed:', error)
|
||
list.value = []
|
||
pagination.total = 0
|
||
ElMessage.error(error?.message || '获取不符合波次策略订单失败')
|
||
} finally {
|
||
fallbackOrderListLoading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
void loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function resetFallbackOrderCondition() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
void loadData()
|
||
}
|
||
|
||
function handleSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
function getFallbackOrderItemSnapshotText(row: WaveStrategyFallbackOrderListRow) {
|
||
const value = row?.item_snapshot
|
||
if (typeof value === 'string' && value.trim()) {
|
||
return value
|
||
}
|
||
return '—'
|
||
}
|
||
|
||
function formatDateTime(value: string | number | null | undefined) {
|
||
if (!value) return '—'
|
||
let normalizedValue: string | number = value
|
||
if (typeof value === 'string' && /^\d+$/.test(value.trim())) {
|
||
const numericValue = Number(value.trim())
|
||
normalizedValue = value.trim().length <= 10 ? numericValue * 1000 : numericValue
|
||
} else if (typeof value === 'number' && Number.isFinite(value) && value > 0 && value < 1000000000000) {
|
||
normalizedValue = value * 1000
|
||
}
|
||
|
||
const date = new Date(normalizedValue)
|
||
if (Number.isNaN(date.getTime())) return String(value)
|
||
const y = date.getFullYear()
|
||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||
const d = String(date.getDate()).padStart(2, '0')
|
||
const hh = String(date.getHours()).padStart(2, '0')
|
||
const mm = String(date.getMinutes()).padStart(2, '0')
|
||
const ss = String(date.getSeconds()).padStart(2, '0')
|
||
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
|
||
}
|
||
|
||
function normalizeCode(value: unknown) {
|
||
return String(value ?? '').trim()
|
||
}
|
||
|
||
function mapNameOptions(rawList: any[], nameKeys: string[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const name = normalizeCode(nameKeys.map((key) => item?.[key]).find((v) => v !== undefined && v !== null && v !== ''))
|
||
if (!name || seen.has(name)) continue
|
||
result.push({ value: name, label: name })
|
||
seen.add(name)
|
||
}
|
||
return result
|
||
}
|
||
|
||
function unwrapIndexListResponse(res: any): any[] {
|
||
const payload = res?.data !== undefined ? res.data : res
|
||
if (Array.isArray(payload)) return payload
|
||
if (payload && typeof payload === 'object') {
|
||
if (Array.isArray(payload.list)) return payload.list
|
||
if (Array.isArray(payload.items)) return payload.items
|
||
if (Array.isArray(payload.records)) return payload.records
|
||
}
|
||
if (Array.isArray(res?.list)) return res.list
|
||
return []
|
||
}
|
||
|
||
function patchFallbackFieldOptions(fieldValue: string, options: Array<{ label: string; value: string }>) {
|
||
const targetField = availableFieldsRef.find((field: any) => field.value === fieldValue)
|
||
if (targetField) {
|
||
targetField.options = options
|
||
}
|
||
}
|
||
|
||
async function loadFallbackOrderFilterOptions() {
|
||
const hasReadyOptions = fallbackOrderOwnerOptions.value.length > 0
|
||
&& fallbackOrderLogisticsOptions.value.length > 0
|
||
&& fallbackOrderPlatformOptions.value.length > 0
|
||
if (hasReadyOptions) return
|
||
|
||
try {
|
||
const [storesRes, expressRes, platformRes] = await Promise.all([
|
||
indexApi.loadStores(),
|
||
indexApi.getExpressList({ systemOnly: 'true' }),
|
||
indexApi.getPlatformList({ systemOnly: 'true' })
|
||
])
|
||
|
||
const storesResAny = storesRes as any
|
||
const stores = Array.isArray(storesResAny?.stores)
|
||
? storesResAny.stores
|
||
: Array.isArray(storesResAny?.data?.stores)
|
||
? storesResAny.data.stores
|
||
: []
|
||
const expressRaw = unwrapIndexListResponse(expressRes)
|
||
const platformRaw = unwrapIndexListResponse(platformRes)
|
||
|
||
const ownerNameSet = new Set<string>()
|
||
stores.forEach((item: any) => {
|
||
const ownerName = String(item?.label || item?.name || '').trim()
|
||
if (!ownerName) return
|
||
ownerNameSet.add(ownerName)
|
||
})
|
||
fallbackOrderOwnerOptions.value = Array.from(ownerNameSet).map((name) => ({
|
||
label: name,
|
||
value: name
|
||
}))
|
||
fallbackOrderLogisticsOptions.value = mapNameOptions(expressRaw, ['name', 'logistics_name', 'express_name', 'label'])
|
||
fallbackOrderPlatformOptions.value = mapNameOptions(platformRaw, ['name', 'platform_name', 'sys_platform_name', 'label'])
|
||
|
||
patchFallbackFieldOptions('owner_name', fallbackOrderOwnerOptions.value)
|
||
patchFallbackFieldOptions('sys_logistics_name', fallbackOrderLogisticsOptions.value)
|
||
patchFallbackFieldOptions('sys_platform_name', fallbackOrderPlatformOptions.value)
|
||
} catch (error) {
|
||
console.error('load fallback order filter options failed:', error)
|
||
}
|
||
}
|
||
|
||
function normalizeAsyncTaskStatus(value: unknown) {
|
||
return String(value ?? '').trim().toLowerCase()
|
||
}
|
||
|
||
function isAsyncTaskSuccessStatus(status: string) {
|
||
return ['success', 'succeeded', 'completed', 'done', 'fin', 'finished'].includes(status)
|
||
}
|
||
|
||
function isAsyncTaskFailureStatus(status: string) {
|
||
return ['failed', 'failure', 'error', 'exception', 'timeout', 'not_found'].includes(status)
|
||
}
|
||
|
||
function resetWaveStrategyQuickScanResult() {
|
||
waveStrategyQuickScanResult.status = ''
|
||
waveStrategyQuickScanResult.taskId = ''
|
||
waveStrategyQuickScanResult.warehouseId = undefined
|
||
waveStrategyQuickScanResult.state = ''
|
||
waveStrategyQuickScanResult.message = ''
|
||
waveStrategyQuickScanResult.acceptedAt = ''
|
||
waveStrategyQuickScanResult.totalOrderCount = 0
|
||
waveStrategyQuickScanResult.processedOrderCount = 0
|
||
waveStrategyQuickScanResult.matchedOrderCount = 0
|
||
waveStrategyQuickScanResult.unmatchedOrderCount = 0
|
||
waveStrategyQuickScanResult.progressPercent = 0
|
||
waveStrategyQuickScanResult.startTime = ''
|
||
waveStrategyQuickScanResult.endTime = ''
|
||
waveStrategyQuickScanResult.durationMs = 0
|
||
waveStrategyQuickScanResult.errorMessage = ''
|
||
}
|
||
|
||
function handleWaveStrategyQuickScanDialogVisibleChange(visible: boolean) {
|
||
waveStrategyQuickScanDialogVisible.value = visible
|
||
if (!visible) {
|
||
resetWaveStrategyQuickScanResult()
|
||
}
|
||
}
|
||
|
||
function stopWaveStrategyQuickScanTaskPolling() {
|
||
if (waveStrategyQuickScanTaskPollTimer.value) {
|
||
clearTimeout(waveStrategyQuickScanTaskPollTimer.value)
|
||
waveStrategyQuickScanTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleWaveStrategyQuickScanTaskPolling(delay = 2000) {
|
||
stopWaveStrategyQuickScanTaskPolling()
|
||
if (!waveStrategyQuickScanResult.taskId) return
|
||
waveStrategyQuickScanTaskPollTimer.value = setTimeout(() => {
|
||
void pollWaveStrategyQuickScanTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyWaveStrategyQuickScanTaskProgress(progress: Partial<WaveStrategyQuickScanTaskProgressResponse> & Record<string, any>) {
|
||
waveStrategyQuickScanResult.taskId = String(progress.task_id || waveStrategyQuickScanResult.taskId || '')
|
||
waveStrategyQuickScanResult.state = String(progress.state || waveStrategyQuickScanResult.state || 'submitted')
|
||
waveStrategyQuickScanResult.warehouseId = Number(progress.warehouse_id ?? waveStrategyQuickScanResult.warehouseId ?? 0) || undefined
|
||
waveStrategyQuickScanResult.totalOrderCount = Number(progress.total_order_count ?? waveStrategyQuickScanResult.totalOrderCount ?? 0)
|
||
waveStrategyQuickScanResult.processedOrderCount = Number(progress.processed_order_count ?? waveStrategyQuickScanResult.processedOrderCount ?? 0)
|
||
waveStrategyQuickScanResult.matchedOrderCount = Number(progress.matched_order_count ?? waveStrategyQuickScanResult.matchedOrderCount ?? 0)
|
||
waveStrategyQuickScanResult.unmatchedOrderCount = Number(progress.unmatched_order_count ?? waveStrategyQuickScanResult.unmatchedOrderCount ?? 0)
|
||
waveStrategyQuickScanResult.progressPercent = Number(progress.progress_percent ?? waveStrategyQuickScanResult.progressPercent ?? 0)
|
||
waveStrategyQuickScanResult.startTime = String(progress.start_time || waveStrategyQuickScanResult.startTime || '')
|
||
waveStrategyQuickScanResult.endTime = String(progress.end_time || waveStrategyQuickScanResult.endTime || '')
|
||
waveStrategyQuickScanResult.durationMs = Number(progress.duration_ms ?? waveStrategyQuickScanResult.durationMs ?? 0)
|
||
waveStrategyQuickScanResult.errorMessage = String(progress.error_message || '')
|
||
}
|
||
|
||
async function pollWaveStrategyQuickScanTaskProgress() {
|
||
if (!waveStrategyQuickScanResult.taskId) return
|
||
try {
|
||
const res = await orderWaveWaveStrategyQuickScanTaskProgress({
|
||
task_id: waveStrategyQuickScanResult.taskId
|
||
}) as WaveStrategyQuickScanTaskProgressResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '查询波次策略快速扫描进度失败')
|
||
}
|
||
|
||
applyWaveStrategyQuickScanTaskProgress(res)
|
||
const normalizedStatus = normalizeAsyncTaskStatus(waveStrategyQuickScanResult.state)
|
||
if (isAsyncTaskFailureStatus(normalizedStatus)) {
|
||
stopWaveStrategyQuickScanTaskPolling()
|
||
waveStrategyQuickScanResult.message = waveStrategyQuickScanResult.errorMessage || res?.message || '快速扫描任务执行失败'
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(waveStrategyQuickScanResult.progressPercent || 0) >= 100) {
|
||
stopWaveStrategyQuickScanTaskPolling()
|
||
waveStrategyQuickScanResult.message = res?.message || '快速扫描任务已完成'
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
scheduleWaveStrategyQuickScanTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll wave strategy quick scan task progress failed:', error)
|
||
scheduleWaveStrategyQuickScanTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
async function submitWaveStrategyQuickScan() {
|
||
stopWaveStrategyQuickScanTaskPolling()
|
||
waveStrategyQuickScanSubmitting.value = true
|
||
waveStrategyQuickScanDialogVisible.value = true
|
||
try {
|
||
const res = await orderWaveWaveStrategyQuickScan() as WaveStrategyQuickScanResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '提交波次策略快速扫描任务失败')
|
||
}
|
||
|
||
waveStrategyQuickScanResult.status = String(res.status || '')
|
||
waveStrategyQuickScanResult.taskId = String(res.task_id || '')
|
||
waveStrategyQuickScanResult.warehouseId = Number(res.warehouse_id || 0) || undefined
|
||
waveStrategyQuickScanResult.state = String(res.state || '')
|
||
waveStrategyQuickScanResult.message = String(res.message || '')
|
||
waveStrategyQuickScanResult.acceptedAt = String(res.accepted_at || '')
|
||
waveStrategyQuickScanResult.progressPercent = 0
|
||
waveStrategyQuickScanResult.errorMessage = ''
|
||
|
||
ElMessage.success((res?.message || '波次策略快速扫描任务已提交') + (res?.task_id ? `(任务ID:${res.task_id})` : ''))
|
||
if (waveStrategyQuickScanResult.taskId) {
|
||
scheduleWaveStrategyQuickScanTaskPolling(1000)
|
||
}
|
||
} catch (error: any) {
|
||
console.error('submit wave strategy quick scan failed:', error)
|
||
resetWaveStrategyQuickScanResult()
|
||
waveStrategyQuickScanDialogVisible.value = false
|
||
ElMessage.error(error?.message || '提交波次策略快速扫描任务失败')
|
||
} finally {
|
||
waveStrategyQuickScanSubmitting.value = false
|
||
}
|
||
}
|
||
|
||
async function submitFallbackOrderFetchByIds() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要抓取散单的订单')
|
||
return
|
||
}
|
||
|
||
const ids = selectionRows.value
|
||
.map((row: any) => Number(row?.id ?? row?.order_id))
|
||
.filter((id: number) => Number.isFinite(id) && id > 0)
|
||
|
||
if (!ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少有效订单ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定将选中的 ${ids.length} 条订单按散单抓取至波次吗?`,
|
||
'抓取散单',
|
||
{ type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
singleOrderSubmitting.value = true
|
||
try {
|
||
const res: any = await orderWaveSingleFetchByIds({ ids })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '抓取散单失败')
|
||
}
|
||
|
||
const payload =
|
||
res?.data && typeof res.data === 'object' && !Array.isArray(res.data)
|
||
? res.data
|
||
: res
|
||
const waveNo = payload?.wave_no ?? ''
|
||
const fetched = Number(payload?.fetched_order_count ?? 0)
|
||
const parts = [
|
||
res?.message || payload?.message || '抓取散单成功',
|
||
waveNo ? `波次:${waveNo}` : '',
|
||
Number.isFinite(fetched) && fetched >= 0 ? `已抓取 ${fetched} 单` : ''
|
||
]
|
||
const excluded = payload?.excluded_existing_wave_order_ids
|
||
const skipped = payload?.skipped_order_ids
|
||
const notFound = payload?.not_found_order_ids
|
||
if (Array.isArray(excluded) && excluded.length) {
|
||
parts.push(`已在波次中跳过 ${excluded.length} 单`)
|
||
}
|
||
if (Array.isArray(skipped) && skipped.length) {
|
||
parts.push(`跳过 ${skipped.length} 单`)
|
||
}
|
||
if (Array.isArray(notFound) && notFound.length) {
|
||
parts.push(`未找到 ${notFound.length} 单`)
|
||
}
|
||
|
||
ElMessage.success(parts.filter(Boolean).join(';'))
|
||
selectionRows.value = []
|
||
await loadData()
|
||
} catch (error: any) {
|
||
console.error('fetch fallback order by ids failed:', error)
|
||
ElMessage.error(error?.message || '抓取散单失败')
|
||
} finally {
|
||
singleOrderSubmitting.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
safeInvoke(async () => {
|
||
await loadFallbackOrderFilterOptions()
|
||
await loadData()
|
||
})
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
stopWaveStrategyQuickScanTaskPolling()
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../orderManagement/styles/order-sub.scss";
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.order-info-text {
|
||
display: inline-block;
|
||
max-width: 100%;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.order-sub-container .main-content {
|
||
.toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
|
||
.toolbar-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
flex-shrink: 0;
|
||
padding-left: 8px;
|
||
}
|
||
|
||
.toolbar-switch-label {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-regular);
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
}
|
||
</style>
|