From ebf20f5269af1b2c4d0aa26f980483bcffce2b7d Mon Sep 17 00:00:00 2001 From: yin <3313488199@qq.com> Date: Tue, 24 Nov 2026 18:20:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(wave):=20=E7=A7=BB=E9=99=A4=E5=9B=A2?= =?UTF-8?q?=E8=B4=AD=E6=B3=A2=E6=AC=A1=E9=9D=A2=E6=9D=BF=E5=86=85=E5=B5=8C?= =?UTF-8?q?=E6=95=A3=E5=8D=95=E6=8A=93=E5=8F=96=E5=BC=B9=E7=AA=97=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=A1=AE=E8=AE=A4=E6=89=93=E5=8D=B0=E4=B8=BA?= =?UTF-8?q?=E8=BF=90=E5=8D=95=E5=8F=B7=E5=8F=A3=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GroupWaveBatchListPanel 删除内嵌「散单抓取」弹窗及其 ScanBox、订单表格、 查询/提交逻辑(约 1400 行),团购波次面板只保留团购相关操作, 散单抓取统一走散单波次 / 策略入口,避免两处实现分叉 - 确认打印(print.confirmWavePrint)相关文案统一为「运单号」: 扫描提示、输入占位、连续扫码注释与错误提示均改为运单号口径 - 散单波次面板将 hasExpress 重命名为 hasWaybill, 打印数据提示改为「含运单号 / 无运单号」 - 波次管理页与配置注释同步改为运单号描述,明确扫描的是波次内任一订单的运单号 --- .../waveOrder/GroupWaveBatchListPanel.vue | 1466 +---------------- .../waveOrder/SandanWaveBatchListPanel.vue | 12 +- .../component/ConfirmWavePrintDialog.vue | 6 +- .../order/waveOrder/config/wave-config.ts | 4 +- src/views/order/waveOrder/index.vue | 4 +- 5 files changed, 17 insertions(+), 1475 deletions(-) diff --git a/src/views/order/waveOrder/GroupWaveBatchListPanel.vue b/src/views/order/waveOrder/GroupWaveBatchListPanel.vue index 9a8a2a87..bee44cac 100644 --- a/src/views/order/waveOrder/GroupWaveBatchListPanel.vue +++ b/src/views/order/waveOrder/GroupWaveBatchListPanel.vue @@ -428,250 +428,6 @@ - - - -
- - -
-
-
- 已选 {{ fallbackOrderSelectionRows.length }} 个订单 -
-
- - 快速扫描 - - 查询 - 重置 - 按订单IDs抓取删单 -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-
- - -
-
-
- 当前仓库波次策略(wms_wave_strategy) -
-
- - 新建策略 - - - 刷新 - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -934,7 +503,6 @@ import { getStatusTextClass } from '@/utils/statusText' import { waveUpperTableDefaults, waveAvailableFields, - fallbackOrderAvailableFields, waveBatchColumns, waveGroupOrderColumns, waveWhereAllowedFields, @@ -942,9 +510,6 @@ import { sortRowsByColumn, formatWaveOperationDetails, getWaveToolbarButtons, - waveStrategyFormRules, - waveStrategyStatusOptions, - waveBooleanOptions, waveStatusTextMap, waveTypeTextMap, waveStorageAssignmentStatusTextMap, @@ -959,9 +524,6 @@ import { getWaveAssignmentAggregateTagType, formatWaveSource, getWaveSourceTagType, - buildOutboundPrintQueue, - fetchOutboundWaveList, - resolveOutboundPrintRowKey, resolveWaveOrderWaybillText } from './config/wave-config' import { safeInvoke } from '@/utils/safe-invoke' @@ -973,7 +535,6 @@ import PendingOrderListPanel from './component/PendingOrderListPanel.vue' import WaveBatchDetailPanel from './component/WaveBatchDetailPanel.vue' import WaveFetchTaskProgressDialog from './component/WaveFetchTaskProgressDialog.vue' import WaveBatchTaskProgressDialog from './component/WaveBatchTaskProgressDialog.vue' -import WaveStrategyQuickScanProgressDialog from './component/WaveStrategyQuickScanProgressDialog.vue' import ConfirmWavePrintDialog from './component/ConfirmWavePrintDialog.vue' import * as indexApi from '@/api/index/index' import { @@ -995,14 +556,6 @@ import { orderWaveFetch, orderWaveGroupFetch, orderWaveSingleFetch, - orderWaveSingleFetchByIds, - orderWaveWaveStrategyCreate, - orderWaveWaveStrategyFetchAdmin, - orderWaveWaveStrategyFallbackOrderList, - orderWaveWaveStrategyQuickScan, - orderWaveWaveStrategyQuickScanTaskProgress, - orderWaveWaveStrategyUpdate, - orderWaveWaveStrategyList, orderWaveFetchTaskProgress, orderWaveGroupOrderFetchList, orderWaveFetchableOrderCount @@ -1026,16 +579,7 @@ import type { WaveFetchParams, WaveFetchResponse, WaveFetchTaskProgressResponse, - WaveSingleFetchParams, - WaveStrategyCreateParams, - WaveStrategyFetchTaskCreatedResponse, - WaveStrategyFallbackOrderListResponse, - WaveStrategyFallbackOrderListRow, - WaveStrategyListResponse, - WaveStrategyMutationResponse, - WaveStrategyUpdateParams, - WaveStrategyQuickScanResponse, - WaveStrategyQuickScanTaskProgressResponse + WaveSingleFetchParams } from '@/api/order.wave/orderwave' import { useUserStore } from '@/stores/modules/user' import { getWavePlatformPrintData } from '@/api/order.print/orderprint' @@ -1053,7 +597,6 @@ const props = withDefaults( } ) -const groupWaveFallbackScanBoxCacheKey = computed(() => `${props.scanBoxCacheKey}-fallback-orders`) const WAVE_TYPE = 1 as const @@ -1079,13 +622,12 @@ const batchCancelLoading = ref(false) const batchQuickRecheckByWaveLoading = ref(false) const printStatusLoadingRowIds = ref>(new Set()) const batchPrintLoading = ref(false) -const batchOutboundPrintLoading = ref(false) const batchPlatformPrintLoading = ref(false) const platformPrintDialogVisible = ref(false) const platformPrintPayload = ref(null) const platformPrintErrorMessage = ref('') const platformPrintRequestMeta = ref<{ warehouse_id: number; wave_ids: Array } | null>(null) -/** 确认打印弹窗(print.confirmWavePrint,扫面单号确认整波) */ +/** 确认打印弹窗(print.confirmWavePrint,扫运单号确认整波) */ const confirmWavePrintVisible = ref(false) const batchAllocateExpressLoading = ref(false) const batchAllocateStorageLoading = ref(false) @@ -1094,9 +636,6 @@ const userStore = useUserStore() const wavePrintDialogVisible = ref(false) const wavePrintRows = ref([]) const wavePrintDataMap = ref>({}) -const outboundPrintDialogVisible = ref(false) -const outboundPrintRows = ref([]) -const outboundPrintDataMap = ref>({}) const queryTime = ref(0) const tableSize = ref('small') const activeTab = ref('detail') @@ -1127,8 +666,6 @@ const batchAllocateExpressTaskPollTimer = ref | nu const batchAllocateStorageTaskPollTimer = ref | null>(null) const batchRemoveExceptionOrdersTaskPollTimer = ref | null>(null) const batchCancelTaskPollTimer = ref | null>(null) -const waveStrategyQuickScanTaskPollTimer = ref | null>(null) -const waveStrategyQuickScanDialogVisible = ref(false) const pendingOrderDialogVisible = ref(false) const pendingOrderDialogWaveNo = ref('') const fetchTaskProgress = reactive({ @@ -1201,74 +738,8 @@ const batchCancelTaskProgress = reactive({ const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) const currentSort = reactive({ prop: '', order: '' }) const groupOrderPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) -const singleOrderDialogVisible = ref(false) -const singleOrderActiveTab = ref<'fallback-orders' | 'strategy-api'>('fallback-orders') -const singleOrderSubmitting = ref(false) -const singleOrderTableRef = ref(null) -const fallbackOrderScanBox = ref(null) -const fallbackOrderListLoading = ref(false) -const fallbackOrderList = ref([]) -const fallbackOrderSelectionRows = ref([]) -const fallbackOrderPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) -const waveStrategyListLoading = ref(false) -const waveStrategyQuickScanSubmitting = ref(false) -const waveStrategyFetchSubmittingId = ref(null) -const waveStrategyList = ref([]) -const waveStrategyFormDialogVisible = ref(false) -const waveStrategyFormSubmitting = ref(false) -const waveStrategyFormMode = ref<'create' | 'edit'>('create') -const waveStrategyEditingId = ref(null) -const waveStrategyFormRef = ref(null) -const waveStrategyFormModel = reactive({ - strategy_name: '', - strategy_type: undefined as number | undefined, - batch_mode: undefined as number | undefined, - status: undefined as number | undefined, - order_min_sku: undefined as number | undefined, - order_max_sku: undefined as number | undefined, - order_min_qty: undefined as number | undefined, - order_max_qty: undefined as number | undefined, - min_same_structure: undefined as number | undefined, - max_same_structure: undefined as number | undefined, - batch_max_orders: undefined as number | undefined, - batch_max_skus: undefined as number | undefined, - group_batch_max_orders: undefined as number | undefined, - require_same_express: undefined as boolean | undefined, - allow_cross_owner: undefined as boolean | undefined, - description: '', - allowed_owners: [] as string[], - allowed_expresses: [] as string[], - allowed_provinces: [] as string[], - allowed_platforms: [] as string[] -}) -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 waveStrategyPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) -const fallbackOrderOwnerOptions = ref>([]) -const fallbackOrderLogisticsOptions = ref>([]) -const fallbackOrderPlatformOptions = ref>([]) -const waveStrategyOwnerOptions = ref>([]) -const waveStrategyExpressOptions = ref>([]) -const waveStrategyProvinceOptions = ref>([]) -const waveStrategyPlatformOptions = ref>([]) const presetTree = ref([]) const availableFieldsRef = reactive(JSON.parse(JSON.stringify(waveAvailableFields))) -const fallbackOrderAvailableFieldsRef = reactive(JSON.parse(JSON.stringify(fallbackOrderAvailableFields))) const columns = ref(JSON.parse(JSON.stringify(waveBatchColumns))) const toolbarButtons = computed(() => getWaveToolbarButtons(WAVE_TYPE)) @@ -1294,7 +765,6 @@ const buttonLoadingMap = computed(() => ({ batchCancelLoading: batchCancelLoading.value, batchQuickRecheckByWaveLoading: batchQuickRecheckByWaveLoading.value, batchPrintLoading: batchPrintLoading.value, - batchOutboundPrintLoading: batchOutboundPrintLoading.value, batchPlatformPrintLoading: batchPlatformPrintLoading.value, batchAllocateExpressLoading: batchAllocateExpressLoading.value, batchAllocateStorageLoading: batchAllocateStorageLoading.value, @@ -1306,7 +776,6 @@ const batchPlatformPrintDisabled = computed(() => !printableSelectionRows.value. const buttonDisabledMap = computed(() => ({ batchPickingPrintDisabled: batchPrintDisabled.value, batchPrintDisabled: batchPrintDisabled.value, - batchOutboundPrintDisabled: batchPrintDisabled.value, batchPlatformPrintDisabled: batchPlatformPrintDisabled.value, noSelection: !hasSelection.value })) @@ -1346,13 +815,9 @@ const toolbarActionMap: Record void> = { openColumnConfigPanel: () => openColumnConfigPanel(), toggleDetailVisible: () => toggleDetailVisible(), handleBatchPrint: () => handleBatchPrint(), - handleBatchOutboundPrint: () => { - void handleBatchOutboundPrint() - }, handleBatchPlatformPrint: () => { void handleBatchPlatformPrint() }, - handleBatchPrintPickingList: () => handleBatchPrintPickingList(), handleBatchAutoGrouping: () => { void handleBatchAutoGrouping() }, @@ -1375,7 +840,6 @@ const toolbarActionMap: Record void> = { void handleBatchRemoveExceptionOrders() }, openGroupOrderDialog: () => openGroupOrderDialog(), - openSingleOrderDialog: () => openSingleOrderDialog(), openConfirmWavePrintDialog: () => { confirmWavePrintVisible.value = true } @@ -1431,66 +895,6 @@ const tableListId = computed(() => `wave-management-list-${WAVE_TYPE}`) const okCode = (code: unknown) => code === 1 || code === 200 || code === 0 -function unwrapWaveStrategyFetchPayload(res: any): WaveStrategyFetchTaskCreatedResponse { - if (res && typeof res.data === 'object' && res.data !== null && !Array.isArray(res.data)) { - return res.data as WaveStrategyFetchTaskCreatedResponse - } - return res as WaveStrategyFetchTaskCreatedResponse -} - -function applyWaveStrategyFetchUiResult( - payload: WaveStrategyFetchTaskCreatedResponse, - options: { defaultSuccessHint?: string; afterSuccess?: () => void | Promise } = {} -) { - const validationErrors = payload?.validation_errors - if (Array.isArray(validationErrors) && validationErrors.length) { - const detail = validationErrors - .map((e) => [e?.field, e?.message].filter(Boolean).join(': ') || '') - .filter(Boolean) - .join(';') - ElMessage.warning(detail || payload?.message || '入参校验未通过') - return - } - - const fs = payload.fetch_state - - if (fs === 2) { - ElMessage.warning(payload.tip || payload.message || '抓取任务创建失败') - return - } - - if (fs === 3) { - const taskId = String(payload.task_id ?? payload.existing_task_id ?? '') - const taskNo = String(payload.task_no ?? payload.existing_task_no ?? '') - const tip = - payload.tip || - payload.message || - (payload.can_enter_pick_flow ? '存在未完成任务,可直接进入拣货流程' : '存在未完成的抓取任务') - const suffix = [taskNo ? `任务编号:${taskNo}` : '', taskId ? `任务ID:${taskId}` : ''].filter(Boolean).join(',') - ElMessage.success(suffix ? `${tip}(${suffix})` : tip) - const after = options.afterSuccess - if (after) void after() - return - } - - if (fs === 1 || fs === undefined || fs === null) { - const taskId = String(payload?.task_id ?? '') - const taskNo = String(payload?.task_no ?? '') - const summary = String(payload?.plan_summary ?? '') - if (fs === 1 && !taskId && !taskNo && !summary) { - ElMessage.warning(payload?.message || '接口未返回任务信息') - return - } - const hint = summary || payload?.message || options.defaultSuccessHint || '抓取任务已创建' - const suffix = [taskNo ? `任务编号:${taskNo}` : '', taskId ? `任务ID:${taskId}` : ''].filter(Boolean).join(',') - ElMessage.success(suffix ? `${hint}(${suffix})` : hint) - const after = options.afterSuccess - if (after) void after() - return - } - - ElMessage.warning(payload?.message || `未知抓取状态(fetch_state=${String(fs)})`) -} const printableSelectionRows = computed(() => selectionRows.value.filter((row: any) => !isAutoGroupingWave(row))) const autoGroupingSelectionRows = computed(() => selectionRows.value.filter((row: any) => isAutoGroupingWave(row))) const selectedWaveOrderTotal = computed(() => { @@ -1505,15 +909,6 @@ const { handleWavePickComplete, isWavePickCompleteLoading } = useWavePickComplet onSuccess: () => loadData() }) -watch( - () => singleOrderActiveTab.value, - (tab) => { - if (tab === 'strategy-api' && singleOrderDialogVisible.value) { - void fetchWaveStrategyList() - } - } -) - onMounted(() => { initializePage() }) @@ -1524,7 +919,6 @@ onBeforeUnmount(() => { stopBatchAllocateStorageTaskPolling() stopBatchRemoveExceptionOrdersTaskPolling() stopBatchCancelTaskPolling() - stopWaveStrategyQuickScanTaskPolling() }) async function initializePage() { @@ -2067,8 +1461,6 @@ async function openBatchPrintDialog(rows: any[]) { items: raw.items || [], expresses: raw.expresses || [] })) - console.log('[拣货单打印] rawList[0] keys:', rawList.length > 0 ? Object.keys(rawList[0]) : 'empty') - console.log('[拣货单打印] orderList[0] has expresses:', orderList.length > 0 ? Array.isArray(orderList[0].expresses) && orderList[0].expresses.length : 'empty') // 通过 detail API 逐条补全运单号等完整数据(与 fetchPendingOrderDetailById 同样调用方式) const enrichedMap: Record = {} @@ -2081,7 +1473,6 @@ async function openBatchPrintDialog(rows: any[]) { ids: [oid], tableType: 'order' }) - console.log('[拣货单打印] detail API 响应:', JSON.stringify({ oid, code: detailRes?.code, flag: detailRes?.flag, hasDetail: !!detailRes?.data?.detail, hasExpresses: !!detailRes?.data?.expresses, expressCount: detailRes?.data?.expresses?.length })) if (detailRes && (detailRes.code === 200 || detailRes.code === 0 || detailRes.flag === 'success')) { const payload = detailRes.data?.detail || detailRes.data || detailRes if (payload && typeof payload === 'object') { @@ -2093,10 +1484,9 @@ async function openBatchPrintDialog(rows: any[]) { } } } catch (e) { - console.error('[拣货单打印] detail API 异常:', e) + // 单条失败不影响其他订单 } } - console.log('[拣货单打印] enrichedMap keys:', Object.keys(enrichedMap), 'enriched has expresses:', Object.values(enrichedMap).some((v: any) => Array.isArray(v.expresses) && v.expresses.length > 0)) if (Object.keys(enrichedMap).length > 0) { orderList = orderList.map((o: any) => { const enriched = enrichedMap[String(o.id ?? '')] @@ -2184,99 +1574,6 @@ async function handleBatchPrint() { await openBatchPrintDialog(rows) } -async function loadOutboundPrintFormData(row: any) { - const key = String(row?.id ?? resolveOutboundPrintRowKey(row || {}, String(row?.wave_id ?? ''), 0)) - return outboundPrintDataMap.value[key] || row || {} -} - -async function openBatchOutboundPrintDialog(rows: any[]) { - const first = rows[0] as Record - const warehouseId = Number(first?.warehouse_id ?? userStore.user?.warehouse_id ?? userStore.user?.store_id) - if (!Number.isFinite(warehouseId) || warehouseId <= 0) { - ElMessage.error('无法确定仓库 ID,请确认列表中的仓库字段或当前登录仓库上下文') - return - } - - const wave_ids = rows - .map((row: any) => row?.id ?? row?.wave_id ?? row?.batch_id) - .filter((id: unknown) => id !== undefined && id !== null && id !== '') - - if (!wave_ids.length) { - ElMessage.warning('当前勾选记录缺少可用的波次 ID') - return - } - - batchOutboundPrintLoading.value = true - try { - const waveList = await fetchOutboundWaveList(wave_ids) - if (!waveList.length) { - ElMessage.warning('未获取到波次订单数据') - return - } - const { printRows, dataMap } = buildOutboundPrintQueue(waveList, rows) - if (!printRows.length) { - ElMessage.warning('未获取到可打印的出库单明细,请确认波次下存在订单且快递已完全分配') - return - } - outboundPrintRows.value = printRows - outboundPrintDataMap.value = dataMap - outboundPrintDialogVisible.value = true - ElMessage.success(`已获取出库单打印数据,共 ${printRows.length} 单`) - } catch (error: any) { - outboundPrintRows.value = [] - outboundPrintDataMap.value = {} - ElMessage.error(error?.message || '获取出库单打印数据失败') - } finally { - batchOutboundPrintLoading.value = false - } -} - -async function handleBatchOutboundPrint() { - if (!selectionRows.value.length) { - ElMessage.warning('请先勾选要打印的波次') - return - } - - const autoGroupingRows = [...autoGroupingSelectionRows.value] - const removedCount = autoGroupingRows.length - - if (removedCount) { - autoGroupingRows.forEach((row: any) => { - upperTable.value?.toggleRowSelection?.(row, false) - }) - } - - if (!printableSelectionRows.value.length) { - ElMessage.warning('自动加团中的波次不参与批量打印,已从当前勾选中移除') - return - } - - if (waveMaxOrderLimit.value !== null && selectedWaveOrderTotal.value > waveMaxOrderLimit.value) { - ElMessage.warning(`选中波次总订单数为 ${selectedWaveOrderTotal.value},超过仓库配置上限 ${waveMaxOrderLimit.value} 单,暂不允许批量打印`) - return - } - if (waveMaxOrderLimit.value === null) { - ElMessage.warning('未获取到仓库波次最大订单数量配置,暂无法执行批量打印') - return - } - - if (removedCount) { - ElMessage.warning(`已自动移除 ${removedCount} 个“自动加团中”波次,不计入批量打印`) - } - - await openBatchOutboundPrintDialog(printableSelectionRows.value) -} - -async function handleBatchPrintPickingList() { - if (!selectionRows.value.length) { - ElMessage.warning('请先勾选要打印拣货单的波次') - return - } - - const rows = [...selectionRows.value] - await openBatchPrintDialog(rows) -} - async function handleBatchPlatformPrint() { if (!selectionRows.value.length) { ElMessage.warning('请先勾选要打印的波次') @@ -3176,213 +2473,6 @@ function openGroupOrderDialog() { searchGroupOrders() } -function openSingleOrderDialog() { - singleOrderDialogVisible.value = true - singleOrderActiveTab.value = 'fallback-orders' - fallbackOrderPagination.currentPage = 1 - fallbackOrderSelectionRows.value = [] - waveStrategyPagination.currentPage = 1 - waveStrategyList.value = [] - waveStrategyPagination.total = 0 - void loadFallbackOrderFilterOptions() - void fetchFallbackOrderList() -} - -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() - 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 mapCodeNameOptions(rawList: any[], codeKeys: string[], nameKeys: string[]) { - const result: Array<{ label: string; value: string }> = [] - const seen = new Set() - for (const item of rawList || []) { - const code = normalizeCode(codeKeys.map((key) => item?.[key]).find((v) => v !== undefined && v !== null && v !== '')) - if (!code || seen.has(code)) continue - const name = normalizeCode(nameKeys.map((key) => item?.[key]).find((v) => v !== undefined && v !== null && v !== '')) - result.push({ - value: code, - label: name && name !== code ? `${code} (${name})` : code - }) - seen.add(code) - } - return result -} - -function toStringList(value: unknown): string[] { - if (Array.isArray(value)) { - return value.map((item) => String(item).trim()).filter(Boolean) - } - if (typeof value === 'string') { - return value.split(',').map((item) => item.trim()).filter(Boolean) - } - return [] -} - -function patchSelectOptionsByValues( - optionsRef: { value: Array<{ label: string; value: string }> }, - values: string[] -) { - const existing = new Set(optionsRef.value.map((item) => item.value)) - const missing = values.filter((item) => item && !existing.has(item)) - if (!missing.length) return - optionsRef.value = optionsRef.value.concat(missing.map((value) => ({ label: value, value }))) -} - -type RegionNode = { code: string; name: string; children?: RegionNode[] } - -/** 省市区字典选项(懒加载):首屏不下载该 134KB chunk,等真正用到省份选项时再拉 */ -let provinceOptionsFromDict: Array<{ label: string; value: string }> = [] -let provinceOptionsLoading: Promise | null = null - -function ensureProvinceOptionsFromDict() { - if (provinceOptionsFromDict.length || provinceOptionsLoading) return - provinceOptionsLoading = import('china-division/dist/pca-code.json') - .then((mod) => { - const tree = (Array.isArray((mod as any).default) ? (mod as any).default : []) as RegionNode[] - provinceOptionsFromDict = tree - .map((item) => ({ - label: String(item?.name || '').trim(), - value: String(item?.name || '').trim() - })) - .filter((item) => item.value) - provinceOptionsLoading = null - // 字典就绪后重建一次省份选项,把完整省份名补进去 - refreshWaveStrategyProvinceOptions() - }) - .catch(() => { - provinceOptionsLoading = null - }) -} - -function refreshWaveStrategyProvinceOptions() { - ensureProvinceOptionsFromDict() - const provinceSet = new Set(provinceOptionsFromDict.map((item) => item.value)) - waveStrategyFormModel.allowed_provinces.forEach((item) => { - const value = normalizeCode(item) - if (value) provinceSet.add(value) - }) - waveStrategyList.value.forEach((row: any) => { - toStringList(row?.allowed_provinces).forEach((item) => { - const value = normalizeCode(item) - if (value) provinceSet.add(value) - }) - }) - fallbackOrderList.value.forEach((row: any) => { - const value = normalizeCode(row?.province) - if (value) provinceSet.add(value) - }) - waveStrategyProvinceOptions.value = Array.from(provinceSet).map((value) => ({ label: value, value })) -} - -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 = fallbackOrderAvailableFieldsRef.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() - const waveStrategyOwnerCodeSet = new Set() - stores.forEach((item: any) => { - const ownerName = String(item?.label || item?.name || '').trim() - if (!ownerName) return - ownerNameSet.add(ownerName) - const ownerCode = normalizeCode(item?.value ?? item?.id ?? item?.owner_code ?? item?.code) - if (ownerCode) waveStrategyOwnerCodeSet.add(ownerCode) - }) - fallbackOrderOwnerOptions.value = Array.from(ownerNameSet).map((name) => ({ - label: name, - value: name - })) - waveStrategyOwnerOptions.value = Array.from(waveStrategyOwnerCodeSet).map((code) => { - const owner = stores.find((item: any) => normalizeCode(item?.value ?? item?.id ?? item?.owner_code ?? item?.code) === code) - const ownerName = normalizeCode(owner?.label || owner?.name) - return { - value: code, - label: ownerName && ownerName !== code ? `${code} (${ownerName})` : code - } - }) - fallbackOrderLogisticsOptions.value = mapNameOptions(expressRaw, ['name', 'logistics_name', 'express_name', 'label']) - fallbackOrderPlatformOptions.value = mapNameOptions(platformRaw, ['name', 'platform_name', 'sys_platform_name', 'label']) - waveStrategyExpressOptions.value = mapCodeNameOptions( - expressRaw, - ['code', 'express_code', 'logistics_code', 'value'], - ['name', 'logistics_name', 'express_name', 'label'] - ) - waveStrategyPlatformOptions.value = mapCodeNameOptions( - platformRaw, - ['code', 'platform_code', 'value', 'platform'], - ['name', 'platform_name', 'sys_platform_name', 'label'] - ) - - patchFallbackFieldOptions('owner_name', fallbackOrderOwnerOptions.value) - patchFallbackFieldOptions('sys_logistics_name', fallbackOrderLogisticsOptions.value) - patchFallbackFieldOptions('sys_platform_name', fallbackOrderPlatformOptions.value) - patchSelectOptionsByValues(waveStrategyOwnerOptions, waveStrategyFormModel.allowed_owners) - patchSelectOptionsByValues(waveStrategyExpressOptions, waveStrategyFormModel.allowed_expresses) - patchSelectOptionsByValues(waveStrategyPlatformOptions, waveStrategyFormModel.allowed_platforms) - refreshWaveStrategyProvinceOptions() - } catch (error) { - console.error('load fallback order filter options failed:', error) - fallbackOrderOwnerOptions.value = [] - fallbackOrderLogisticsOptions.value = [] - fallbackOrderPlatformOptions.value = [] - waveStrategyOwnerOptions.value = [] - waveStrategyExpressOptions.value = [] - waveStrategyPlatformOptions.value = [] - patchFallbackFieldOptions('owner_name', []) - patchFallbackFieldOptions('sys_logistics_name', []) - patchFallbackFieldOptions('sys_platform_name', []) - refreshWaveStrategyProvinceOptions() - } -} - async function loadGroupOrderStoreOptions() { if (groupOrderStoreOptions.value.length > 0) return try { @@ -3440,443 +2530,6 @@ function buildGroupOrderListPayload() { return buildStructureFetchListPayload(groupOrderPagination, groupOrderFilters) } -function sanitizeFallbackOrderWhere(where: Record) { - const allowedFieldMap: Record = { - 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', - buyer_message_has: 'buyer_message_has' - } - const nextWhere: Record = {} - 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 buildFallbackOrderListPayload() { - const scanBox = fallbackOrderScanBox.value - return { - pagination: { - page: fallbackOrderPagination.currentPage, - pageSize: fallbackOrderPagination.pageSize - }, - where: sanitizeFallbackOrderWhere(buildWhereConditions(scanBox?.getConditions?.() || {})) - } -} - -async function fetchWaveStrategyList() { - waveStrategyListLoading.value = true - try { - const res = await orderWaveWaveStrategyList({ - pagination: { - page: waveStrategyPagination.currentPage, - pageSize: waveStrategyPagination.pageSize - }, - /** module order.wave:strategy_type 1=散单 2=团购(本页为团购波次) */ - strategy_type: 2, - }) as WaveStrategyListResponse & { code?: number; message?: string; data?: Partial } - 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 || {} - waveStrategyList.value = responseList - waveStrategyPagination.currentPage = responsePagination.page || waveStrategyPagination.currentPage - waveStrategyPagination.pageSize = responsePagination.pageSize || waveStrategyPagination.pageSize - waveStrategyPagination.total = responsePagination.total || 0 - refreshWaveStrategyProvinceOptions() - } catch (error: any) { - console.error('fetch wave strategy list failed:', error) - waveStrategyList.value = [] - waveStrategyPagination.total = 0 - refreshWaveStrategyProvinceOptions() - ElMessage.error(error?.message || '获取波次策略列表失败') - } finally { - waveStrategyListLoading.value = false - } -} - -async function submitWaveStrategyFetchAdmin(row: Record) { - const strategyId = Number(row?.id || 0) - if (!strategyId) { - ElMessage.warning('无法识别策略ID,请刷新后重试') - return - } - - waveStrategyFetchSubmittingId.value = strategyId - try { - const res = await orderWaveWaveStrategyFetchAdmin({ - strategy_id: strategyId, - source: 'admin', - operation_source: 'admin' - }) as WaveStrategyFetchTaskCreatedResponse & { code?: number; message?: string } - if (!res || !okCode(res.code)) { - throw new Error(res?.message || '提交后台抓取任务失败') - } - const payload = unwrapWaveStrategyFetchPayload(res) - applyWaveStrategyFetchUiResult(payload, { - defaultSuccessHint: '后台抓取任务已创建', - afterSuccess: () => fetchWaveStrategyList() - }) - } catch (error: any) { - console.error('submit wave strategy fetch admin failed:', error) - ElMessage.error(error?.message || '提交后台抓取任务失败') - } finally { - waveStrategyFetchSubmittingId.value = null - } -} - -function handleWaveStrategyPageChange(page: number) { - waveStrategyPagination.currentPage = page - void fetchWaveStrategyList() -} - -function handleWaveStrategyPageSizeChange(size: number) { - waveStrategyPagination.pageSize = size - waveStrategyPagination.currentPage = 1 - void fetchWaveStrategyList() -} - -function resetWaveStrategyForm() { - waveStrategyEditingId.value = null - waveStrategyFormModel.strategy_name = '' - waveStrategyFormModel.strategy_type = undefined - waveStrategyFormModel.batch_mode = undefined - waveStrategyFormModel.status = undefined - waveStrategyFormModel.order_min_sku = undefined - waveStrategyFormModel.order_max_sku = undefined - waveStrategyFormModel.order_min_qty = undefined - waveStrategyFormModel.order_max_qty = undefined - waveStrategyFormModel.min_same_structure = undefined - waveStrategyFormModel.max_same_structure = undefined - waveStrategyFormModel.batch_max_orders = undefined - waveStrategyFormModel.batch_max_skus = undefined - waveStrategyFormModel.group_batch_max_orders = undefined - waveStrategyFormModel.require_same_express = undefined - waveStrategyFormModel.allow_cross_owner = undefined - waveStrategyFormModel.description = '' - waveStrategyFormModel.allowed_owners = [] - waveStrategyFormModel.allowed_expresses = [] - waveStrategyFormModel.allowed_provinces = [] - waveStrategyFormModel.allowed_platforms = [] - refreshWaveStrategyProvinceOptions() - waveStrategyFormRef.value?.clearValidate?.() -} - -function buildWaveStrategyPayload() { - const payload: Partial = { - strategy_name: waveStrategyFormModel.strategy_name.trim(), - strategy_type: waveStrategyFormModel.strategy_type, - batch_mode: waveStrategyFormModel.batch_mode, - status: waveStrategyFormModel.status, - order_min_sku: waveStrategyFormModel.order_min_sku, - order_max_sku: waveStrategyFormModel.order_max_sku, - order_min_qty: waveStrategyFormModel.order_min_qty, - order_max_qty: waveStrategyFormModel.order_max_qty, - min_same_structure: waveStrategyFormModel.min_same_structure, - max_same_structure: waveStrategyFormModel.max_same_structure, - batch_max_orders: waveStrategyFormModel.batch_max_orders, - batch_max_skus: waveStrategyFormModel.batch_max_skus, - group_batch_max_orders: waveStrategyFormModel.group_batch_max_orders, - require_same_express: waveStrategyFormModel.require_same_express, - allow_cross_owner: waveStrategyFormModel.allow_cross_owner, - description: waveStrategyFormModel.description.trim() || undefined - } - const allowedOwners = waveStrategyFormModel.allowed_owners - const allowedExpresses = waveStrategyFormModel.allowed_expresses - const allowedProvinces = waveStrategyFormModel.allowed_provinces - const allowedPlatforms = waveStrategyFormModel.allowed_platforms - if (allowedOwners.length) payload.allowed_owners = allowedOwners - if (allowedExpresses.length) payload.allowed_expresses = allowedExpresses - if (allowedProvinces.length) payload.allowed_provinces = allowedProvinces - if (allowedPlatforms.length) payload.allowed_platforms = allowedPlatforms - - Object.keys(payload).forEach((key) => { - const value = payload[key as keyof typeof payload] - if (value === undefined) { - delete payload[key as keyof typeof payload] - } - }) - return payload -} - -function openCreateWaveStrategyDialog() { - waveStrategyFormMode.value = 'create' - resetWaveStrategyForm() - void loadFallbackOrderFilterOptions() - waveStrategyFormDialogVisible.value = true -} - -function openEditWaveStrategyDialog(row: Record) { - waveStrategyFormMode.value = 'edit' - resetWaveStrategyForm() - waveStrategyEditingId.value = Number(row?.id || 0) || null - waveStrategyFormModel.strategy_name = String(row?.strategy_name || '') - waveStrategyFormModel.strategy_type = Number(row?.strategy_type ?? 0) || undefined - waveStrategyFormModel.batch_mode = Number(row?.batch_mode ?? 0) || undefined - waveStrategyFormModel.status = row?.status === 0 || row?.status === 1 ? Number(row.status) : undefined - waveStrategyFormModel.order_min_sku = Number(row?.order_min_sku ?? 0) || undefined - waveStrategyFormModel.order_max_sku = Number(row?.order_max_sku ?? 0) || undefined - waveStrategyFormModel.order_min_qty = Number(row?.order_min_qty ?? 0) || undefined - waveStrategyFormModel.order_max_qty = Number(row?.order_max_qty ?? 0) || undefined - waveStrategyFormModel.min_same_structure = Number(row?.min_same_structure ?? 0) || undefined - waveStrategyFormModel.max_same_structure = Number(row?.max_same_structure ?? 0) || undefined - waveStrategyFormModel.batch_max_orders = Number(row?.batch_max_orders ?? 0) || undefined - waveStrategyFormModel.batch_max_skus = Number(row?.batch_max_skus ?? 0) || undefined - waveStrategyFormModel.group_batch_max_orders = Number(row?.group_batch_max_orders ?? 0) || undefined - if (row?.require_same_express === 1 || row?.require_same_express === true) { - waveStrategyFormModel.require_same_express = true - } else if (row?.require_same_express === 0 || row?.require_same_express === false) { - waveStrategyFormModel.require_same_express = false - } - if (row?.allow_cross_owner === 1 || row?.allow_cross_owner === true) { - waveStrategyFormModel.allow_cross_owner = true - } else if (row?.allow_cross_owner === 0 || row?.allow_cross_owner === false) { - waveStrategyFormModel.allow_cross_owner = false - } - waveStrategyFormModel.description = String(row?.description || '') - waveStrategyFormModel.allowed_owners = toStringList(row?.allowed_owners) - waveStrategyFormModel.allowed_expresses = toStringList(row?.allowed_expresses) - waveStrategyFormModel.allowed_provinces = toStringList(row?.allowed_provinces) - waveStrategyFormModel.allowed_platforms = toStringList(row?.allowed_platforms) - patchSelectOptionsByValues(waveStrategyOwnerOptions, waveStrategyFormModel.allowed_owners) - patchSelectOptionsByValues(waveStrategyExpressOptions, waveStrategyFormModel.allowed_expresses) - patchSelectOptionsByValues(waveStrategyPlatformOptions, waveStrategyFormModel.allowed_platforms) - refreshWaveStrategyProvinceOptions() - void loadFallbackOrderFilterOptions() - waveStrategyFormDialogVisible.value = true -} - -async function submitWaveStrategyForm() { - if (!waveStrategyFormRef.value) return - try { - await waveStrategyFormRef.value.validate() - } catch { - return - } - - waveStrategyFormSubmitting.value = true - try { - const payload = buildWaveStrategyPayload() - if (waveStrategyFormMode.value === 'create') { - const res = await orderWaveWaveStrategyCreate( - payload as WaveStrategyCreateParams - ) as WaveStrategyMutationResponse & { code?: number; message?: string; data?: Record } - if (!res || !okCode(res.code)) { - throw new Error(res?.message || '新建波次策略失败') - } - ElMessage.success(res?.message || '新建波次策略成功') - } else { - if (!waveStrategyEditingId.value) { - throw new Error('缺少策略ID,无法更新') - } - const res = await orderWaveWaveStrategyUpdate({ - id: waveStrategyEditingId.value, - ...(payload as WaveStrategyUpdateParams) - }) as WaveStrategyMutationResponse & { code?: number; message?: string; data?: Record } - if (!res || !okCode(res.code)) { - throw new Error(res?.message || '更新波次策略失败') - } - ElMessage.success(res?.message || '更新波次策略成功') - } - waveStrategyFormDialogVisible.value = false - await fetchWaveStrategyList() - } catch (error: any) { - console.error('submit wave strategy form failed:', error) - ElMessage.error(error?.message || '保存波次策略失败') - } finally { - waveStrategyFormSubmitting.value = false - } -} - -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) return - - // 扫描中关闭弹窗仅表示“后台运行”,保留任务 ID 继续轮询;结束后再清理状态。 - const status = normalizeAsyncTaskStatus(waveStrategyQuickScanResult.state) - const finished = isAsyncTaskSuccessStatus(status) - || isAsyncTaskFailureStatus(status) - || Number(waveStrategyQuickScanResult.progressPercent || 0) >= 100 - if (finished || !waveStrategyQuickScanResult.taskId) { - 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 & Record) { - 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 fetchFallbackOrderList() - return - } - - if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(waveStrategyQuickScanResult.progressPercent || 0) >= 100) { - stopWaveStrategyQuickScanTaskPolling() - waveStrategyQuickScanResult.message = res?.message || '快速扫描任务已完成' - await fetchFallbackOrderList() - return - } - - scheduleWaveStrategyQuickScanTaskPolling() - } catch (error) { - console.error('poll wave strategy quick scan task progress failed:', error) - scheduleWaveStrategyQuickScanTaskPolling(4000) - } -} - -async function submitWaveStrategyQuickScan() { - stopWaveStrategyQuickScanTaskPolling() - resetWaveStrategyQuickScanResult() - 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 - } -} - -function getFallbackOrderItemSnapshotText(row: WaveStrategyFallbackOrderListRow) { - const value = row?.item_snapshot - if (typeof value === 'string' && value.trim()) { - return value - } - return '—' -} - -async function fetchFallbackOrderList() { - fallbackOrderListLoading.value = true - try { - const res = await orderWaveWaveStrategyFallbackOrderList(buildFallbackOrderListPayload()) as - WaveStrategyFallbackOrderListResponse & { code?: number; message?: string; data?: Partial } - 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 || {} - fallbackOrderList.value = responseList - fallbackOrderPagination.currentPage = responsePagination.page || fallbackOrderPagination.currentPage - fallbackOrderPagination.pageSize = responsePagination.pageSize || fallbackOrderPagination.pageSize - fallbackOrderPagination.total = responsePagination.total || 0 - refreshWaveStrategyProvinceOptions() - } catch (error: any) { - console.error('fetch fallback order list failed:', error) - fallbackOrderList.value = [] - fallbackOrderPagination.total = 0 - refreshWaveStrategyProvinceOptions() - ElMessage.error(error?.message || '获取不符合波次策略订单失败') - } finally { - fallbackOrderListLoading.value = false - } -} - // ─── 可抓取订单数统计(order.wave.fetchableOrderCount) ─────────────── // 与「可抓取团购单」列表同一口径的汇总:同一候选条件 + items_hash 粗分组 + 团购阈值过滤, // 但不分页、不查明细,仅返回达到闵值分组的数量与组内订单数合计。 @@ -4028,42 +2681,6 @@ function handleGroupOrderPageSizeChange(size: number) { fetchGroupOrderList() } -function handleFallbackOrderSelectionChange(rows: any[]) { - fallbackOrderSelectionRows.value = rows || [] -} - -function handleFallbackOrderConditionChange() { - fallbackOrderPagination.currentPage = 1 - void fetchFallbackOrderList() -} - -function handleFallbackOrderConditionClear() { - fallbackOrderPagination.currentPage = 1 - void fetchFallbackOrderList() -} - -function handleFallbackOrderConditionReset() { - fallbackOrderPagination.currentPage = 1 - void fetchFallbackOrderList() -} - -function resetFallbackOrderCondition() { - fallbackOrderPagination.currentPage = 1 - fallbackOrderScanBox.value?.reset?.() - void fetchFallbackOrderList() -} - -function handleFallbackOrderPageChange(page: number) { - fallbackOrderPagination.currentPage = page - void fetchFallbackOrderList() -} - -function handleFallbackOrderPageSizeChange(size: number) { - fallbackOrderPagination.pageSize = size - fallbackOrderPagination.currentPage = 1 - void fetchFallbackOrderList() -} - function getGroupOrderStoreText(row: any) { if (Array.isArray(row?.store_ids) && row.store_ids.length > 1) { return row.store_ids.join(',') @@ -4172,81 +2789,6 @@ async function submitGroupOrderDialog() { } } -async function submitFallbackOrderFetchByIds() { - if (!fallbackOrderSelectionRows.value.length) { - ElMessage.warning('请先勾选要抓取删单的订单') - return - } - - const ids = fallbackOrderSelectionRows.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', buttonSize: 'small' } - ) - } 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 excludedLocked = payload?.excluded_locked_order_ids - const skipped = payload?.skipped_order_ids - const notFound = payload?.not_found_order_ids - const excludedSn = payload?.excluded_sn_order_ids - if (Array.isArray(excluded) && excluded.length) { - parts.push(`已在波次中跳过 ${excluded.length} 单`) - } - if (Array.isArray(excludedLocked) && excludedLocked.length) { - parts.push(`已锁定跳过 ${excludedLocked.length} 单`) - } - if (Array.isArray(excludedSn) && excludedSn.length) { - parts.push(`SN 订单不支持散单抓取,已跳过 ${excludedSn.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(';')) - singleOrderDialogVisible.value = false - fallbackOrderSelectionRows.value = [] - await loadData() - } catch (error: any) { - console.error('fetch fallback order by ids failed:', error) - ElMessage.error(error?.message || '抓取散单失败') - } finally { - singleOrderSubmitting.value = false - } -}