2747 lines
97 KiB
Vue
2747 lines
97 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
: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" @wheel="handleToolbarWheel">
|
||
<div
|
||
class="toolbar-scroll-container"
|
||
ref="scrollContainerRef"
|
||
@mousedown="handleMouseDown"
|
||
@mousemove="handleMouseMove"
|
||
@mouseup="handleMouseUp"
|
||
@mouseleave="handleMouseUp"
|
||
>
|
||
<el-button
|
||
v-for="button in toolbarButtons"
|
||
:key="button.key"
|
||
:size="button.size || 'small'"
|
||
:type="button.type"
|
||
:plain="button.plain"
|
||
:disabled="resolveButtonDisabled(button.disabledKey)"
|
||
:loading="resolveButtonLoading(button.loadingKey)"
|
||
@click="handleToolbarButtonClick(button.action)"
|
||
>
|
||
{{ resolveButtonLabel(button.label, button.dynamicLabelKey) }}
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="batchAllocateExpressTaskProgress.taskId" class="task-progress-panel task-progress-panel--toolbar">
|
||
<div class="task-progress-panel__header">
|
||
<span class="task-progress-panel__title">快递号分配任务进度</span>
|
||
<span class="task-progress-panel__meta">任务ID:{{ batchAllocateExpressTaskProgress.taskId }}</span>
|
||
</div>
|
||
<el-progress :percentage="batchAllocateExpressTaskPercent" :status="batchAllocateExpressTaskProgressBarStatus" :stroke-width="16" />
|
||
<div class="task-progress-panel__info">
|
||
<span>状态:{{ getFetchTaskStatusText(batchAllocateExpressTaskProgress.status) }}</span>
|
||
<span>已完成订单:{{ batchAllocateExpressTaskProgress.successCount }} / {{ batchAllocateExpressTaskProgress.totalCount }}</span>
|
||
<span>失败订单:{{ batchAllocateExpressTaskProgress.failedCount }}</span>
|
||
<span v-if="batchAllocateExpressTaskProgress.updateTime">更新时间:{{ formatDateTime(batchAllocateExpressTaskProgress.updateTime) }}</span>
|
||
</div>
|
||
<div v-if="batchAllocateExpressTaskProgress.message || batchAllocateExpressTaskProgress.error" class="task-progress-panel__message">
|
||
{{ batchAllocateExpressTaskProgress.error || batchAllocateExpressTaskProgress.message }}
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="batchAllocateStorageTaskProgress.taskId" class="task-progress-panel task-progress-panel--toolbar">
|
||
<div class="task-progress-panel__header">
|
||
<span class="task-progress-panel__title">储位分配任务进度</span>
|
||
<span class="task-progress-panel__meta">任务ID:{{ batchAllocateStorageTaskProgress.taskId }}</span>
|
||
</div>
|
||
<el-progress :percentage="batchAllocateStorageTaskPercent" :status="batchAllocateStorageTaskProgressBarStatus" :stroke-width="16" />
|
||
<div class="task-progress-panel__info">
|
||
<span>状态:{{ getFetchTaskStatusText(batchAllocateStorageTaskProgress.status) }}</span>
|
||
<span>已完成订单:{{ batchAllocateStorageTaskProgress.successCount }} / {{ batchAllocateStorageTaskProgress.totalCount }}</span>
|
||
<span>失败订单:{{ batchAllocateStorageTaskProgress.failedCount }}</span>
|
||
<span v-if="batchAllocateStorageTaskProgress.updateTime">更新时间:{{ formatDateTime(batchAllocateStorageTaskProgress.updateTime) }}</span>
|
||
</div>
|
||
<div v-if="batchAllocateStorageTaskProgress.message || batchAllocateStorageTaskProgress.error" class="task-progress-panel__message">
|
||
{{ batchAllocateStorageTaskProgress.error || batchAllocateStorageTaskProgress.message }}
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="batchRemoveExceptionOrdersTaskProgress.taskId" class="task-progress-panel task-progress-panel--toolbar">
|
||
<div class="task-progress-panel__header">
|
||
<span class="task-progress-panel__title">移除异常订单任务进度</span>
|
||
<span class="task-progress-panel__meta">任务ID:{{ batchRemoveExceptionOrdersTaskProgress.taskId }}</span>
|
||
</div>
|
||
<el-progress :percentage="batchRemoveExceptionOrdersTaskPercent" :status="batchRemoveExceptionOrdersTaskProgressBarStatus" :stroke-width="16" />
|
||
<div class="task-progress-panel__info">
|
||
<span>状态:{{ getFetchTaskStatusText(batchRemoveExceptionOrdersTaskProgress.status) }}</span>
|
||
<span>已移除订单:{{ batchRemoveExceptionOrdersTaskProgress.successCount }} / {{ batchRemoveExceptionOrdersTaskProgress.totalCount }}</span>
|
||
<span>失败订单:{{ batchRemoveExceptionOrdersTaskProgress.failedCount }}</span>
|
||
<span v-if="batchRemoveExceptionOrdersTaskProgress.updateTime">更新时间:{{ formatDateTime(batchRemoveExceptionOrdersTaskProgress.updateTime) }}</span>
|
||
</div>
|
||
<div v-if="batchRemoveExceptionOrdersTaskProgress.message || batchRemoveExceptionOrdersTaskProgress.error" class="task-progress-panel__message">
|
||
{{ batchRemoveExceptionOrdersTaskProgress.error || batchRemoveExceptionOrdersTaskProgress.message }}
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="batchCancelTaskProgress.taskId" class="task-progress-panel task-progress-panel--toolbar">
|
||
<div class="task-progress-panel__header">
|
||
<span class="task-progress-panel__title">批量取消波次任务进度</span>
|
||
<span class="task-progress-panel__meta">任务ID:{{ batchCancelTaskProgress.taskId }}</span>
|
||
</div>
|
||
<el-progress :percentage="batchCancelTaskPercent" :status="batchCancelTaskProgressBarStatus" :stroke-width="16" />
|
||
<div class="task-progress-panel__info">
|
||
<span>状态:{{ getFetchTaskStatusText(batchCancelTaskProgress.status) }}</span>
|
||
<span>已处理波次:{{ batchCancelTaskProgress.successCount }} / {{ batchCancelTaskProgress.totalCount }}</span>
|
||
<span>失败波次:{{ batchCancelTaskProgress.failedCount }}</span>
|
||
<span v-if="batchCancelTaskProgress.updateTime">更新时间:{{ formatDateTime(batchCancelTaskProgress.updateTime) }}</span>
|
||
</div>
|
||
<div v-if="batchCancelTaskProgress.message || batchCancelTaskProgress.error" class="task-progress-panel__message">
|
||
{{ batchCancelTaskProgress.error || batchCancelTaskProgress.message }}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTable"
|
||
:title="waveUpperTableDefaults.title"
|
||
:enable-column-config="waveUpperTableDefaults.enableColumnConfig"
|
||
:column-config-schema-version="3"
|
||
:table-id="tableListId"
|
||
:data="list"
|
||
:row-key="getRowIdentity"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="waveUpperTableDefaults.showIndex"
|
||
:show-selection="waveUpperTableDefaults.showSelection"
|
||
:loading="loading"
|
||
:queryTime="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<template #column-wave_id="{ row }">
|
||
<span>{{ row.wave_id ?? row.id ?? '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-wave_no="{ row }">
|
||
<span>{{ getWaveCode(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-wave_type="{ row }">
|
||
<el-tag size="small" type="info">
|
||
{{ getWaveTypeText(row) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-wave_status="{ row }">
|
||
<el-tag size="small" :type="getStatusTagType(row)">
|
||
{{ getStatusText(row) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-total_orders="{ row }">
|
||
<span>{{ row.total_orders ?? getOrderCount(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-order_count="{ row }">
|
||
<span>{{ getOrderCount(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-processed_orders="{ row }">
|
||
<span>{{ getProcessedOrders(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-storage_assignment_status="{ row }">
|
||
<el-tag size="small" :type="getAssignmentTagType(getStorageAssignmentStatusText(row))">
|
||
{{ getStorageAssignmentStatusText(row) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-express_assignment_status="{ row }">
|
||
<el-tag size="small" :type="getAssignmentTagType(row.express_assignment_status)">
|
||
{{ row.express_assignment_status || '—' }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-print_assignment_status="{ row }">
|
||
<el-tag size="small" :type="getAssignmentTagType(row.print_assignment_status)">
|
||
{{ row.print_assignment_status || '—' }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-distinguish_express="{ row }">
|
||
<el-tag size="small" :type="Number(row?.distinguish_express) ? 'warning' : 'info'">
|
||
{{ Number(row?.distinguish_express) ? '是' : '否' }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-item_detail_machine="{ row }">
|
||
<span class="order-info-text">{{ row.item_detail_machine || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-item_snapshot_key="{ row }">
|
||
<span class="order-info-text">{{ row.item_snapshot_key || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-item_snapshot="{ row }">
|
||
<span class="order-info-text">{{ getItemSnapshotText(row) }}</span>
|
||
</template>
|
||
|
||
<template #column-logistics_name="{ row }">
|
||
<span>{{ row.logistics_name || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-creator="{ row }">
|
||
<span>{{ row.creator || row.creator_name || '—' }}</span>
|
||
</template>
|
||
|
||
<template #column-create_time="{ row }">
|
||
{{ formatDateTime(row.create_time || row.created_at || row.create_at) }}
|
||
</template>
|
||
|
||
<template #column-update_time="{ row }">
|
||
{{ formatDateTime(row.update_time || row.updated_at || row.update_at) }}
|
||
</template>
|
||
|
||
<template #column-operation="{ row }">
|
||
<el-button link type="primary" size="small" @click.stop="openPendingOrdersByWave(row)">处理订单</el-button>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ waveUpperTableDefaults.emptyText }}</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
<div v-if="selectedRow" class="lower-level" :class="tableSize" :style="lowerPaneStyle">
|
||
<div class="detail-header">
|
||
<span class="detail-title">波次详情</span>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<el-descriptions :column="2" border size="small">
|
||
<el-descriptions-item label="波次编号">{{ getWaveCode(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="波次类型">{{ getWaveTypeText(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag size="small" :type="getStatusTagType(selectedRow)">{{ getStatusText(selectedRow) }}</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="订单数量">{{ getOrderCount(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="已处理订单">{{ getProcessedOrders(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="仓库ID">{{ selectedRow.warehouse_id ?? '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="快递">{{ selectedRow.logistics_name || '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="库位分配状态">{{ getStorageAssignmentStatusText(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="快递分配状态">{{ selectedRow.express_assignment_status || '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="创建人">{{ selectedRow.creator || selectedRow.creator_name || '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="商品结构快照" :span="2">{{ getItemSnapshotText(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="订单信息" :span="2">{{ getOrderInfoSummary(selectedRow) }}</el-descriptions-item>
|
||
<el-descriptions-item label="创建时间">{{ formatDateTime(selectedRow.create_time || selectedRow.created_at || selectedRow.create_at) }}</el-descriptions-item>
|
||
<el-descriptions-item label="更新时间">{{ formatDateTime(selectedRow.update_time || selectedRow.updated_at || selectedRow.update_at) }}</el-descriptions-item>
|
||
<el-descriptions-item label="订单列表" :span="2">{{ getOrderListPreview(selectedRow) }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<el-dialog
|
||
v-model="pendingOrderDialogVisible"
|
||
:title="pendingOrderDialogTitle"
|
||
width="92vw"
|
||
top="4vh"
|
||
destroy-on-close
|
||
append-to-body
|
||
align-center
|
||
@closed="handlePendingOrderDialogClosed"
|
||
>
|
||
<pending-order-list-panel v-if="pendingOrderDialogVisible && pendingOrderDialogWaveNo" :wave-no="pendingOrderDialogWaveNo" />
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="groupOrderDialogVisible"
|
||
title="抓取团购单"
|
||
width="1280px"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
>
|
||
<div class="group-order-dialog">
|
||
<el-form :inline="true" size="small" class="group-order-filters">
|
||
<el-form-item label="货主">
|
||
<el-select
|
||
v-model="groupOrderFilters.storeId"
|
||
placeholder="全部"
|
||
clearable
|
||
filterable
|
||
style="width: 180px"
|
||
@change="handleGroupOrderFilterChange"
|
||
>
|
||
<el-option
|
||
v-for="store in groupOrderStoreOptions"
|
||
:key="String(store.value)"
|
||
:label="store.label"
|
||
:value="store.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="最小同组订单数">
|
||
<el-input-number
|
||
v-model="groupOrderFilters.sameOrderQuantity"
|
||
:min="1"
|
||
:controls="false"
|
||
style="width: 150px"
|
||
@change="handleGroupOrderFilterChange"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="店铺名称">
|
||
<el-input
|
||
v-model="groupOrderFilters.shopName"
|
||
clearable
|
||
placeholder="模糊匹配店铺名称"
|
||
style="width: 180px"
|
||
@keyup.enter="fetchGroupOrderList"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="包含 SKU">
|
||
<el-input
|
||
v-model="groupOrderFilters.includeSku"
|
||
clearable
|
||
placeholder="仅保留包含该 SKU 的分组"
|
||
style="width: 180px"
|
||
@keyup.enter="fetchGroupOrderList"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-switch
|
||
v-model="groupOrderFilters.distinguishExpress"
|
||
active-text="区分快递"
|
||
inactive-text="不区分快递"
|
||
@change="handleGroupOrderFilterChange"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" :loading="groupOrderListLoading" @click="fetchGroupOrderList">查询</el-button>
|
||
<el-button @click="resetGroupOrderFilters">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<div class="group-order-toolbar">
|
||
<div class="group-order-toolbar__left">
|
||
<span>已选 {{ groupOrderSelectionRows.length }} 个结构</span>
|
||
</div>
|
||
<el-checkbox v-model="groupOrderFilters.returnOrderIds">返回订单 ID 列表</el-checkbox>
|
||
</div>
|
||
|
||
<el-table
|
||
ref="groupOrderTableRef"
|
||
:data="groupOrderList"
|
||
v-loading="groupOrderListLoading"
|
||
border
|
||
size="small"
|
||
row-key="item_detail_machine"
|
||
max-height="460"
|
||
@selection-change="handleGroupOrderSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="48" reserve-selection />
|
||
<el-table-column prop="item_detail" label="商品结构" min-width="260" show-overflow-tooltip />
|
||
<el-table-column prop="logistics_name" label="快递" min-width="130" show-overflow-tooltip />
|
||
<el-table-column prop="group_count" label="同组订单数" min-width="100" align="right" />
|
||
<el-table-column prop="items_total" label="商品总数" min-width="100" align="right" />
|
||
<el-table-column label="货主" min-width="110">
|
||
<template #default="{ row }">
|
||
{{ getGroupOrderStoreText(row) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态汇总" min-width="240">
|
||
<template #default="{ row }">
|
||
<span class="status-summary-text">{{ getGroupOrderStatusSummary(row) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品快照" min-width="280">
|
||
<template #default="{ row }">
|
||
<span class="order-info-text">{{ getGroupOrderItemSnapshotText(row) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="抓取数量" width="120" align="center">
|
||
<template #default="{ row }">
|
||
<el-input-number
|
||
:model-value="groupOrderQuantityMap[row.item_detail_machine]"
|
||
:min="1"
|
||
:controls="false"
|
||
placeholder="默认"
|
||
style="width: 92px"
|
||
@change="(value: number | undefined) => updateGroupOrderQuantity(row, value)"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="首单时间" min-width="168">
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.first_order_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="末单时间" min-width="168">
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.last_order_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无可抓取的团购单结构</div>
|
||
</template>
|
||
</el-table>
|
||
|
||
<div class="group-order-pagination">
|
||
<el-pagination
|
||
v-model:current-page="groupOrderPagination.currentPage"
|
||
v-model:page-size="groupOrderPagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:total="groupOrderPagination.total"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
background
|
||
size="small"
|
||
@size-change="handleGroupOrderPageSizeChange"
|
||
@current-change="handleGroupOrderPageChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<template #footer>
|
||
<el-button size="small" @click="groupOrderDialogVisible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="groupOrderSubmitting" @click="submitGroupOrderDialog">抓取选中结构</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="singleOrderDialogVisible"
|
||
title="删单抓取"
|
||
width="1280px"
|
||
class="single-fetch-dialog"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
>
|
||
<el-tabs v-model="singleOrderActiveTab" class="single-order-tabs">
|
||
<el-tab-pane label="不符合波次策略订单列表" name="fallback-orders">
|
||
<div class="single-fallback-layout">
|
||
<scan-box
|
||
ref="fallbackOrderScanBox"
|
||
width="300px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:available-fields="fallbackOrderAvailableFieldsRef"
|
||
@condition-change="handleFallbackOrderConditionChange"
|
||
@condition-clear="handleFallbackOrderConditionClear"
|
||
@reset="handleFallbackOrderConditionReset"
|
||
/>
|
||
|
||
<div class="single-fallback-main">
|
||
<div class="group-order-toolbar">
|
||
<div class="group-order-toolbar__left">
|
||
<span>已选 {{ fallbackOrderSelectionRows.length }} 个订单</span>
|
||
</div>
|
||
<div>
|
||
<el-button type="primary" size="small" :loading="fallbackOrderListLoading" @click="fetchFallbackOrderList">查询</el-button>
|
||
<el-button size="small" @click="resetFallbackOrderCondition">重置</el-button>
|
||
<el-button type="warning" size="small" :loading="singleOrderSubmitting" :disabled="!fallbackOrderSelectionRows.length" @click="submitFallbackOrderFetchByIds">按订单IDs抓取删单</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<el-table
|
||
ref="singleOrderTableRef"
|
||
:data="fallbackOrderList"
|
||
v-loading="fallbackOrderListLoading"
|
||
border
|
||
size="small"
|
||
row-key="id"
|
||
max-height="500"
|
||
@selection-change="handleFallbackOrderSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="48" reserve-selection />
|
||
<el-table-column prop="id" label="订单ID" min-width="100" />
|
||
<el-table-column prop="delivery_order_code" label="订单号" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="shop_name" label="店铺" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="sys_platform_name" label="平台" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="logistics_name" label="快递" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="wave_scan_result" label="扫描结果" min-width="110" align="center" />
|
||
<el-table-column label="更新时间" min-width="170">
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.updated_at || row.update_time || row.updated_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无不符合波次策略订单</div>
|
||
</template>
|
||
</el-table>
|
||
|
||
<div class="group-order-pagination">
|
||
<el-pagination
|
||
v-model:current-page="fallbackOrderPagination.currentPage"
|
||
v-model:page-size="fallbackOrderPagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:total="fallbackOrderPagination.total"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
background
|
||
size="small"
|
||
@size-change="handleFallbackOrderPageSizeChange"
|
||
@current-change="handleFallbackOrderPageChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</el-tab-pane>
|
||
|
||
<el-tab-pane label="波次策略(待开发)" name="strategy-api">
|
||
<el-empty description="波次策略接口页签暂未接入" />
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="singleOrderDialogVisible = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<wave-fetch-task-progress-dialog
|
||
:model-value="Boolean(fetchTaskProgress.taskId)"
|
||
:progress="fetchTaskProgress"
|
||
/>
|
||
|
||
<wave-batch-print-preview-dialog
|
||
v-model="wavePrintDialogVisible"
|
||
:loading="wavePrintDialogLoading"
|
||
:error-message="wavePrintDialogError"
|
||
:payload="wavePrintDialogPayload"
|
||
:request-meta="wavePrintRequestMeta"
|
||
align-center
|
||
/>
|
||
</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 { pendingAvailableFields } from '@/views/order/orderManagement/config/order-common-config'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import {
|
||
waveScanBoxConfig,
|
||
waveUpperTableDefaults,
|
||
waveAvailableFields,
|
||
waveBatchColumns,
|
||
waveWhereAllowedFields,
|
||
getWaveToolbarButtons
|
||
} from './config/wave-config'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import PendingOrderListPanel from './component/PendingOrderListPanel.vue'
|
||
import WaveFetchTaskProgressDialog from './component/WaveFetchTaskProgressDialog.vue'
|
||
import * as indexApi from '@/api/index/index'
|
||
import { settingWarehouseGetSettings as getWarehouseSettings } from '@/api/setting.warehouse/settingwarehouse'
|
||
import {
|
||
orderWaveBatchAllocateExpress,
|
||
orderWaveBatchAllocateExpressTaskProgress,
|
||
orderWaveBatchAllocateStorage,
|
||
orderWaveBatchAllocateStorageTaskProgress,
|
||
orderWaveBatchAutoGrouping,
|
||
orderWaveBatchCancel,
|
||
orderWaveBatchCancelTaskProgress,
|
||
orderWaveBatchFinishAutoGrouping,
|
||
orderWaveBatchRemoveExceptionOrders,
|
||
orderWaveBatchRemoveExceptionOrdersTaskProgress,
|
||
orderWaveBatchList,
|
||
orderWaveFetch,
|
||
orderWaveGroupFetch,
|
||
orderWaveSingleFetchByIds,
|
||
orderWaveWaveStrategyFallbackOrderList,
|
||
orderWaveFetchTaskProgress,
|
||
orderWaveGroupOrderFetchList
|
||
} from '@/api/order.wave/orderwave'
|
||
import type {
|
||
WaveBatchAllocateExpressTaskProgressResponse,
|
||
WaveBatchAllocateStorageTaskProgressResponse,
|
||
WaveBatchCancelTaskProgressResponse,
|
||
WaveBatchRemoveExceptionOrdersTaskProgressResponse,
|
||
WaveFetchParams,
|
||
WaveFetchResponse,
|
||
WaveFetchTaskProgressResponse
|
||
} from '@/api/order.wave/orderwave'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import { getWavePrintData } from '@/api/order.print/orderprint'
|
||
import type { WavePrintDataPayload } from '@/api/order.print/orderprint'
|
||
import WaveBatchPrintPreviewDialog from './component/WaveBatchPrintPreviewDialog.vue'
|
||
const props = defineProps<{
|
||
/** 1 团购波次,2 散单波次 */
|
||
waveType: 1 | 2
|
||
}>()
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const groupOrderTableRef = ref<any>(null)
|
||
const singleOrderTableRef = ref<any>(null)
|
||
const scrollContainerRef = ref<HTMLElement | null>(null)
|
||
const loading = ref(false)
|
||
const batchAutoGroupingLoading = ref(false)
|
||
const batchFinishAutoGroupingLoading = ref(false)
|
||
const batchCancelLoading = ref(false)
|
||
const batchPrintLoading = ref(false)
|
||
const batchAllocateExpressLoading = ref(false)
|
||
const batchAllocateStorageLoading = ref(false)
|
||
const batchRemoveExceptionOrdersLoading = ref(false)
|
||
const userStore = useUserStore()
|
||
const wavePrintDialogVisible = ref(false)
|
||
const wavePrintDialogLoading = ref(false)
|
||
const wavePrintDialogError = ref('')
|
||
const wavePrintDialogPayload = ref<WavePrintDataPayload | null>(null)
|
||
const wavePrintRequestMeta = ref<{ warehouse_id: number; wave_ids: Array<number | string> } | null>(null)
|
||
const queryTime = ref(0)
|
||
const tableSize = ref('small')
|
||
const list = ref<any[]>([])
|
||
const selectedRow = ref<any>(null)
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const groupOrderDialogVisible = ref(false)
|
||
const groupOrderListLoading = ref(false)
|
||
const groupOrderSubmitting = ref(false)
|
||
const groupOrderList = ref<any[]>([])
|
||
const groupOrderSelectionRows = ref<any[]>([])
|
||
const groupOrderStoreOptions = ref<Array<{ label: string; value: number | string }>>([])
|
||
const waveMaxOrderLimit = ref<number | null>(null)
|
||
const fetchTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
const batchAllocateExpressTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
const batchAllocateStorageTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
const batchRemoveExceptionOrdersTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
const batchCancelTaskPollTimer = ref<ReturnType<typeof setTimeout> | null>(null)
|
||
const pendingOrderDialogVisible = ref(false)
|
||
const pendingOrderDialogWaveNo = ref('')
|
||
const fetchTaskProgress = reactive({
|
||
taskId: '',
|
||
status: 'submitted',
|
||
warehouseId: undefined as number | undefined,
|
||
structureCount: 0,
|
||
finishedStructureCount: 0,
|
||
progressPercent: 0,
|
||
totalFetchedQuantity: 0,
|
||
durationMs: 0,
|
||
error: '',
|
||
updateTime: '',
|
||
message: ''
|
||
})
|
||
const batchAllocateExpressTaskProgress = reactive({
|
||
taskId: '',
|
||
status: 'submitted',
|
||
totalCount: 0,
|
||
successCount: 0,
|
||
failedCount: 0,
|
||
progressPercent: 0,
|
||
durationMs: 0,
|
||
updateTime: '',
|
||
error: '',
|
||
message: ''
|
||
})
|
||
const batchAllocateStorageTaskProgress = reactive({
|
||
taskId: '',
|
||
status: 'submitted',
|
||
totalCount: 0,
|
||
successCount: 0,
|
||
failedCount: 0,
|
||
progressPercent: 0,
|
||
durationMs: 0,
|
||
updateTime: '',
|
||
error: '',
|
||
message: ''
|
||
})
|
||
const batchRemoveExceptionOrdersTaskProgress = reactive({
|
||
taskId: '',
|
||
status: 'submitted',
|
||
totalCount: 0,
|
||
successCount: 0,
|
||
failedCount: 0,
|
||
progressPercent: 0,
|
||
durationMs: 0,
|
||
updateTime: '',
|
||
error: '',
|
||
message: ''
|
||
})
|
||
const batchCancelTaskProgress = reactive({
|
||
taskId: '',
|
||
status: 'submitted',
|
||
totalCount: 0,
|
||
successCount: 0,
|
||
failedCount: 0,
|
||
progressPercent: 0,
|
||
durationMs: 0,
|
||
updateTime: '',
|
||
error: '',
|
||
message: ''
|
||
})
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
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 fallbackOrderScanBox = ref<any>(null)
|
||
const fallbackOrderListLoading = ref(false)
|
||
const fallbackOrderList = ref<any[]>([])
|
||
const fallbackOrderSelectionRows = ref<any[]>([])
|
||
const fallbackOrderPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(waveAvailableFields)))
|
||
const fallbackOrderAvailableFieldsRef = reactive(JSON.parse(JSON.stringify(pendingAvailableFields)))
|
||
const columns = ref(JSON.parse(JSON.stringify(waveBatchColumns)))
|
||
|
||
const toolbarButtons = computed(() => getWaveToolbarButtons(props.waveType))
|
||
|
||
const detailVisible = ref(true)
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
|
||
defaultLowerPercent: 38
|
||
})
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
const isDragging = ref(false)
|
||
const startX = ref(0)
|
||
const scrollLeft = ref(0)
|
||
|
||
const handleToolbarWheel = (e: WheelEvent) => {
|
||
if (scrollContainerRef.value) {
|
||
e.preventDefault()
|
||
scrollContainerRef.value.scrollLeft += e.deltaY
|
||
}
|
||
}
|
||
|
||
const handleMouseDown = (e: MouseEvent) => {
|
||
if (!scrollContainerRef.value) return
|
||
isDragging.value = true
|
||
startX.value = e.pageX - scrollContainerRef.value.offsetLeft
|
||
scrollLeft.value = scrollContainerRef.value.scrollLeft
|
||
}
|
||
|
||
const handleMouseMove = (e: MouseEvent) => {
|
||
if (!isDragging.value || !scrollContainerRef.value) return
|
||
e.preventDefault()
|
||
const x = e.pageX - scrollContainerRef.value.offsetLeft
|
||
const walk = (x - startX.value) * 1.5
|
||
scrollContainerRef.value.scrollLeft = scrollLeft.value - walk
|
||
}
|
||
|
||
const handleMouseUp = () => {
|
||
isDragging.value = false
|
||
}
|
||
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value,
|
||
batchAutoGroupingLoading: batchAutoGroupingLoading.value,
|
||
batchFinishAutoGroupingLoading: batchFinishAutoGroupingLoading.value,
|
||
batchCancelLoading: batchCancelLoading.value,
|
||
batchPrintLoading: batchPrintLoading.value,
|
||
batchAllocateExpressLoading: batchAllocateExpressLoading.value,
|
||
batchAllocateStorageLoading: batchAllocateStorageLoading.value,
|
||
batchRemoveExceptionOrdersLoading: batchRemoveExceptionOrdersLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
batchPrintDisabled: batchPrintDisabled.value,
|
||
noSelection: !hasSelection.value
|
||
}))
|
||
|
||
const buttonLabelMap = computed(() => ({
|
||
batchPrintTotal: `批量打印(${selectedWaveOrderTotal.value})`,
|
||
detailToggleLabel: detailVisible.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, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => {
|
||
void loadData()
|
||
},
|
||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||
toggleDetailVisible: () => toggleDetailVisible(),
|
||
handleBatchPrint: () => handleBatchPrint(),
|
||
handleBatchAutoGrouping: () => {
|
||
void handleBatchAutoGrouping()
|
||
},
|
||
handleBatchFinishAutoGrouping: () => {
|
||
void handleBatchFinishAutoGrouping()
|
||
},
|
||
handleBatchCancel: () => {
|
||
void handleBatchCancel()
|
||
},
|
||
handleBatchAllocateExpress: () => {
|
||
void handleBatchAllocateExpress()
|
||
},
|
||
handleBatchAllocateStorage: () => {
|
||
void handleBatchAllocateStorage()
|
||
},
|
||
handleBatchRemoveExceptionOrders: () => {
|
||
void handleBatchRemoveExceptionOrders()
|
||
},
|
||
openGroupOrderDialog: () => openGroupOrderDialog(),
|
||
openSingleOrderDialog: () => openSingleOrderDialog()
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const groupOrderFilters = reactive({
|
||
distinguishExpress: true,
|
||
storeId: undefined as number | string | undefined,
|
||
sameOrderQuantity: undefined as number | undefined,
|
||
shopName: '',
|
||
includeSku: '',
|
||
returnOrderIds: false
|
||
})
|
||
const groupOrderQuantityMap = reactive<Record<string, number | undefined>>({})
|
||
const isGroupWaveTab = computed(() => props.waveType === 1)
|
||
const currentWaveType = computed(() => props.waveType)
|
||
const tableListId = computed(() => `wave-management-list-${props.waveType}`)
|
||
|
||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||
const printableSelectionRows = computed(() => selectionRows.value.filter((row: any) => !isAutoGroupingWave(row)))
|
||
const autoGroupingSelectionRows = computed(() => selectionRows.value.filter((row: any) => isAutoGroupingWave(row)))
|
||
const selectedWaveOrderTotal = computed(() => {
|
||
return printableSelectionRows.value.reduce((total: number, row: any) => total + Number(getOrderCount(row) || 0), 0)
|
||
})
|
||
const batchPrintDisabled = computed(() => {
|
||
return !printableSelectionRows.value.length || (waveMaxOrderLimit.value !== null && selectedWaveOrderTotal.value > waveMaxOrderLimit.value)
|
||
})
|
||
const batchAllocateExpressTaskPercent = computed(() => {
|
||
const value = Number(batchAllocateExpressTaskProgress.progressPercent || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, value))
|
||
})
|
||
const batchAllocateExpressTaskProgressBarStatus = computed(() => {
|
||
if (batchAllocateExpressTaskProgress.status === 'failed' || batchAllocateExpressTaskProgress.status === 'not_found') return 'exception'
|
||
if (batchAllocateExpressTaskProgress.status === 'success' || batchAllocateExpressTaskPercent.value >= 100) return 'success'
|
||
return undefined
|
||
})
|
||
const batchAllocateStorageTaskPercent = computed(() => {
|
||
const value = Number(batchAllocateStorageTaskProgress.progressPercent || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, value))
|
||
})
|
||
const batchAllocateStorageTaskProgressBarStatus = computed(() => {
|
||
if (batchAllocateStorageTaskProgress.status === 'failed' || batchAllocateStorageTaskProgress.status === 'not_found') return 'exception'
|
||
if (batchAllocateStorageTaskProgress.status === 'success' || batchAllocateStorageTaskPercent.value >= 100) return 'success'
|
||
return undefined
|
||
})
|
||
const batchRemoveExceptionOrdersTaskPercent = computed(() => {
|
||
const value = Number(batchRemoveExceptionOrdersTaskProgress.progressPercent || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, value))
|
||
})
|
||
const batchRemoveExceptionOrdersTaskProgressBarStatus = computed(() => {
|
||
if (batchRemoveExceptionOrdersTaskProgress.status === 'failed' || batchRemoveExceptionOrdersTaskProgress.status === 'not_found') return 'exception'
|
||
if (batchRemoveExceptionOrdersTaskProgress.status === 'success' || batchRemoveExceptionOrdersTaskPercent.value >= 100) return 'success'
|
||
return undefined
|
||
})
|
||
const batchCancelTaskPercent = computed(() => {
|
||
const value = Number(batchCancelTaskProgress.progressPercent || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, value))
|
||
})
|
||
const batchCancelTaskProgressBarStatus = computed(() => {
|
||
if (batchCancelTaskProgress.status === 'failed' || batchCancelTaskProgress.status === 'not_found') return 'exception'
|
||
if (batchCancelTaskProgress.status === 'success' || batchCancelTaskPercent.value >= 100) return 'success'
|
||
return undefined
|
||
})
|
||
const pendingOrderDialogTitle = computed(() => pendingOrderDialogWaveNo.value ? `待处理订单 - ${pendingOrderDialogWaveNo.value}` : '待处理订单')
|
||
|
||
onMounted(() => {
|
||
initializePage()
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
stopFetchTaskPolling()
|
||
stopBatchAllocateExpressTaskPolling()
|
||
stopBatchAllocateStorageTaskPolling()
|
||
stopBatchRemoveExceptionOrdersTaskPolling()
|
||
stopBatchCancelTaskPolling()
|
||
})
|
||
|
||
async function initializePage() {
|
||
await Promise.all([loadWarehouseSettings(), loadData()])
|
||
}
|
||
|
||
async function loadWarehouseSettings() {
|
||
try {
|
||
const res: any = await getWarehouseSettings()
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '获取仓库配置失败')
|
||
}
|
||
const maxWaveQuantity = Number(res?.subject_config?.max_wave_quantity)
|
||
waveMaxOrderLimit.value = Number.isFinite(maxWaveQuantity) && maxWaveQuantity > 0 ? maxWaveQuantity : null
|
||
} catch (error) {
|
||
console.error('load warehouse settings failed:', error)
|
||
waveMaxOrderLimit.value = null
|
||
}
|
||
}
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = sanitizeWaveWhere(buildWhereConditions(scanBox.value?.getConditions?.() || {}))
|
||
where.wave_type = currentWaveType.value
|
||
const res: any = await orderWaveBatchList({
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where
|
||
})
|
||
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
|
||
|
||
syncSelectionRows()
|
||
syncSelectedRow()
|
||
} catch (error: any) {
|
||
console.error('load wave batch list failed:', error)
|
||
ElMessage.error(error?.message || '获取波次列表失败')
|
||
list.value = []
|
||
pagination.total = 0
|
||
selectedRow.value = null
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
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 sanitizeWaveWhere(where: Record<string, any>) {
|
||
const nextWhere: Record<string, any> = {}
|
||
Object.keys(where || {}).forEach((key) => {
|
||
if (!waveWhereAllowedFields.has(key)) return
|
||
if (key === 'warehouse_id' || key === 'warehouseId') return
|
||
const value = where[key]
|
||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) return
|
||
nextWhere[key] = value
|
||
})
|
||
return nextWhere
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
loadData()
|
||
}
|
||
|
||
function handleRowClick(row: any) {
|
||
selectedRow.value = row || null
|
||
}
|
||
|
||
function handleSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
hasSelection.value = selectionRows.value.length > 0
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
function syncSelectionRows() {
|
||
if (!selectionRows.value.length) return
|
||
const selectedIds = new Set(selectionRows.value.map((row: any) => getRowIdentity(row)))
|
||
selectionRows.value = list.value.filter((row: any) => selectedIds.has(getRowIdentity(row)))
|
||
hasSelection.value = selectionRows.value.length > 0
|
||
}
|
||
|
||
function syncSelectedRow() {
|
||
if (!selectedRow.value) return
|
||
const currentId = getRowIdentity(selectedRow.value)
|
||
selectedRow.value = list.value.find((item: any) => getRowIdentity(item) === currentId) || null
|
||
}
|
||
|
||
function getRowIdentity(row: any) {
|
||
return String(row?.id || row?.wave_id || row?.batch_id || row?.wave_code || row?.batch_code || '')
|
||
}
|
||
|
||
function getWaveCode(row: any) {
|
||
return row?.wave_code || row?.batch_code || row?.wave_no || row?.batch_no || row?.code || row?.id || '—'
|
||
}
|
||
|
||
function openPendingOrdersByWave(row: any) {
|
||
const waveNo = String(row?.wave_no || '').trim()
|
||
if (!waveNo) {
|
||
ElMessage.warning('当前波次缺少波次号,无法跳转待处理订单页')
|
||
return
|
||
}
|
||
|
||
pendingOrderDialogWaveNo.value = waveNo
|
||
pendingOrderDialogVisible.value = true
|
||
}
|
||
|
||
function handlePendingOrderDialogClosed() {
|
||
pendingOrderDialogWaveNo.value = ''
|
||
loadData()
|
||
}
|
||
|
||
function getFetchTaskStatusText(status: string) {
|
||
const map: Record<string, string> = {
|
||
submitted: '已受理',
|
||
running: '进行中',
|
||
success: '成功',
|
||
failed: '失败',
|
||
not_found: '未找到'
|
||
}
|
||
return map[status] || status || '—'
|
||
}
|
||
|
||
function getStatusValue(row: any) {
|
||
return row?.status ?? row?.wave_status ?? row?.batch_status
|
||
}
|
||
|
||
function isAutoGroupingWave(row: any) {
|
||
const value = String(getStatusValue(row) ?? '').trim().toLowerCase()
|
||
return value === '0' || value === 'pending'
|
||
}
|
||
|
||
function getStatusText(row: any) {
|
||
const value = getStatusValue(row)
|
||
const map: Record<string, string> = {
|
||
'-1': '已取消',
|
||
'0': '自动加团中',
|
||
'1': '已就绪',
|
||
'2': '已打印',
|
||
'3': '拣货中',
|
||
'4': '拣货完成',
|
||
'5': '复核完成',
|
||
'6': '打包完成',
|
||
cancelled: '已取消',
|
||
pending: '自动加团中',
|
||
assigned: '已就绪'
|
||
}
|
||
return map[String(value)] || (value ?? '—')
|
||
}
|
||
|
||
function getStatusTagType(row: any) {
|
||
const value = String(getStatusValue(row) ?? '')
|
||
if (value === '-1' || value === 'cancelled') return 'danger'
|
||
if (value === '0' || value === 'pending') return 'warning'
|
||
if (value === '1' || value === '2' || value === 'assigned') return 'success'
|
||
if (value === '3' || value === '4') return 'primary'
|
||
if (value === '5' || value === '6') return 'info'
|
||
return 'info'
|
||
}
|
||
|
||
function getWaveTypeText(row: any) {
|
||
const value = String(row?.wave_type ?? '')
|
||
const map: Record<string, string> = {
|
||
'1': '团购',
|
||
'2': '散单'
|
||
}
|
||
return map[value] || (value || '—')
|
||
}
|
||
|
||
function getOrderCount(row: any) {
|
||
return row?.order_count ?? row?.total_orders ?? row?.total_order_count ?? row?.orders_count ?? row?.count ?? 0
|
||
}
|
||
|
||
function getProcessedOrders(row: any) {
|
||
return row?.processed_orders ?? row?.done_orders ?? 0
|
||
}
|
||
|
||
function getStorageAssignmentStatusText(row: any) {
|
||
const rawValue = row?.storage_assignment_status
|
||
const text = String(rawValue ?? '').trim()
|
||
if (!text) return '—'
|
||
|
||
const normalized = text.toLowerCase()
|
||
const exactMap: Record<string, string> = {
|
||
none: '未分配',
|
||
no_error: '未分配',
|
||
pending: '处理中',
|
||
padding: '处理中',
|
||
processing: '处理中',
|
||
running: '处理中',
|
||
success: '已分配',
|
||
succeeded: '已分配',
|
||
fin: '已分配',
|
||
finished: '已分配',
|
||
done: '已分配',
|
||
completed: '已分配',
|
||
partial: '部分分配',
|
||
partial_failed: '部分分配',
|
||
error: '分配异常',
|
||
failed: '分配异常',
|
||
exception: '分配异常',
|
||
timeout: '处理超时',
|
||
not_found: '未找到'
|
||
}
|
||
|
||
if (exactMap[normalized] !== undefined) {
|
||
return exactMap[normalized]
|
||
}
|
||
|
||
return text
|
||
}
|
||
|
||
function translateStorageAssignmentErrorValue(value: unknown) {
|
||
const text = String(value ?? '').trim()
|
||
if (!text) return '—'
|
||
|
||
const normalized = text.toLowerCase()
|
||
const exactMap: Record<string, string> = {
|
||
none: '无',
|
||
no_error: '无',
|
||
no_exception: '无',
|
||
success: '无',
|
||
succeeded: '无',
|
||
fin: '无',
|
||
finished: '无',
|
||
done: '无',
|
||
completed: '无',
|
||
pending: '处理中',
|
||
padding: '处理中',
|
||
processing: '处理中',
|
||
running: '处理中',
|
||
error: '分配异常',
|
||
failed: '分配失败',
|
||
exception: '分配异常',
|
||
timeout: '处理超时',
|
||
not_found: '未找到',
|
||
partial: '部分异常',
|
||
partial_failed: '部分异常'
|
||
}
|
||
|
||
if (exactMap[normalized] !== undefined) {
|
||
return exactMap[normalized]
|
||
}
|
||
|
||
if (/[\u4e00-\u9fa5]/.test(text)) {
|
||
return text
|
||
}
|
||
|
||
const phraseMap: Array<[RegExp, string]> = [
|
||
[/storage assignment/gi, '库位分配'],
|
||
[/assignment/gi, '分配'],
|
||
[/storage/gi, '库位'],
|
||
[/error/gi, '异常'],
|
||
[/failed/gi, '失败'],
|
||
[/exception/gi, '异常'],
|
||
[/timeout/gi, '超时'],
|
||
[/pending|padding|processing|running/gi, '处理中'],
|
||
[/partial/gi, '部分'],
|
||
[/not found/gi, '未找到'],
|
||
[/none|success|succeeded|finished|completed|done|fin/gi, '无']
|
||
]
|
||
|
||
let translated = text.replace(/[_-]+/g, ' ')
|
||
for (const [pattern, replacement] of phraseMap) {
|
||
translated = translated.replace(pattern, replacement)
|
||
}
|
||
|
||
translated = translated.replace(/\s+/g, ' ').trim()
|
||
return translated || text
|
||
}
|
||
|
||
function getStorageAssignmentError(row: any) {
|
||
return translateStorageAssignmentErrorValue(
|
||
row?.storage_assignment_error
|
||
|| row?.storage_assignment_exception
|
||
|| row?.storage_assignment_error_message
|
||
|| row?.storage_error
|
||
|| row?.storage_error_message
|
||
|| '—'
|
||
)
|
||
}
|
||
|
||
function getItemSnapshotText(row: any) {
|
||
return row?.item_snapshot_key || row?.item_detail_machine || row?.item_detail || '—'
|
||
}
|
||
|
||
function getOrderInfoSummary(row: any) {
|
||
if (Array.isArray(row?.order_list) && row.order_list.length) {
|
||
const preview = row.order_list
|
||
.slice(0, 6)
|
||
.map((item: any) => item.delivery_order_code || item.order_no || item.order_number || item.id)
|
||
.filter(Boolean)
|
||
return row.order_list.length > 6 ? `${preview.join(',')} 等 ${row.order_list.length} 单` : preview.join(',')
|
||
}
|
||
const info = row?.order_info || row?.order_summary || row?.orders_summary
|
||
if (typeof info === 'string' && info.trim()) return info
|
||
if (Array.isArray(info) && info.length) return info.join(',')
|
||
if (Array.isArray(row?.orders) && row.orders.length) {
|
||
return row.orders.map((item: any) => item.order_sn || item.order_no || item.order_number || item.id).filter(Boolean).join(',')
|
||
}
|
||
return '—'
|
||
}
|
||
|
||
function getOrderListPreview(row: any) {
|
||
if (!Array.isArray(row?.order_list) || row.order_list.length === 0) {
|
||
return '—'
|
||
}
|
||
return row.order_list
|
||
.map((item: any) => {
|
||
const code = item.delivery_order_code || item.order_no || item.order_number || item.id
|
||
const storage = item.storage_status || '—'
|
||
const post = item.post_status || '—'
|
||
return `${code}(库位:${storage}, 快递:${post})`
|
||
})
|
||
.join(';')
|
||
}
|
||
|
||
function getAssignmentTagType(value: string | undefined) {
|
||
const text = String(value || '')
|
||
if (text.includes('异常') || text.includes('失败') || text.includes('超时')) return 'danger'
|
||
if (text.includes('处理中')) return 'warning'
|
||
if (text.includes('已分配') || text.includes('完成')) return 'success'
|
||
if (text.includes('部分')) return 'warning'
|
||
if (text.includes('未分配')) return 'info'
|
||
return 'info'
|
||
}
|
||
|
||
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 getSelectedWaveIds() {
|
||
return selectionRows.value
|
||
.map((row: any) => row?.id ?? row?.wave_id ?? row?.batch_id)
|
||
.filter((id: unknown) => id !== undefined && id !== null && id !== '')
|
||
}
|
||
|
||
async function handleBatchAutoGrouping() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要修改的波次')
|
||
return
|
||
}
|
||
|
||
const ids = getSelectedWaveIds()
|
||
if (!ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要将 ${ids.length} 个波次批量修改为自动加团中吗?仅会作用当前登录仓库命中的波次。`,
|
||
'批量改为自动加团',
|
||
{ type: 'warning', confirmButtonText: '确认修改', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchAutoGroupingLoading.value = true
|
||
try {
|
||
const res: any = await orderWaveBatchAutoGrouping({ ids })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '批量修改自动加团状态失败')
|
||
}
|
||
ElMessage.success(res?.message || '批量修改为自动加团成功')
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
await loadData()
|
||
} catch (error: any) {
|
||
console.error('batch auto grouping wave failed:', error)
|
||
ElMessage.error(error?.message || '批量修改自动加团状态失败')
|
||
} finally {
|
||
batchAutoGroupingLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleBatchFinishAutoGrouping() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要结束自动加团的波次')
|
||
return
|
||
}
|
||
|
||
const ids = getSelectedWaveIds()
|
||
if (!ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要将 ${ids.length} 个波次批量结束自动加团吗?仅会作用当前登录仓库命中且处于自动加团中的波次。`,
|
||
'批量结束自动加团',
|
||
{ type: 'warning', confirmButtonText: '确认结束', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchFinishAutoGroupingLoading.value = true
|
||
try {
|
||
const res: any = await orderWaveBatchFinishAutoGrouping({ ids })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '批量结束自动加团失败')
|
||
}
|
||
ElMessage.success(res?.message || '批量结束自动加团成功')
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
await loadData()
|
||
} catch (error: any) {
|
||
console.error('batch finish auto grouping wave failed:', error)
|
||
ElMessage.error(error?.message || '批量结束自动加团失败')
|
||
} finally {
|
||
batchFinishAutoGroupingLoading.value = false
|
||
}
|
||
}
|
||
|
||
function unwrapWavePrintPayload(res: any): WavePrintDataPayload {
|
||
const inner =
|
||
res?.data !== undefined && res?.data !== null && typeof res.data === 'object' && !Array.isArray(res.data)
|
||
? res.data
|
||
: res
|
||
const summaryRaw = inner?.summary
|
||
const summary =
|
||
summaryRaw !== undefined && summaryRaw !== null && typeof summaryRaw === 'object' && !Array.isArray(summaryRaw)
|
||
? (summaryRaw as Record<string, unknown>)
|
||
: {}
|
||
const waveListRaw = inner?.wave_list
|
||
const wave_list = Array.isArray(waveListRaw)
|
||
? (waveListRaw.filter((x) => x && typeof x === 'object') as Record<string, unknown>[])
|
||
: []
|
||
const extRaw = inner?.ext
|
||
const ext =
|
||
extRaw !== undefined && extRaw !== null && typeof extRaw === 'object' && !Array.isArray(extRaw)
|
||
? (extRaw as Record<string, unknown>)
|
||
: undefined
|
||
return { summary, wave_list, ext }
|
||
}
|
||
|
||
async function handleBatchPrint() {
|
||
if (!isGroupWaveTab.value) {
|
||
ElMessage.warning('批量打印仅在「团购波次」页签可用')
|
||
return
|
||
}
|
||
|
||
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} 个“自动加团中”波次,不计入批量打印`)
|
||
}
|
||
|
||
const rows = printableSelectionRows.value
|
||
const first = rows[0] as Record<string, unknown>
|
||
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
|
||
}
|
||
|
||
wavePrintRequestMeta.value = { warehouse_id: warehouseId, wave_ids }
|
||
wavePrintDialogPayload.value = null
|
||
wavePrintDialogError.value = ''
|
||
wavePrintDialogVisible.value = true
|
||
wavePrintDialogLoading.value = true
|
||
|
||
batchPrintLoading.value = true
|
||
try {
|
||
const res: any = await getWavePrintData({ warehouse_id: warehouseId, wave_ids })
|
||
wavePrintDialogPayload.value = unwrapWavePrintPayload(res)
|
||
const waveCount = wavePrintDialogPayload.value.wave_list?.length ?? 0
|
||
ElMessage.success(res?.message || `已获取打印数据,返回 ${waveCount} 个波次`)
|
||
} catch (error: any) {
|
||
wavePrintDialogError.value = error?.message || '获取波次打印数据失败'
|
||
wavePrintDialogPayload.value = null
|
||
} finally {
|
||
wavePrintDialogLoading.value = false
|
||
batchPrintLoading.value = false
|
||
}
|
||
}
|
||
|
||
function stopFetchTaskPolling() {
|
||
if (fetchTaskPollTimer.value) {
|
||
clearTimeout(fetchTaskPollTimer.value)
|
||
fetchTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleFetchTaskPolling(delay = 2000) {
|
||
stopFetchTaskPolling()
|
||
if (!fetchTaskProgress.taskId) return
|
||
fetchTaskPollTimer.value = setTimeout(() => {
|
||
void pollFetchTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyFetchTaskProgress(progress: Partial<WaveFetchTaskProgressResponse>) {
|
||
fetchTaskProgress.taskId = String(progress.task_id || fetchTaskProgress.taskId || '')
|
||
fetchTaskProgress.status = resolveAsyncTaskStatus(progress as Record<string, any>, fetchTaskProgress.status || 'submitted')
|
||
fetchTaskProgress.warehouseId = progress.warehouse_id
|
||
fetchTaskProgress.structureCount = Number(progress.structure_count ?? fetchTaskProgress.structureCount ?? 0)
|
||
fetchTaskProgress.finishedStructureCount = Number(progress.finished_structure_count ?? fetchTaskProgress.finishedStructureCount ?? 0)
|
||
fetchTaskProgress.progressPercent = Number(progress.progress_percent ?? fetchTaskProgress.progressPercent ?? 0)
|
||
fetchTaskProgress.totalFetchedQuantity = Number(progress.total_fetched_quantity ?? fetchTaskProgress.totalFetchedQuantity ?? 0)
|
||
fetchTaskProgress.durationMs = Number(progress.duration_ms ?? fetchTaskProgress.durationMs ?? 0)
|
||
fetchTaskProgress.error = String(progress.error || '')
|
||
fetchTaskProgress.updateTime = String(progress.update_time || '')
|
||
fetchTaskProgress.message = String(progress.message || '')
|
||
}
|
||
|
||
function resetFetchTaskProgress() {
|
||
fetchTaskProgress.taskId = ''
|
||
fetchTaskProgress.status = 'submitted'
|
||
fetchTaskProgress.warehouseId = undefined
|
||
fetchTaskProgress.structureCount = 0
|
||
fetchTaskProgress.finishedStructureCount = 0
|
||
fetchTaskProgress.progressPercent = 0
|
||
fetchTaskProgress.totalFetchedQuantity = 0
|
||
fetchTaskProgress.durationMs = 0
|
||
fetchTaskProgress.error = ''
|
||
fetchTaskProgress.updateTime = ''
|
||
fetchTaskProgress.message = ''
|
||
}
|
||
|
||
async function pollFetchTaskProgress() {
|
||
if (!fetchTaskProgress.taskId) return
|
||
try {
|
||
const res = await orderWaveFetchTaskProgress({ task_id: fetchTaskProgress.taskId }) as WaveFetchTaskProgressResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '获取抓取任务进度失败')
|
||
}
|
||
|
||
applyFetchTaskProgress(res)
|
||
|
||
if (fetchTaskProgress.status === 'failed' || fetchTaskProgress.status === 'not_found') {
|
||
stopFetchTaskPolling()
|
||
await loadData()
|
||
resetFetchTaskProgress()
|
||
return
|
||
}
|
||
|
||
if (fetchTaskProgress.status === 'success' || Number(fetchTaskProgress.progressPercent || 0) >= 100) {
|
||
stopFetchTaskPolling()
|
||
await loadData()
|
||
resetFetchTaskProgress()
|
||
return
|
||
}
|
||
|
||
scheduleFetchTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll fetch task progress failed:', error)
|
||
scheduleFetchTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
function normalizeAsyncTaskStatus(value: unknown) {
|
||
return String(value ?? '').trim().toLowerCase()
|
||
}
|
||
|
||
function resolveAsyncTaskStatus(progress: Record<string, any>, fallback = 'submitted') {
|
||
return String(progress.status ?? progress.state ?? progress.task_status ?? fallback)
|
||
}
|
||
|
||
function isAsyncTaskSuccessStatus(status: string) {
|
||
return ['success', 'succeeded', 'finished', 'fin', 'done', 'completed', 'complete'].includes(status)
|
||
}
|
||
|
||
function isAsyncTaskFailureStatus(status: string) {
|
||
return ['failed', 'failure', 'error', 'exception', 'cancel', 'cancelled', 'canceled', 'timeout', 'not_found'].includes(status)
|
||
}
|
||
|
||
function stopBatchAllocateExpressTaskPolling() {
|
||
if (batchAllocateExpressTaskPollTimer.value) {
|
||
clearTimeout(batchAllocateExpressTaskPollTimer.value)
|
||
batchAllocateExpressTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleBatchAllocateExpressTaskPolling(delay = 2000) {
|
||
stopBatchAllocateExpressTaskPolling()
|
||
if (!batchAllocateExpressTaskProgress.taskId) return
|
||
batchAllocateExpressTaskPollTimer.value = setTimeout(() => {
|
||
void pollBatchAllocateExpressTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyBatchAllocateExpressTaskProgress(progress: Partial<WaveBatchAllocateExpressTaskProgressResponse> & Record<string, any>) {
|
||
batchAllocateExpressTaskProgress.taskId = String(progress.task_id || batchAllocateExpressTaskProgress.taskId || '')
|
||
batchAllocateExpressTaskProgress.status = resolveAsyncTaskStatus(progress, batchAllocateExpressTaskProgress.status || 'submitted')
|
||
batchAllocateExpressTaskProgress.totalCount = Number(
|
||
progress.total_count
|
||
?? progress.total_order_count
|
||
?? batchAllocateExpressTaskProgress.totalCount
|
||
?? 0
|
||
)
|
||
batchAllocateExpressTaskProgress.successCount = Number(
|
||
progress.success_count
|
||
?? progress.allocated_order_count
|
||
?? progress.updated_count
|
||
?? batchAllocateExpressTaskProgress.successCount
|
||
?? 0
|
||
)
|
||
batchAllocateExpressTaskProgress.failedCount = Number(
|
||
progress.failed_count
|
||
?? progress.failed_order_count
|
||
?? batchAllocateExpressTaskProgress.failedCount
|
||
?? 0
|
||
)
|
||
batchAllocateExpressTaskProgress.progressPercent = Number(progress.progress_percent ?? batchAllocateExpressTaskProgress.progressPercent ?? 0)
|
||
batchAllocateExpressTaskProgress.durationMs = Number(progress.duration_ms ?? batchAllocateExpressTaskProgress.durationMs ?? 0)
|
||
batchAllocateExpressTaskProgress.updateTime = String(progress.update_time || '')
|
||
batchAllocateExpressTaskProgress.error = String(progress.error || '')
|
||
batchAllocateExpressTaskProgress.message = String(progress.message || '')
|
||
}
|
||
|
||
function resetBatchAllocateExpressTaskProgress() {
|
||
batchAllocateExpressTaskProgress.taskId = ''
|
||
batchAllocateExpressTaskProgress.status = 'submitted'
|
||
batchAllocateExpressTaskProgress.totalCount = 0
|
||
batchAllocateExpressTaskProgress.successCount = 0
|
||
batchAllocateExpressTaskProgress.failedCount = 0
|
||
batchAllocateExpressTaskProgress.progressPercent = 0
|
||
batchAllocateExpressTaskProgress.durationMs = 0
|
||
batchAllocateExpressTaskProgress.updateTime = ''
|
||
batchAllocateExpressTaskProgress.error = ''
|
||
batchAllocateExpressTaskProgress.message = ''
|
||
}
|
||
|
||
function stopBatchAllocateStorageTaskPolling() {
|
||
if (batchAllocateStorageTaskPollTimer.value) {
|
||
clearTimeout(batchAllocateStorageTaskPollTimer.value)
|
||
batchAllocateStorageTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleBatchAllocateStorageTaskPolling(delay = 2000) {
|
||
stopBatchAllocateStorageTaskPolling()
|
||
if (!batchAllocateStorageTaskProgress.taskId) return
|
||
batchAllocateStorageTaskPollTimer.value = setTimeout(() => {
|
||
void pollBatchAllocateStorageTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyBatchAllocateStorageTaskProgress(progress: Partial<WaveBatchAllocateStorageTaskProgressResponse> & Record<string, any>) {
|
||
batchAllocateStorageTaskProgress.taskId = String(progress.task_id || batchAllocateStorageTaskProgress.taskId || '')
|
||
batchAllocateStorageTaskProgress.status = resolveAsyncTaskStatus(progress, batchAllocateStorageTaskProgress.status || 'submitted')
|
||
batchAllocateStorageTaskProgress.totalCount = Number(
|
||
progress.total_count
|
||
?? progress.total_order_count
|
||
?? progress.total_wave_count
|
||
?? batchAllocateStorageTaskProgress.totalCount
|
||
?? 0
|
||
)
|
||
batchAllocateStorageTaskProgress.successCount = Number(
|
||
progress.success_count
|
||
?? progress.processed_order_count
|
||
?? progress.allocated_order_count
|
||
?? progress.updated_count
|
||
?? batchAllocateStorageTaskProgress.successCount
|
||
?? 0
|
||
)
|
||
batchAllocateStorageTaskProgress.failedCount = Number(
|
||
progress.failed_count
|
||
?? progress.failed_order_count
|
||
?? batchAllocateStorageTaskProgress.failedCount
|
||
?? 0
|
||
)
|
||
batchAllocateStorageTaskProgress.progressPercent = Number(progress.progress_percent ?? batchAllocateStorageTaskProgress.progressPercent ?? 0)
|
||
batchAllocateStorageTaskProgress.durationMs = Number(progress.duration_ms ?? batchAllocateStorageTaskProgress.durationMs ?? 0)
|
||
batchAllocateStorageTaskProgress.updateTime = String(progress.update_time || '')
|
||
batchAllocateStorageTaskProgress.error = String(progress.error || '')
|
||
batchAllocateStorageTaskProgress.message = String(progress.message || '')
|
||
}
|
||
|
||
function resetBatchAllocateStorageTaskProgress() {
|
||
batchAllocateStorageTaskProgress.taskId = ''
|
||
batchAllocateStorageTaskProgress.status = 'submitted'
|
||
batchAllocateStorageTaskProgress.totalCount = 0
|
||
batchAllocateStorageTaskProgress.successCount = 0
|
||
batchAllocateStorageTaskProgress.failedCount = 0
|
||
batchAllocateStorageTaskProgress.progressPercent = 0
|
||
batchAllocateStorageTaskProgress.durationMs = 0
|
||
batchAllocateStorageTaskProgress.updateTime = ''
|
||
batchAllocateStorageTaskProgress.error = ''
|
||
batchAllocateStorageTaskProgress.message = ''
|
||
}
|
||
|
||
function stopBatchRemoveExceptionOrdersTaskPolling() {
|
||
if (batchRemoveExceptionOrdersTaskPollTimer.value) {
|
||
clearTimeout(batchRemoveExceptionOrdersTaskPollTimer.value)
|
||
batchRemoveExceptionOrdersTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleBatchRemoveExceptionOrdersTaskPolling(delay = 2000) {
|
||
stopBatchRemoveExceptionOrdersTaskPolling()
|
||
if (!batchRemoveExceptionOrdersTaskProgress.taskId) return
|
||
batchRemoveExceptionOrdersTaskPollTimer.value = setTimeout(() => {
|
||
void pollBatchRemoveExceptionOrdersTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyBatchRemoveExceptionOrdersTaskProgress(progress: Partial<WaveBatchRemoveExceptionOrdersTaskProgressResponse> & Record<string, any>) {
|
||
batchRemoveExceptionOrdersTaskProgress.taskId = String(progress.task_id || batchRemoveExceptionOrdersTaskProgress.taskId || '')
|
||
batchRemoveExceptionOrdersTaskProgress.status = resolveAsyncTaskStatus(progress, batchRemoveExceptionOrdersTaskProgress.status || 'submitted')
|
||
batchRemoveExceptionOrdersTaskProgress.totalCount = Number(
|
||
progress.total_count
|
||
?? progress.total_order_count
|
||
?? batchRemoveExceptionOrdersTaskProgress.totalCount
|
||
?? 0
|
||
)
|
||
batchRemoveExceptionOrdersTaskProgress.successCount = Number(
|
||
progress.success_count
|
||
?? progress.removed_order_count
|
||
?? progress.updated_count
|
||
?? batchRemoveExceptionOrdersTaskProgress.successCount
|
||
?? 0
|
||
)
|
||
batchRemoveExceptionOrdersTaskProgress.failedCount = Number(
|
||
progress.failed_count
|
||
?? progress.failed_order_count
|
||
?? batchRemoveExceptionOrdersTaskProgress.failedCount
|
||
?? 0
|
||
)
|
||
batchRemoveExceptionOrdersTaskProgress.progressPercent = Number(progress.progress_percent ?? batchRemoveExceptionOrdersTaskProgress.progressPercent ?? 0)
|
||
batchRemoveExceptionOrdersTaskProgress.durationMs = Number(progress.duration_ms ?? batchRemoveExceptionOrdersTaskProgress.durationMs ?? 0)
|
||
batchRemoveExceptionOrdersTaskProgress.updateTime = String(progress.update_time || '')
|
||
batchRemoveExceptionOrdersTaskProgress.error = String(progress.error || '')
|
||
batchRemoveExceptionOrdersTaskProgress.message = String(progress.message || '')
|
||
}
|
||
|
||
function resetBatchRemoveExceptionOrdersTaskProgress() {
|
||
batchRemoveExceptionOrdersTaskProgress.taskId = ''
|
||
batchRemoveExceptionOrdersTaskProgress.status = 'submitted'
|
||
batchRemoveExceptionOrdersTaskProgress.totalCount = 0
|
||
batchRemoveExceptionOrdersTaskProgress.successCount = 0
|
||
batchRemoveExceptionOrdersTaskProgress.failedCount = 0
|
||
batchRemoveExceptionOrdersTaskProgress.progressPercent = 0
|
||
batchRemoveExceptionOrdersTaskProgress.durationMs = 0
|
||
batchRemoveExceptionOrdersTaskProgress.updateTime = ''
|
||
batchRemoveExceptionOrdersTaskProgress.error = ''
|
||
batchRemoveExceptionOrdersTaskProgress.message = ''
|
||
}
|
||
|
||
function stopBatchCancelTaskPolling() {
|
||
if (batchCancelTaskPollTimer.value) {
|
||
clearTimeout(batchCancelTaskPollTimer.value)
|
||
batchCancelTaskPollTimer.value = null
|
||
}
|
||
}
|
||
|
||
function scheduleBatchCancelTaskPolling(delay = 2000) {
|
||
stopBatchCancelTaskPolling()
|
||
if (!batchCancelTaskProgress.taskId) return
|
||
batchCancelTaskPollTimer.value = setTimeout(() => {
|
||
void pollBatchCancelTaskProgress()
|
||
}, delay)
|
||
}
|
||
|
||
function applyBatchCancelTaskProgress(progress: Partial<WaveBatchCancelTaskProgressResponse> & Record<string, any>) {
|
||
batchCancelTaskProgress.taskId = String(progress.task_id || batchCancelTaskProgress.taskId || '')
|
||
batchCancelTaskProgress.status = resolveAsyncTaskStatus(progress, batchCancelTaskProgress.status || 'submitted')
|
||
batchCancelTaskProgress.totalCount = Number(
|
||
progress.total_count
|
||
?? progress.total_wave_count
|
||
?? batchCancelTaskProgress.totalCount
|
||
?? 0
|
||
)
|
||
batchCancelTaskProgress.successCount = Number(
|
||
progress.success_count
|
||
?? progress.processed_wave_count
|
||
?? batchCancelTaskProgress.successCount
|
||
?? 0
|
||
)
|
||
batchCancelTaskProgress.failedCount = Number(
|
||
progress.failed_count
|
||
?? batchCancelTaskProgress.failedCount
|
||
?? 0
|
||
)
|
||
batchCancelTaskProgress.progressPercent = Number(progress.progress_percent ?? batchCancelTaskProgress.progressPercent ?? 0)
|
||
batchCancelTaskProgress.durationMs = Number(progress.duration_ms ?? batchCancelTaskProgress.durationMs ?? 0)
|
||
batchCancelTaskProgress.updateTime = String(progress.update_time || '')
|
||
batchCancelTaskProgress.error = String(progress.error || '')
|
||
batchCancelTaskProgress.message = String(progress.message || '')
|
||
}
|
||
|
||
function resetBatchCancelTaskProgress() {
|
||
batchCancelTaskProgress.taskId = ''
|
||
batchCancelTaskProgress.status = 'submitted'
|
||
batchCancelTaskProgress.totalCount = 0
|
||
batchCancelTaskProgress.successCount = 0
|
||
batchCancelTaskProgress.failedCount = 0
|
||
batchCancelTaskProgress.progressPercent = 0
|
||
batchCancelTaskProgress.durationMs = 0
|
||
batchCancelTaskProgress.updateTime = ''
|
||
batchCancelTaskProgress.error = ''
|
||
batchCancelTaskProgress.message = ''
|
||
}
|
||
|
||
async function pollBatchCancelTaskProgress() {
|
||
if (!batchCancelTaskProgress.taskId) return
|
||
try {
|
||
const res = await orderWaveBatchCancelTaskProgress({ task_id: batchCancelTaskProgress.taskId }) as WaveBatchCancelTaskProgressResponse & { code?: number; message?: string; flag?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '查询批量取消波次任务进度失败')
|
||
}
|
||
|
||
applyBatchCancelTaskProgress(res)
|
||
const normalizedStatus = normalizeAsyncTaskStatus(batchCancelTaskProgress.status)
|
||
|
||
if (isAsyncTaskFailureStatus(normalizedStatus)) {
|
||
stopBatchCancelTaskPolling()
|
||
await loadData()
|
||
resetBatchCancelTaskProgress()
|
||
return
|
||
}
|
||
|
||
if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(batchCancelTaskProgress.progressPercent || 0) >= 100) {
|
||
stopBatchCancelTaskPolling()
|
||
await loadData()
|
||
resetBatchCancelTaskProgress()
|
||
return
|
||
}
|
||
|
||
scheduleBatchCancelTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll batch cancel task progress failed:', error)
|
||
scheduleBatchCancelTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
async function pollBatchRemoveExceptionOrdersTaskProgress() {
|
||
if (!batchRemoveExceptionOrdersTaskProgress.taskId) return
|
||
try {
|
||
const res = await orderWaveBatchRemoveExceptionOrdersTaskProgress({ task_id: batchRemoveExceptionOrdersTaskProgress.taskId }) as WaveBatchRemoveExceptionOrdersTaskProgressResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '查询移除异常订单任务进度失败')
|
||
}
|
||
|
||
applyBatchRemoveExceptionOrdersTaskProgress(res)
|
||
const normalizedStatus = normalizeAsyncTaskStatus(batchRemoveExceptionOrdersTaskProgress.status)
|
||
|
||
if (isAsyncTaskFailureStatus(normalizedStatus)) {
|
||
stopBatchRemoveExceptionOrdersTaskPolling()
|
||
await loadData()
|
||
resetBatchRemoveExceptionOrdersTaskProgress()
|
||
return
|
||
}
|
||
|
||
if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(batchRemoveExceptionOrdersTaskProgress.progressPercent || 0) >= 100) {
|
||
stopBatchRemoveExceptionOrdersTaskPolling()
|
||
await loadData()
|
||
resetBatchRemoveExceptionOrdersTaskProgress()
|
||
return
|
||
}
|
||
|
||
scheduleBatchRemoveExceptionOrdersTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll batch remove exception orders task progress failed:', error)
|
||
scheduleBatchRemoveExceptionOrdersTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
async function pollBatchAllocateStorageTaskProgress() {
|
||
if (!batchAllocateStorageTaskProgress.taskId) return
|
||
try {
|
||
const res = await orderWaveBatchAllocateStorageTaskProgress({ task_id: batchAllocateStorageTaskProgress.taskId }) as WaveBatchAllocateStorageTaskProgressResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '查询储位分配任务进度失败')
|
||
}
|
||
|
||
applyBatchAllocateStorageTaskProgress(res)
|
||
const normalizedStatus = normalizeAsyncTaskStatus(batchAllocateStorageTaskProgress.status)
|
||
|
||
if (isAsyncTaskFailureStatus(normalizedStatus)) {
|
||
stopBatchAllocateStorageTaskPolling()
|
||
await loadData()
|
||
resetBatchAllocateStorageTaskProgress()
|
||
return
|
||
}
|
||
|
||
if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(batchAllocateStorageTaskProgress.progressPercent || 0) >= 100) {
|
||
stopBatchAllocateStorageTaskPolling()
|
||
await loadData()
|
||
resetBatchAllocateStorageTaskProgress()
|
||
return
|
||
}
|
||
|
||
scheduleBatchAllocateStorageTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll batch allocate storage task progress failed:', error)
|
||
scheduleBatchAllocateStorageTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
async function pollBatchAllocateExpressTaskProgress() {
|
||
if (!batchAllocateExpressTaskProgress.taskId) return
|
||
try {
|
||
const res = await orderWaveBatchAllocateExpressTaskProgress({ task_id: batchAllocateExpressTaskProgress.taskId }) as WaveBatchAllocateExpressTaskProgressResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '查询快递号分配任务进度失败')
|
||
}
|
||
|
||
applyBatchAllocateExpressTaskProgress(res)
|
||
const normalizedStatus = normalizeAsyncTaskStatus(batchAllocateExpressTaskProgress.status)
|
||
|
||
if (isAsyncTaskFailureStatus(normalizedStatus)) {
|
||
stopBatchAllocateExpressTaskPolling()
|
||
await loadData()
|
||
resetBatchAllocateExpressTaskProgress()
|
||
return
|
||
}
|
||
|
||
if (isAsyncTaskSuccessStatus(normalizedStatus) || Number(batchAllocateExpressTaskProgress.progressPercent || 0) >= 100) {
|
||
stopBatchAllocateExpressTaskPolling()
|
||
await loadData()
|
||
resetBatchAllocateExpressTaskProgress()
|
||
return
|
||
}
|
||
|
||
scheduleBatchAllocateExpressTaskPolling()
|
||
} catch (error) {
|
||
console.error('poll batch allocate express task progress failed:', error)
|
||
scheduleBatchAllocateExpressTaskPolling(4000)
|
||
}
|
||
}
|
||
|
||
async function handleBatchAllocateExpress() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要分配快递号的波次')
|
||
return
|
||
}
|
||
|
||
const wave_ids = getSelectedWaveIds()
|
||
if (!wave_ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要为选中的 ${wave_ids.length} 个波次提交快递号分配任务吗?`,
|
||
'批次分配快递号',
|
||
{ type: 'warning', confirmButtonText: '确认提交', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchAllocateExpressLoading.value = true
|
||
try {
|
||
const res = await orderWaveBatchAllocateExpress({ wave_ids }) as { code?: number; message?: string; task_id?: string; status?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '提交批次分配快递号任务失败')
|
||
}
|
||
|
||
const taskId = String(res?.task_id || '').trim()
|
||
if (!taskId) {
|
||
resetBatchAllocateExpressTaskProgress()
|
||
ElMessage.success(res?.message || '快递号分配任务已提交')
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
applyBatchAllocateExpressTaskProgress({
|
||
task_id: taskId,
|
||
status: 'submitted',
|
||
total_count: wave_ids.length,
|
||
success_count: 0,
|
||
failed_count: 0,
|
||
progress_percent: 0,
|
||
message: res?.message || '快递号分配任务已受理'
|
||
})
|
||
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
ElMessage.success((res?.message || '快递号分配任务已受理') + `(任务ID:${taskId})`)
|
||
scheduleBatchAllocateExpressTaskPolling(1000)
|
||
} catch (error: any) {
|
||
console.error('submit batch allocate express task failed:', error)
|
||
ElMessage.error(error?.message || '提交批次分配快递号任务失败')
|
||
} finally {
|
||
batchAllocateExpressLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleBatchAllocateStorage() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要分配储位的波次')
|
||
return
|
||
}
|
||
|
||
const wave_ids = getSelectedWaveIds()
|
||
if (!wave_ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要为选中的 ${wave_ids.length} 个波次提交储位分配任务吗?`,
|
||
'批量分配储位',
|
||
{ type: 'warning', confirmButtonText: '确认提交', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchAllocateStorageLoading.value = true
|
||
try {
|
||
const res = await orderWaveBatchAllocateStorage({ wave_ids }) as { code?: number; message?: string; task_id?: string; status?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '提交批量分配储位任务失败')
|
||
}
|
||
|
||
const taskId = String(res?.task_id || '').trim()
|
||
if (!taskId) {
|
||
resetBatchAllocateStorageTaskProgress()
|
||
ElMessage.success(res?.message || '储位分配任务已提交')
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
applyBatchAllocateStorageTaskProgress({
|
||
task_id: taskId,
|
||
status: 'submitted',
|
||
total_count: wave_ids.length,
|
||
success_count: 0,
|
||
failed_count: 0,
|
||
progress_percent: 0,
|
||
message: res?.message || '储位分配任务已受理'
|
||
})
|
||
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
ElMessage.success((res?.message || '储位分配任务已受理') + `(任务ID:${taskId})`)
|
||
scheduleBatchAllocateStorageTaskPolling(1000)
|
||
} catch (error: any) {
|
||
console.error('submit batch allocate storage task failed:', error)
|
||
ElMessage.error(error?.message || '提交批量分配储位任务失败')
|
||
} finally {
|
||
batchAllocateStorageLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleBatchRemoveExceptionOrders() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要移除异常订单的波次')
|
||
return
|
||
}
|
||
|
||
const wave_ids = getSelectedWaveIds()
|
||
if (!wave_ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要为选中的 ${wave_ids.length} 个波次提交移除异常订单任务吗?`,
|
||
'批量移除异常订单',
|
||
{ type: 'warning', confirmButtonText: '确认提交', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchRemoveExceptionOrdersLoading.value = true
|
||
try {
|
||
const res = await orderWaveBatchRemoveExceptionOrders({ wave_ids }) as { code?: number; message?: string; task_id?: string; status?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '提交批量移除异常订单任务失败')
|
||
}
|
||
|
||
const taskId = String(res?.task_id || '').trim()
|
||
if (!taskId) {
|
||
resetBatchRemoveExceptionOrdersTaskProgress()
|
||
ElMessage.success(res?.message || '移除异常订单任务已提交')
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
applyBatchRemoveExceptionOrdersTaskProgress({
|
||
task_id: taskId,
|
||
status: 'submitted',
|
||
total_count: wave_ids.length,
|
||
success_count: 0,
|
||
failed_count: 0,
|
||
progress_percent: 0,
|
||
message: res?.message || '移除异常订单任务已受理'
|
||
})
|
||
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
ElMessage.success((res?.message || '移除异常订单任务已受理') + `(任务ID:${taskId})`)
|
||
scheduleBatchRemoveExceptionOrdersTaskPolling(1000)
|
||
} catch (error: any) {
|
||
console.error('submit batch remove exception orders task failed:', error)
|
||
ElMessage.error(error?.message || '提交批量移除异常订单任务失败')
|
||
} finally {
|
||
batchRemoveExceptionOrdersLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleBatchCancel() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要取消的波次')
|
||
return
|
||
}
|
||
|
||
const ids = getSelectedWaveIds()
|
||
|
||
if (!ids.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要批量取消 ${ids.length} 个波次吗?取消后将解除订单与波次的关联。`,
|
||
'批量取消波次',
|
||
{ type: 'warning', confirmButtonText: '确认取消', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchCancelLoading.value = true
|
||
try {
|
||
const res: any = await orderWaveBatchCancel({ ids })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '批量取消波次失败')
|
||
}
|
||
|
||
const taskId = String(res?.task_id || '').trim()
|
||
if (!taskId) {
|
||
resetBatchCancelTaskProgress()
|
||
ElMessage.success(res?.message || '批量取消波次成功')
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
await loadData()
|
||
return
|
||
}
|
||
|
||
applyBatchCancelTaskProgress({
|
||
task_id: taskId,
|
||
status: 'submitted',
|
||
total_count: ids.length,
|
||
success_count: 0,
|
||
failed_count: 0,
|
||
progress_percent: 0,
|
||
message: res?.message || '批量取消波次任务已受理'
|
||
})
|
||
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
ElMessage.success((res?.message || '批量取消波次任务已受理') + `(任务ID:${taskId})`)
|
||
scheduleBatchCancelTaskPolling(1000)
|
||
} catch (error: any) {
|
||
console.error('batch cancel wave failed:', error)
|
||
ElMessage.error(error?.message || '批量取消波次失败')
|
||
} finally {
|
||
batchCancelLoading.value = false
|
||
}
|
||
}
|
||
|
||
function openGroupOrderDialog() {
|
||
groupOrderDialogVisible.value = true
|
||
groupOrderFilters.distinguishExpress = true
|
||
groupOrderPagination.currentPage = 1
|
||
groupOrderSelectionRows.value = []
|
||
resetGroupOrderQuantityMap()
|
||
loadGroupOrderStoreOptions()
|
||
fetchGroupOrderList()
|
||
}
|
||
|
||
function openSingleOrderDialog() {
|
||
singleOrderDialogVisible.value = true
|
||
singleOrderActiveTab.value = 'fallback-orders'
|
||
fallbackOrderPagination.currentPage = 1
|
||
fallbackOrderSelectionRows.value = []
|
||
void fetchFallbackOrderList()
|
||
}
|
||
|
||
async function loadGroupOrderStoreOptions() {
|
||
if (groupOrderStoreOptions.value.length > 0) return
|
||
try {
|
||
const res: any = await indexApi.loadStores({ type: 'order' })
|
||
const stores = Array.isArray(res?.stores) ? res.stores : []
|
||
groupOrderStoreOptions.value = stores.map((item: any) => ({
|
||
label: item.label || item.name || String(item.value || item.id),
|
||
value: item.value ?? item.id
|
||
}))
|
||
} catch (error) {
|
||
console.error('load group order stores failed:', error)
|
||
groupOrderStoreOptions.value = []
|
||
}
|
||
}
|
||
|
||
type StructureFetchListFilters = {
|
||
distinguishExpress: boolean
|
||
storeId: number | string | undefined
|
||
sameOrderQuantity: number | undefined
|
||
shopName: string
|
||
includeSku: string
|
||
returnOrderIds: boolean
|
||
}
|
||
|
||
function buildStructureFetchListPayload(
|
||
pagination: { currentPage: number; pageSize: number },
|
||
filters: StructureFetchListFilters
|
||
) {
|
||
const payload: Record<string, any> = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
distinguish_express: filters.distinguishExpress,
|
||
return_order_ids: filters.returnOrderIds
|
||
}
|
||
|
||
if (filters.storeId !== undefined && filters.storeId !== null && filters.storeId !== '') {
|
||
payload.store_id = Number(filters.storeId)
|
||
}
|
||
if (filters.sameOrderQuantity !== undefined && filters.sameOrderQuantity !== null) {
|
||
payload.same_order_quantity = Number(filters.sameOrderQuantity)
|
||
}
|
||
if (filters.shopName.trim()) {
|
||
payload.shop_name = filters.shopName.trim()
|
||
}
|
||
if (filters.includeSku.trim()) {
|
||
payload.include_sku = filters.includeSku.trim()
|
||
}
|
||
|
||
return payload
|
||
}
|
||
|
||
function buildGroupOrderListPayload() {
|
||
return buildStructureFetchListPayload(groupOrderPagination, groupOrderFilters)
|
||
}
|
||
|
||
function sanitizeFallbackOrderWhere(where: Record<string, any>) {
|
||
const nextWhere: Record<string, any> = {}
|
||
Object.keys(where || {}).forEach((key) => {
|
||
if (key === 'warehouse_id' || key === 'warehouseId') return
|
||
const value = where[key]
|
||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) return
|
||
nextWhere[key] = value
|
||
})
|
||
return nextWhere
|
||
}
|
||
|
||
function buildFallbackOrderListPayload() {
|
||
return {
|
||
pagination: {
|
||
page: fallbackOrderPagination.currentPage,
|
||
pageSize: fallbackOrderPagination.pageSize
|
||
},
|
||
where: sanitizeFallbackOrderWhere(buildWhereConditions(fallbackOrderScanBox.value?.getConditions?.() || {})),
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC'
|
||
}
|
||
}
|
||
}
|
||
|
||
async function fetchFallbackOrderList() {
|
||
fallbackOrderListLoading.value = true
|
||
try {
|
||
const res: any = await orderWaveWaveStrategyFallbackOrderList(buildFallbackOrderListPayload())
|
||
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
|
||
} catch (error: any) {
|
||
console.error('fetch fallback order list failed:', error)
|
||
fallbackOrderList.value = []
|
||
fallbackOrderPagination.total = 0
|
||
ElMessage.error(error?.message || '获取不符合波次策略订单失败')
|
||
} finally {
|
||
fallbackOrderListLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function fetchGroupOrderList() {
|
||
groupOrderListLoading.value = true
|
||
try {
|
||
const res: any = await orderWaveGroupOrderFetchList(buildGroupOrderListPayload())
|
||
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 || {}
|
||
groupOrderList.value = responseList
|
||
groupOrderPagination.currentPage = responsePagination.page || groupOrderPagination.currentPage
|
||
groupOrderPagination.pageSize = responsePagination.pageSize || groupOrderPagination.pageSize
|
||
groupOrderPagination.total = responsePagination.total || 0
|
||
} catch (error: any) {
|
||
console.error('fetch group order list failed:', error)
|
||
groupOrderList.value = []
|
||
groupOrderPagination.total = 0
|
||
ElMessage.error(error?.message || '获取可抓取团购单列表失败')
|
||
} finally {
|
||
groupOrderListLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleGroupOrderSelectionChange(rows: any[]) {
|
||
groupOrderSelectionRows.value = rows || []
|
||
}
|
||
|
||
function handleGroupOrderFilterChange() {
|
||
groupOrderPagination.currentPage = 1
|
||
fetchGroupOrderList()
|
||
}
|
||
|
||
function resetGroupOrderFilters() {
|
||
groupOrderFilters.distinguishExpress = true
|
||
groupOrderFilters.storeId = undefined
|
||
groupOrderFilters.sameOrderQuantity = undefined
|
||
groupOrderFilters.shopName = ''
|
||
groupOrderFilters.includeSku = ''
|
||
groupOrderFilters.returnOrderIds = false
|
||
groupOrderPagination.currentPage = 1
|
||
fetchGroupOrderList()
|
||
}
|
||
|
||
function handleGroupOrderPageChange(page: number) {
|
||
groupOrderPagination.currentPage = page
|
||
fetchGroupOrderList()
|
||
}
|
||
|
||
function handleGroupOrderPageSizeChange(size: number) {
|
||
groupOrderPagination.pageSize = size
|
||
groupOrderPagination.currentPage = 1
|
||
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 updateGroupOrderQuantity(row: any, value: number | undefined) {
|
||
const key = String(row?.item_detail_machine || '')
|
||
if (!key) return
|
||
if (value === undefined || value === null || Number.isNaN(Number(value))) {
|
||
delete groupOrderQuantityMap[key]
|
||
return
|
||
}
|
||
groupOrderQuantityMap[key] = Math.max(1, Math.trunc(Number(value)))
|
||
}
|
||
|
||
function resetGroupOrderQuantityMap() {
|
||
Object.keys(groupOrderQuantityMap).forEach((key) => {
|
||
delete groupOrderQuantityMap[key]
|
||
})
|
||
}
|
||
|
||
function getGroupOrderStoreText(row: any) {
|
||
if (Array.isArray(row?.store_ids) && row.store_ids.length > 1) {
|
||
return row.store_ids.join(',')
|
||
}
|
||
return row?.store_id ?? row?.store_ids?.[0] ?? '—'
|
||
}
|
||
|
||
function getGroupOrderStatusSummary(row: any) {
|
||
const summary = row?.status_summary || {}
|
||
const parts = [
|
||
`配货未开始 ${summary.pick_none ?? 0}`,
|
||
`配货完成 ${summary.pick_fin ?? 0}`,
|
||
`出库未开始 ${summary.outbound_none ?? 0}`,
|
||
`出库完成 ${summary.outbound_fin ?? 0}`
|
||
]
|
||
return parts.join(' / ')
|
||
}
|
||
|
||
function getGroupOrderItemSnapshotText(row: any) {
|
||
if (typeof row?.item_detail === 'string' && row.item_detail) {
|
||
return row.item_detail
|
||
}
|
||
if (Array.isArray(row?.item_snapshot) && row.item_snapshot.length) {
|
||
return row.item_snapshot
|
||
.map((item: any) => `${item.item_name || item.item_code || item.barcode || '未知商品'} x ${item.quantity ?? 0}`)
|
||
.join(' | ')
|
||
}
|
||
return row?.item_detail_machine_snapshot || '—'
|
||
}
|
||
|
||
async function submitGroupOrderDialog() {
|
||
if (!groupOrderSelectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要抓取的团购单结构')
|
||
return
|
||
}
|
||
|
||
groupOrderSubmitting.value = true
|
||
try {
|
||
const structureList: WaveFetchParams['structure_list'] = groupOrderSelectionRows.value.map((row: any) => {
|
||
const key = String(row?.item_detail_machine || '')
|
||
const payload: WaveFetchParams['structure_list'][number] = {
|
||
item_detail_machine: key
|
||
}
|
||
const quantity = groupOrderQuantityMap[key]
|
||
if (quantity !== undefined) {
|
||
payload.quantity = quantity
|
||
}
|
||
return payload
|
||
})
|
||
|
||
const res = await orderWaveGroupFetch({ structure_list: structureList }) as WaveFetchResponse & { code?: number; message?: string }
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '抓取团购单失败')
|
||
}
|
||
|
||
const acceptedMessage = [
|
||
res?.message || '任务已提交,后端异步处理中',
|
||
res?.task_id ? `任务ID:${res.task_id}` : '',
|
||
res?.structure_count !== undefined ? `结构数:${res.structure_count}` : ''
|
||
].filter(Boolean).join(';')
|
||
|
||
applyFetchTaskProgress({
|
||
task_id: res.task_id,
|
||
status: 'submitted',
|
||
warehouse_id: res.warehouse_id,
|
||
structure_count: res.structure_count,
|
||
finished_structure_count: 0,
|
||
progress_percent: 0,
|
||
total_fetched_quantity: 0,
|
||
message: res.message || '任务已提交,后端异步处理中'
|
||
})
|
||
scheduleFetchTaskPolling(1000)
|
||
|
||
ElMessage.success(acceptedMessage)
|
||
groupOrderDialogVisible.value = false
|
||
groupOrderSelectionRows.value = []
|
||
resetGroupOrderQuantityMap()
|
||
} catch (error: any) {
|
||
console.error('fetch group order failed:', error)
|
||
ElMessage.error(error?.message || '抓取团购单失败')
|
||
} finally {
|
||
groupOrderSubmitting.value = false
|
||
}
|
||
}
|
||
|
||
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' }
|
||
)
|
||
} 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(';'))
|
||
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
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../orderManagement/styles/order-sub.scss";
|
||
|
||
.task-progress-panel--toolbar {
|
||
margin-bottom: 3px;
|
||
}
|
||
|
||
.task-progress-panel {
|
||
padding: 12px 14px;
|
||
background: #fff;
|
||
border: 1px solid #ebeef5;
|
||
}
|
||
|
||
.task-progress-panel__header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 8px;
|
||
gap: 12px;
|
||
}
|
||
|
||
.task-progress-panel__title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.task-progress-panel__meta {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
.task-progress-panel__info {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
margin-top: 8px;
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
|
||
.task-progress-panel__message {
|
||
margin-top: 6px;
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
|
||
.order-sub-container .main-content .lower-level .detail-container {
|
||
padding: 10px;
|
||
overflow: auto;
|
||
}
|
||
|
||
.order-sub-container .main-content .lower-level .detail-header {
|
||
padding: 0 12px;
|
||
height: 42px;
|
||
}
|
||
|
||
.detail-title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.structure-fetch-hint {
|
||
margin-bottom: 4px;
|
||
}
|
||
|
||
.structure-fetch-label-help {
|
||
margin-left: 4px;
|
||
vertical-align: middle;
|
||
color: var(--el-color-info);
|
||
cursor: help;
|
||
}
|
||
|
||
.group-order-dialog {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
}
|
||
|
||
.single-order-tabs {
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
|
||
.single-fallback-layout {
|
||
display: flex;
|
||
gap: 10px;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
|
||
.single-fallback-main {
|
||
flex: 1;
|
||
min-width: 0;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
}
|
||
|
||
:deep(.single-fetch-dialog .el-dialog__body) {
|
||
height: calc(100vh - 240px);
|
||
max-height: calc(100vh - 240px);
|
||
overflow: hidden;
|
||
}
|
||
|
||
:deep(.single-fetch-dialog .el-tabs),
|
||
:deep(.single-fetch-dialog .el-tabs__content),
|
||
:deep(.single-fetch-dialog .el-tab-pane) {
|
||
height: 100%;
|
||
}
|
||
|
||
.group-order-filters {
|
||
padding: 4px 0 0;
|
||
}
|
||
|
||
.group-order-toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
}
|
||
|
||
.group-order-pagination {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
padding-top: 4px;
|
||
}
|
||
|
||
.status-summary-text {
|
||
display: inline-block;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.order-sub-container .main-content {
|
||
.toolbar {
|
||
.toolbar-left {
|
||
cursor: grab;
|
||
|
||
&:active {
|
||
cursor: grabbing;
|
||
}
|
||
|
||
.toolbar-scroll-container {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
overflow-x: auto;
|
||
scrollbar-width: none;
|
||
|
||
&::-webkit-scrollbar {
|
||
display: none;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style> |