1129 lines
37 KiB
Vue
1129 lines
37 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="orderManagement:exceptionOrder"
|
||
width="250px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<order-toolbar-button-group
|
||
:buttons="toolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
|
||
<template v-for="(btn, index) in expectionOrderbuttonList" :key="index">
|
||
<el-dropdown
|
||
v-if="btn.type === 'dropdown'"
|
||
trigger="hover"
|
||
@command="(cmd:any) => handleCommand(btn.command, cmd)"
|
||
>
|
||
<el-button size="small" :loading="btn.loading">
|
||
{{ btn.label }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||
</el-button>
|
||
<template #dropdown>
|
||
<el-dropdown-menu>
|
||
<el-dropdown-item
|
||
v-for="opt in btn.options"
|
||
:key="opt.value"
|
||
:command="opt.value"
|
||
:divided="opt.divided"
|
||
>
|
||
{{ opt.label }}
|
||
</el-dropdown-item>
|
||
</el-dropdown-menu>
|
||
</template>
|
||
</el-dropdown>
|
||
|
||
<el-button
|
||
v-else
|
||
size="small"
|
||
:type="btn.btnType || 'primary'"
|
||
:disabled="btn.needSelection && !hasSelection"
|
||
@click="handleCommand(btn.command)"
|
||
>
|
||
{{ btn.label }}
|
||
</el-button>
|
||
</template>
|
||
</div>
|
||
|
||
<!-- 已迁移至 ScanBox:搜索订单号 -->
|
||
<!-- <div class="toolbar-right">
|
||
<el-input size="small" placeholder="搜索订单号" v-model="quickSearch" style="width:220px" @keyup.enter.native="onQuickSearch" />
|
||
</div> -->
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="待处理异常订单列表"
|
||
default-align="center"
|
||
:enable-column-config="true"
|
||
table-id="order-management-exception-order"
|
||
:data="list"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:show-selection="true"
|
||
:loading="loading"
|
||
:queryTime="queryTime"
|
||
@current-change="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@selection-change="onSelectionChange"
|
||
>
|
||
<template #column-order_status="{ row }">
|
||
<el-tag :type="getTagType('order_status', row.order_status)" size="small">
|
||
{{ translateOrderField('order_status', row.order_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-status="{ row }">
|
||
<el-tag :type="getTagType('status', row.status)" size="small">
|
||
{{ translateOrderField('status', row.status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-is_urgency="{ row }">
|
||
<el-tag :type="getTagType('is_urgency', row.is_urgency)" size="small">
|
||
{{ translateOrderField('is_urgency', row.is_urgency) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-sync_status="{ row }">
|
||
<el-tag :type="getTagType('sync_status', row.sync_status)" size="small">
|
||
{{ translateOrderField('sync_status', row.sync_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-recheck_status="{ row }">
|
||
<el-tag :type="getTagType('recheck_status', resolveOrderRecheckStatus(row))" size="small">
|
||
{{ translateOrderField('recheck_status', resolveOrderRecheckStatus(row)) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-storage_status="{ row }">
|
||
<el-tag :type="getTagType('storage_status', row.storage_status)" size="small">
|
||
{{ translateOrderField('storage_status', row.storage_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-intercept_status="{ row }">
|
||
<el-tag v-if="row.intercept_status && row.intercept_status !== 'none'" type="danger" size="small">
|
||
{{ translateInterceptStatus(row.intercept_status) }}
|
||
</el-tag>
|
||
<span v-else style="color:#909399">—</span>
|
||
</template>
|
||
|
||
<template #column-post_status="{ row }">
|
||
<el-tag :type="getTagType('post_status', row.post_status)" size="small">
|
||
{{ translateOrderField('post_status', row.post_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-print_status="{ row }">
|
||
<el-tag :type="getTagType('print_status', row.print_status)" size="small">
|
||
{{ translateOrderField('print_status', row.print_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-pick_status="{ row }">
|
||
<el-tag :type="getTagType('pick_status', row.pick_status)" size="small">
|
||
{{ translateOrderField('pick_status', row.pick_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-pack_status="{ row }">
|
||
<el-tag :type="getTagType('pack_status', row.pack_status)" size="small">
|
||
{{ translateOrderField('pack_status', row.pack_status) }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-order_flag="{ row }">
|
||
<el-tooltip
|
||
:content="orderFlagFullText(row)"
|
||
placement="top"
|
||
:disabled="!orderFlagFullText(row)"
|
||
:show-after="400"
|
||
>
|
||
<span
|
||
class="order-flag-cell"
|
||
role="button"
|
||
tabindex="0"
|
||
@click.stop="copyOrderFlag(row)"
|
||
@keydown.enter.prevent="copyOrderFlag(row)"
|
||
>
|
||
{{ orderFlagCellText(row) }}
|
||
</span>
|
||
</el-tooltip>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无待处理异常订单</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
<div class="lower-level" v-if="selectedOrderId" :class="tableSize" :style="lowerPaneStyle">
|
||
<div class="detail-header">
|
||
<el-tabs v-model="activeTab" class="detail-tab">
|
||
<el-tab-pane label="订单明细" name="detail" />
|
||
<el-tab-pane label="商品明细" name="items" />
|
||
<el-tab-pane label="订单日志" name="logs" />
|
||
</el-tabs>
|
||
<div v-if="activeTab === 'detail' || activeTab === 'items'" class="detail-header-actions">
|
||
<order-detail-display-toggle v-model="detailDisplayMode" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<div v-if="activeTab === 'detail'" :key="`detail-${selectedOrderId}`" class="detail-page order-detail-wrapper">
|
||
<pending-order-detail-panel :key="selectedOrderId" :row="selectedRow" :detail-request="fetchExpectionOrderDetail" :display-mode="detailDisplayMode" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'items'" :key="`items-${selectedOrderId}`" class="detail-page order-detail-wrapper">
|
||
<order-items-detail-panel :key="selectedOrderId" :row="selectedRow" :detail-request="fetchExpectionOrderDetail" :display-mode="detailDisplayMode" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'picking'" class="detail-page order-picking-wrapper">
|
||
<p>配货明细加载中...</p>
|
||
</div>
|
||
<div v-else :key="`logs-${selectedOrderId}`" class="detail-page order-log-wrapper">
|
||
<log :key="selectedOrderId" :data="selectedRow" />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="no-selection" v-else :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
|
||
<allocate-express-form
|
||
v-model="allocateDialogVisible"
|
||
:loading="allocateLoading"
|
||
@closed="resetAllocateDialog"
|
||
@submit="submitAllocateExpress"
|
||
/>
|
||
<storage-allocate-form
|
||
v-model="storageDialogVisible"
|
||
v-model:allow-storage-location="storageForm.allowStorageLocation"
|
||
:mode="storageDialogMode"
|
||
:order-count="storagePendingOrderIds.length"
|
||
:loading="storageAllocateLoading"
|
||
:request-id="storageAllocateRequestId"
|
||
:task-status="storageAllocateTaskStatus"
|
||
:progress-percent="storageAllocateProgressPercent"
|
||
:total-count="storageAllocateTotalCount"
|
||
:success-count="storageAllocateSuccessCount"
|
||
:failed-count="storageAllocateFailedCount"
|
||
:message="storageAllocateMessage"
|
||
@closed="resetStorageAllocateDialog"
|
||
@submit="submitStorageAllocate"
|
||
/>
|
||
<update-order-meta-form
|
||
v-model="updateOrderMetaDialogVisible"
|
||
v-model:code="updateOrderMetaForm.code"
|
||
:mode="updateOrderMetaDialogMode"
|
||
:order-count="updateOrderMetaOrderIds.length"
|
||
:loading="updateOrderMetaLoading"
|
||
:options="updateOrderMetaOptions"
|
||
@closed="resetUpdateOrderMetaDialog"
|
||
@submit="submitUpdateOrderMeta"
|
||
/>
|
||
<clone-order-form
|
||
v-model="cloneOrderDialogVisible"
|
||
:loading="cloneOrderLoading"
|
||
:source-order-id="cloneSourceOrderId"
|
||
:source-order-code="cloneSourceOrderCode"
|
||
@closed="resetCloneOrderDialog"
|
||
@submit="submitCloneOrder"
|
||
/>
|
||
<manual-waybill-form
|
||
v-model="manualWaybillDialogVisible"
|
||
v-model:waybill-code="manualWaybillForm.waybill_code"
|
||
:loading="manualWaybillLoading"
|
||
:order-id="manualWaybillOrderId"
|
||
:order-code="manualWaybillOrderCode"
|
||
@closed="resetManualWaybillDialog"
|
||
@submit="submitManualWaybill"
|
||
/>
|
||
<sync-order-ids-form
|
||
v-model="syncOrderIdsDialogVisible"
|
||
:order-count="selectionRows.length"
|
||
:loading="syncOrderIdsLoading"
|
||
@closed="resetSyncOrderIdsDialog"
|
||
@submit="submitSyncOrderIds"
|
||
/>
|
||
<update-address-form
|
||
v-model="updateAddressDialogVisible"
|
||
v-model:form="updateAddressForm"
|
||
:order-count="updateAddressOrderIds.length"
|
||
:loading="updateAddressLoading"
|
||
@closed="resetUpdateAddressDialog"
|
||
@submit="submitUpdateAddress"
|
||
/>
|
||
<update-remark-form
|
||
v-model="updateRemarkDialogVisible"
|
||
v-model:form="updateRemarkForm"
|
||
:order-count="updateRemarkOrderIds.length"
|
||
:loading="updateRemarkLoading"
|
||
@closed="resetUpdateRemarkDialog"
|
||
@submit="submitUpdateRemark"
|
||
/>
|
||
<batch-async-task-form
|
||
v-if="batchAsyncTaskConfig"
|
||
v-model="batchAsyncTaskDialogVisible"
|
||
:title="batchAsyncTaskConfig.title"
|
||
:description="batchAsyncTaskConfig.description"
|
||
:submit-button-text="batchAsyncTaskConfig.submitButtonText"
|
||
:result-count-label="batchAsyncTaskConfig.resultCountLabel"
|
||
:result-ids-label="batchAsyncTaskConfig.resultIdsLabel"
|
||
:order-count="batchAsyncTaskOrderIds.length"
|
||
:loading="batchAsyncTaskLoading"
|
||
:phase="batchAsyncTaskPhase"
|
||
:task-id="batchAsyncTaskProgress.taskId"
|
||
:task-state="batchAsyncTaskProgress.taskState"
|
||
:progress-percent="batchAsyncTaskProgress.progressPercent"
|
||
:total-order-count="batchAsyncTaskProgress.totalOrderCount"
|
||
:processed-order-count="batchAsyncTaskProgress.processedOrderCount"
|
||
:result-order-count="batchAsyncTaskProgress.resultOrderCount"
|
||
:result-order-ids="batchAsyncTaskProgress.resultOrderIds"
|
||
:accept-message="batchAsyncTaskProgress.acceptMessage"
|
||
:error-message="batchAsyncTaskProgress.errorMessage"
|
||
@closed="resetBatchAsyncTaskDialog"
|
||
@submit="submitBatchAsyncTask"
|
||
/>
|
||
|
||
<el-dialog
|
||
v-model="resolveExceptionDialogVisible"
|
||
title="异常订单处理"
|
||
width="520px"
|
||
align-center
|
||
destroy-on-close
|
||
@closed="resetResolveExceptionDialog"
|
||
>
|
||
<el-alert
|
||
type="warning"
|
||
:closable="false"
|
||
show-icon
|
||
title="该操作会将异常订单恢复为正常待处理状态(step: 3 -> 2)。"
|
||
/>
|
||
<el-form label-width="120px" class="resolve-exception-form">
|
||
<el-form-item label="已选订单数">
|
||
<span>{{ resolveExceptionOrderIds.length }} 条</span>
|
||
</el-form-item>
|
||
<el-form-item label="订单ID">
|
||
<div class="resolve-exception-ids">{{ resolveExceptionOrderIds.join(', ') }}</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="resolveExceptionDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="resolveExceptionLoading" @click="submitResolveException">
|
||
确认处理
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<wave-platform-print-preview-dialog
|
||
v-model="batchPrintDialogVisible"
|
||
:error-message="batchPrintErrorMessage"
|
||
:payload="batchPrintPayload"
|
||
:request-meta="batchPrintRequestMeta"
|
||
@refresh="handleBatchPrintRefresh"
|
||
@print-success="onBatchPrintSuccess"
|
||
/>
|
||
</div>
|
||
|
||
<order-export-progress-dialog
|
||
v-model:visible="exportDialogVisible"
|
||
:loading="exportLoading"
|
||
:progress-percent="exportProgressPercent"
|
||
:progress-status="exportProgressStatus"
|
||
:status-label="exportStatusLabel"
|
||
:task-id="exportTaskProgress.taskId"
|
||
:message="exportTaskProgress.message"
|
||
:error="exportTaskProgress.error"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, onUnmounted, computed } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { ArrowDown } from '@element-plus/icons-vue'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import * as indexApi from '@/api/index/index'
|
||
import { orderExpectionOrder } from '@/api/order.expectionorder/orderexpectionorder'
|
||
import { orderPendingOrder } from '@/api/order.pendingorder/orderpendingOrder'
|
||
|
||
import {
|
||
buildPendingStyleColumns,
|
||
expectionColumns,
|
||
expectionOrderAvailableFields,
|
||
expectionOrderbuttonList,
|
||
exceptionToolbarButtons,
|
||
type ToolbarButtonConfig,
|
||
translateOrderField,
|
||
translateInterceptStatus,
|
||
getTagType,
|
||
fillExpressCompanyScanFieldOptions,
|
||
fillStoreScanFieldOptions,
|
||
extractStoreListFromResponse
|
||
} from './config/order-common-config'
|
||
|
||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.vue'
|
||
import OrderDetailDisplayToggle, { type OrderDetailDisplayMode } from './component/OrderDetailDisplayToggle.vue'
|
||
import log from './component/log.vue'
|
||
import { useCreateOrderSession } from './composables/useCreateOrderSession'
|
||
import AllocateExpressForm from './form/AllocateExpressForm.vue'
|
||
import StorageAllocateForm from './form/StorageAllocateForm.vue'
|
||
import UpdateOrderMetaForm from './form/UpdateOrderMetaForm.vue'
|
||
import CloneOrderForm from './form/CloneOrderForm.vue'
|
||
import ManualWaybillForm from './form/ManualWaybillForm.vue'
|
||
import SyncOrderIdsForm from './form/SyncOrderIdsForm.vue'
|
||
import UpdateAddressForm from './form/UpdateAddressForm.vue'
|
||
import UpdateRemarkForm from './form/UpdateRemarkForm.vue'
|
||
import BatchAsyncTaskForm from './form/BatchAsyncTaskForm.vue'
|
||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||
import { createOrderPageExport } from './utils/order-page-export'
|
||
import { buildOrderWhereConditions, parseOrderListResponse, resolveOrderRecheckStatus } from './utils/order-index-helpers'
|
||
import { useOrderListPageCleanup } from './utils/use-order-list-page-cleanup'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import OrderToolbarButtonGroup from './component/OrderToolbarButtonGroup.vue'
|
||
import { createPendingToolbarController } from './utils/toolbar-actions'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import WavePlatformPrintPreviewDialog from '@/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue'
|
||
import { getOrderPrintData } from '@/api/order.print/orderprint'
|
||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||
import { unwrapWavePlatformPrintPayload } from '@/views/order/waveOrder/config/wave-config'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const userStore = useUserStore()
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(expectionOrderAvailableFields)))
|
||
|
||
const activeTab = ref('detail')
|
||
const detailDisplayMode = ref<OrderDetailDisplayMode>('compact')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const actionLoading = ref(false)
|
||
const { openCreateOrderDialog, registerCreateOrderSuccess, unregisterCreateOrderSuccess } =
|
||
useCreateOrderSession()
|
||
const resolveExceptionDialogVisible = ref(false)
|
||
const resolveExceptionLoading = ref(false)
|
||
const resolveExceptionOrderIds = ref<number[]>([])
|
||
|
||
// 批量打印
|
||
const batchPrintDialogVisible = ref(false)
|
||
const batchPrintLoading = ref(false)
|
||
const batchPrintErrorMessage = ref('')
|
||
const batchPrintPayload = ref<WavePlatformPrintDataPayload | null>(null)
|
||
const batchPrintRequestMeta = ref<{ warehouse_id: number; wave_ids: Array<number | string> } | null>(null)
|
||
|
||
const expressCodeOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const platformCodeOptions = ref<Array<{ label: string; value: string }>>([])
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
|
||
const columns = ref(buildPendingStyleColumns(expectionColumns))
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedOrderId = ref<number | string | null>(null)
|
||
const detailVisible = ref(true)
|
||
|
||
const toolbarButtons = exceptionToolbarButtons
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedOrderId.value) || null
|
||
})
|
||
|
||
/** order.expectionOrder.list:where 禁止传入 warehouse_id / warehouseId */
|
||
function sanitizeExpectionListWhere(where: Record<string, any>) {
|
||
const w = { ...where }
|
||
delete w.warehouse_id
|
||
delete w.warehouseId
|
||
return w
|
||
}
|
||
|
||
/** order.expectionOrder.detail:异常页订单明细 */
|
||
function fetchExpectionOrderDetail(data: Record<string, any>) {
|
||
return orderExpectionOrder.detail({
|
||
...data,
|
||
tableType: 'order'
|
||
})
|
||
}
|
||
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
|
||
defaultLowerPercent: 38
|
||
})
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden',
|
||
}))
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
function orderFlagFullText(row: any): string {
|
||
const v = row?.order_flag
|
||
if (v == null) return ''
|
||
return String(v).trim()
|
||
}
|
||
|
||
/** 列表格内省略展示,完整内容见 tooltip,点击复制全文 */
|
||
function orderFlagCellText(row: any): string {
|
||
const t = orderFlagFullText(row)
|
||
if (!t) return '—'
|
||
const max = 48
|
||
return t.length > max ? `${t.slice(0, max)}…` : t
|
||
}
|
||
|
||
async function copyOrderFlag(row: any) {
|
||
const text = orderFlagFullText(row)
|
||
if (!text) {
|
||
ElMessage.warning('当前行无订单标记可复制')
|
||
return
|
||
}
|
||
try {
|
||
if (navigator.clipboard?.writeText) {
|
||
await navigator.clipboard.writeText(text)
|
||
} else {
|
||
throw new Error('no clipboard api')
|
||
}
|
||
ElMessage.success('订单标记已复制到剪贴板')
|
||
} catch {
|
||
try {
|
||
const ta = document.createElement('textarea')
|
||
ta.value = text
|
||
ta.setAttribute('readonly', 'readonly')
|
||
ta.style.position = 'fixed'
|
||
ta.style.left = '-9999px'
|
||
document.body.appendChild(ta)
|
||
ta.select()
|
||
document.execCommand('copy')
|
||
document.body.removeChild(ta)
|
||
ElMessage.success('订单标记已复制到剪贴板')
|
||
} catch {
|
||
ElMessage.error('复制失败,请手动复制')
|
||
}
|
||
}
|
||
}
|
||
|
||
function normalizePositiveIntId(raw: unknown): number | null {
|
||
if (raw === undefined || raw === null || raw === '') return null
|
||
const n = typeof raw === 'number' ? raw : Number(raw)
|
||
if (!Number.isInteger(n) || n <= 0) return null
|
||
return n
|
||
}
|
||
|
||
function normalizeCode(value: unknown) {
|
||
return String(value ?? '').trim()
|
||
}
|
||
|
||
function mapCodeOptions(rawList: any[], codeKeys: string[], nameKeys: string[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const code = normalizeCode(codeKeys.map((k) => item?.[k]).find((v) => v !== undefined && v !== null && v !== ''))
|
||
if (!code || seen.has(code)) continue
|
||
const name = normalizeCode(nameKeys.map((k) => item?.[k]).find((v) => v !== undefined && v !== null && v !== ''))
|
||
result.push({
|
||
value: code,
|
||
label: name ? `${code} - ${name}` : code
|
||
})
|
||
seen.add(code)
|
||
}
|
||
return result
|
||
}
|
||
|
||
function mapNameOptions(rawList: any[], nameKeys: string[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const name = normalizeCode(nameKeys.map((k) => item?.[k]).find((v) => v !== undefined && v !== null && v !== ''))
|
||
if (!name || seen.has(name)) continue
|
||
result.push({ value: name, label: name })
|
||
seen.add(name)
|
||
}
|
||
return result
|
||
}
|
||
|
||
function getSelectedIds(): number[] {
|
||
const ids: number[] = []
|
||
for (const item of selectionRows.value) {
|
||
const id = normalizePositiveIntId(item?.id)
|
||
if (id !== null) ids.push(id)
|
||
}
|
||
return ids
|
||
}
|
||
|
||
onMounted(() => {
|
||
registerCreateOrderSuccess(loadData)
|
||
loadData()
|
||
loadFilterData()
|
||
loadOrderMetaOptions()
|
||
})
|
||
|
||
onUnmounted(() => {
|
||
unregisterCreateOrderSuccess(loadData)
|
||
})
|
||
|
||
useOrderListPageCleanup({ list, selectionRows, selectedOrderId })
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const params = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where: buildExportWhere(),
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC' as const
|
||
}
|
||
}
|
||
const res: any = await orderExpectionOrder.list(params)
|
||
if (res && (res.code === 200 || res.code === 1)) {
|
||
const data = parseOrderListResponse(res)
|
||
list.value = data.list
|
||
pagination.total = data.total
|
||
} else {
|
||
list.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e) {
|
||
list.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('获取待处理异常订单列表失败')
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function buildExportWhere() {
|
||
const where = buildOrderWhereConditions(scanBox.value?.getConditions?.() || {})
|
||
return sanitizeExpectionListWhere(where)
|
||
}
|
||
|
||
const pageExport = createOrderPageExport({
|
||
scopeKey: 'exceptionOrder',
|
||
buildWhere: buildExportWhere,
|
||
buildSort: () => ({
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC'
|
||
}),
|
||
selectionRows,
|
||
columns,
|
||
fileNamePrefix: '异常订单',
|
||
storageKey: 'orderManagement:exceptionOrder:exportTaskId'
|
||
})
|
||
|
||
const {
|
||
exportLoading,
|
||
exportSelectionLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
handleExport,
|
||
handleExportWaybill,
|
||
handleExportItem,
|
||
handleExportSelection
|
||
} = pageExport
|
||
|
||
async function loadFilterData() {
|
||
try {
|
||
const storesRes: any = await indexApi.loadStores({ type: 'order' })
|
||
fillStoreScanFieldOptions(availableFieldsRef, extractStoreListFromResponse(storesRes))
|
||
} catch {
|
||
fillStoreScanFieldOptions(availableFieldsRef, [])
|
||
}
|
||
}
|
||
|
||
async function loadOrderMetaOptions() {
|
||
try {
|
||
const [expressRes, platformRes] = await Promise.all([
|
||
indexApi.getExpressList({}),
|
||
indexApi.getPlatformList({})
|
||
])
|
||
const expressData: any = expressRes?.data
|
||
const platformData: any = platformRes?.data
|
||
const expressRaw = expressData?.list || expressData || []
|
||
const platformRaw = platformData?.list || platformData || []
|
||
expressCodeOptions.value = mapCodeOptions(expressRaw, ['code', 'logistics_code', 'express_code'], ['name', 'logistics_name', 'express_name'])
|
||
platformCodeOptions.value = mapCodeOptions(platformRaw, ['code', 'platform_code'], ['name', 'platform_name'])
|
||
const logisticsField = availableFieldsRef.find((i: any) => i.value === 'logistics_name')
|
||
if (logisticsField) {
|
||
logisticsField.options = mapNameOptions(expressRaw, ['name', 'logistics_name', 'express_name'])
|
||
}
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, expressRaw)
|
||
} catch {
|
||
expressCodeOptions.value = []
|
||
platformCodeOptions.value = []
|
||
const logisticsField = availableFieldsRef.find((i: any) => i.value === 'logistics_name')
|
||
if (logisticsField) logisticsField.options = []
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, [])
|
||
}
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleConditionClear = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
loadData()
|
||
}
|
||
|
||
function onSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
hasSelection.value = selectionRows.value.length > 0
|
||
}
|
||
|
||
function handleRowClick(row: any) {
|
||
selectedOrderId.value = row?.id || null
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function openResolveExceptionDialog() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选需要处理的异常订单')
|
||
return
|
||
}
|
||
const ids = getSelectedIds()
|
||
if (!ids.length) {
|
||
ElMessage.error('选中行缺少有效订单 id,请刷新后重试')
|
||
return
|
||
}
|
||
resolveExceptionOrderIds.value = [...ids]
|
||
resolveExceptionDialogVisible.value = true
|
||
}
|
||
|
||
function resetResolveExceptionDialog() {
|
||
resolveExceptionOrderIds.value = []
|
||
}
|
||
|
||
async function submitResolveException() {
|
||
if (resolveExceptionLoading.value) return
|
||
const ids = [...resolveExceptionOrderIds.value]
|
||
if (!ids.length) {
|
||
ElMessage.warning('没有可处理的异常订单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定将选中的 ${ids.length} 条异常订单恢复为待处理状态吗?`,
|
||
'确认处理',
|
||
{ type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
resolveExceptionLoading.value = true
|
||
try {
|
||
const res = await orderExpectionOrder.resolveException({ ids })
|
||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||
if (!ok) {
|
||
ElMessage.error(res?.message || '异常处理失败')
|
||
return
|
||
}
|
||
const updatedCount = Number(res?.data?.updated_count ?? ids.length) || 0
|
||
ElMessage.success(`异常处理成功 ${updatedCount} 条`)
|
||
resolveExceptionDialogVisible.value = false
|
||
upperTable.value?.clearSelection?.()
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
await loadData()
|
||
} catch {
|
||
ElMessage.error('异常处理失败')
|
||
} finally {
|
||
resolveExceptionLoading.value = false
|
||
}
|
||
}
|
||
|
||
// 统一执行命令
|
||
function handleCommand(commandName: string, subCommand?: string) {
|
||
const handlers: Record<string, Function> = {
|
||
handleExpectionOperation
|
||
}
|
||
const handler = handlers[commandName]
|
||
if (handler) {
|
||
handler(subCommand)
|
||
}
|
||
}
|
||
|
||
const commandLabels: Record<string, string> = {
|
||
'import-exception-tracking': '异常跟踪单导入',
|
||
'export-exception-tracking': '导出异常跟踪单'
|
||
}
|
||
|
||
async function handleExpectionOperation(command: string) {
|
||
const label = commandLabels[command] || '操作'
|
||
exportLoading.value = true
|
||
setTimeout(() => {
|
||
exportLoading.value = false
|
||
ElMessage.success(`${label}成功`)
|
||
}, 1000)
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
hasNoSelection: selectionRows.value.length === 0,
|
||
notSingleSelection: selectionRows.value.length !== 1
|
||
}))
|
||
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const {
|
||
actionMap: pendingToolbarActionMap,
|
||
dialogState: {
|
||
allocateDialogVisible,
|
||
allocateLoading,
|
||
storageDialogVisible,
|
||
storageDialogMode,
|
||
storagePendingOrderIds,
|
||
storageAllocateLoading,
|
||
storageForm,
|
||
storageAllocateRequestId,
|
||
storageAllocateTaskStatus,
|
||
storageAllocateProgressPercent,
|
||
storageAllocateTotalCount,
|
||
storageAllocateSuccessCount,
|
||
storageAllocateFailedCount,
|
||
storageAllocateMessage,
|
||
updateOrderMetaDialogVisible,
|
||
updateOrderMetaDialogMode,
|
||
updateOrderMetaOrderIds,
|
||
updateOrderMetaForm,
|
||
updateOrderMetaOptions,
|
||
updateOrderMetaLoading,
|
||
cloneOrderDialogVisible,
|
||
cloneOrderLoading,
|
||
cloneSourceOrderId,
|
||
cloneSourceOrderCode,
|
||
manualWaybillDialogVisible,
|
||
manualWaybillLoading,
|
||
manualWaybillOrderId,
|
||
manualWaybillOrderCode,
|
||
manualWaybillForm,
|
||
syncOrderIdsDialogVisible,
|
||
syncOrderIdsLoading,
|
||
updateAddressDialogVisible,
|
||
updateAddressLoading,
|
||
updateAddressOrderIds,
|
||
updateAddressForm,
|
||
updateRemarkDialogVisible,
|
||
updateRemarkLoading,
|
||
updateRemarkOrderIds,
|
||
updateRemarkForm,
|
||
batchAsyncTaskDialogVisible,
|
||
batchAsyncTaskLoading,
|
||
batchAsyncTaskConfig,
|
||
batchAsyncTaskOrderIds,
|
||
batchAsyncTaskPhase,
|
||
batchAsyncTaskProgress,
|
||
waveSingleFetchLoading
|
||
},
|
||
submitStorageAllocate,
|
||
submitUpdateOrderMeta,
|
||
submitCloneOrder,
|
||
submitManualWaybill,
|
||
submitSyncOrderIds,
|
||
submitAllocateExpress,
|
||
submitUpdateAddress,
|
||
submitUpdateRemark,
|
||
submitBatchAsyncTask,
|
||
resetAllocateDialog,
|
||
resetStorageAllocateDialog,
|
||
resetUpdateOrderMetaDialog,
|
||
resetCloneOrderDialog,
|
||
resetManualWaybillDialog,
|
||
resetSyncOrderIdsDialog,
|
||
resetUpdateAddressDialog,
|
||
resetUpdateRemarkDialog,
|
||
resetBatchAsyncTaskDialog
|
||
} = createPendingToolbarController({
|
||
loadData,
|
||
handleExport,
|
||
handleExportWaybill,
|
||
handleExportItem,
|
||
handleExportSelection,
|
||
openColumnConfigPanel,
|
||
toggleDetailVisible,
|
||
openCreateOrderDialog,
|
||
getSelectedRows: () => selectionRows.value,
|
||
getSelectedIds,
|
||
clearSelection: () => {
|
||
upperTable.value?.clearSelection?.()
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
},
|
||
pendingApi: orderPendingOrder,
|
||
actionLoading,
|
||
expressCodeOptions,
|
||
platformCodeOptions
|
||
})
|
||
|
||
const toolbarActionMap: Record<string, () => void | Promise<void>> = {
|
||
...pendingToolbarActionMap,
|
||
openResolveExceptionDialog,
|
||
handleBatchPrint
|
||
}
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
exportLoading: exportLoading.value,
|
||
exportSelectionLoading: exportSelectionLoading.value,
|
||
actionLoading: actionLoading.value,
|
||
storageAllocateLoading: storageAllocateLoading.value,
|
||
allocateLoading: allocateLoading.value,
|
||
updateOrderMetaLoading: updateOrderMetaLoading.value,
|
||
cloneOrderLoading: cloneOrderLoading.value,
|
||
manualWaybillLoading: manualWaybillLoading.value,
|
||
syncOrderIdsLoading: syncOrderIdsLoading.value,
|
||
updateAddressLoading: updateAddressLoading.value,
|
||
updateRemarkLoading: updateRemarkLoading.value,
|
||
batchAsyncTaskLoading: batchAsyncTaskLoading.value,
|
||
resolveExceptionLoading: resolveExceptionLoading.value,
|
||
waveSingleFetchLoading: waveSingleFetchLoading.value,
|
||
batchPrintLoading: batchPrintLoading.value
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean(buttonLoadingMap.value[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean(buttonDisabledMap.value[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return buttonLabelMap.value[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
async function handleBatchPrint() {
|
||
const rows = selectionRows.value
|
||
if (!rows.length) {
|
||
ElMessage.warning('请先勾选需要批量打印的订单')
|
||
return
|
||
}
|
||
if (batchPrintLoading.value) return
|
||
|
||
const orderIds: Array<number | string> = []
|
||
for (const row of rows) {
|
||
const id = row?.id
|
||
if (id !== undefined && id !== null && id !== '') {
|
||
orderIds.push(id)
|
||
}
|
||
}
|
||
if (!orderIds.length) {
|
||
ElMessage.warning('当前勾选记录缺少可用的订单 ID')
|
||
return
|
||
}
|
||
|
||
const warehouseId = Number(rows[0]?.warehouse_id ?? userStore.user?.warehouse_id ?? userStore.user?.store_id)
|
||
if (!Number.isFinite(warehouseId) || warehouseId <= 0) {
|
||
ElMessage.error('无法确定仓库 ID,请确认列表中的仓库字段或当前登录仓库上下文')
|
||
return
|
||
}
|
||
|
||
batchPrintRequestMeta.value = { warehouse_id: warehouseId, wave_ids: orderIds }
|
||
batchPrintErrorMessage.value = ''
|
||
batchPrintPayload.value = null
|
||
batchPrintLoading.value = true
|
||
try {
|
||
const res: any = await getOrderPrintData({ order_ids: orderIds })
|
||
if (res?.code !== undefined && res?.code !== null && res?.code !== 1 && res?.code !== 200 && res?.code !== 0) {
|
||
throw new Error(res?.message || '获取打印数据失败')
|
||
}
|
||
batchPrintPayload.value = unwrapWavePlatformPrintPayload(res)
|
||
batchPrintDialogVisible.value = true
|
||
ElMessage.success(res?.message || '已获取打印数据')
|
||
} catch (error: any) {
|
||
batchPrintPayload.value = null
|
||
batchPrintErrorMessage.value = error?.message || '获取打印数据失败'
|
||
batchPrintDialogVisible.value = true
|
||
ElMessage.error(batchPrintErrorMessage.value)
|
||
} finally {
|
||
batchPrintLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleBatchPrintRefresh() {
|
||
const meta = batchPrintRequestMeta.value
|
||
if (!meta) return
|
||
try {
|
||
const res: any = await getOrderPrintData({ order_ids: meta.wave_ids })
|
||
if (res?.code !== undefined && res?.code !== null && res?.code !== 1 && res?.code !== 200 && res?.code !== 0) {
|
||
throw new Error(res?.message || '刷新打印数据失败')
|
||
}
|
||
batchPrintPayload.value = unwrapWavePlatformPrintPayload(res)
|
||
batchPrintErrorMessage.value = ''
|
||
} catch (error: any) {
|
||
batchPrintPayload.value = null
|
||
batchPrintErrorMessage.value = error?.message || '刷新打印数据失败'
|
||
ElMessage.error(batchPrintErrorMessage.value)
|
||
}
|
||
}
|
||
|
||
function onBatchPrintSuccess() {
|
||
loadData()
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "./styles/order-sub.scss";
|
||
|
||
.order-flag-cell {
|
||
display: inline-block;
|
||
max-width: 100%;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
vertical-align: bottom;
|
||
cursor: pointer;
|
||
color: var(--el-color-primary);
|
||
line-height: 1.5;
|
||
border-bottom: 1px dashed var(--el-color-primary-light-5);
|
||
|
||
&:hover {
|
||
color: var(--el-color-primary-dark-2);
|
||
}
|
||
|
||
&:focus-visible {
|
||
outline: 2px solid var(--el-color-primary-light-3);
|
||
outline-offset: 2px;
|
||
border-radius: 2px;
|
||
}
|
||
}
|
||
|
||
.allocate-confirm-text {
|
||
margin: 0;
|
||
font-size: 14px;
|
||
line-height: 1.6;
|
||
color: #303133;
|
||
}
|
||
|
||
.storage-allocate-form {
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.resolve-exception-form {
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.resolve-exception-ids {
|
||
max-height: 96px;
|
||
overflow-y: auto;
|
||
color: #606266;
|
||
line-height: 1.6;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.clone-order-meta {
|
||
margin-top: 12px;
|
||
color: #606266;
|
||
}
|
||
|
||
.clone-order-meta p {
|
||
margin: 4px 0;
|
||
}
|
||
|
||
.detail-page {
|
||
height: 100%;
|
||
overflow-x: hidden;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.order-detail-wrapper,
|
||
.order-picking-wrapper,
|
||
.order-archive-wrapper,
|
||
.order-log-wrapper {
|
||
height: 100%;
|
||
}
|
||
</style>
|
||
|