985 lines
30 KiB
Vue
985 lines
30 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="320px"
|
||
: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" @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>
|
||
|
||
<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>
|
||
</div>
|
||
|
||
<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="待处理异常订单列表"
|
||
: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-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-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-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="items" />
|
||
<el-tab-pane label="配货信息" name="picking" />
|
||
<el-tab-pane label="归档订单" name="archive" />
|
||
<el-tab-pane label="异常记录" name="exceptions" />
|
||
<el-tab-pane label="操作日志" name="logs" />
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<KeepAlive>
|
||
<div v-if="activeTab === 'items'" class="detail-page order-detail-wrapper">
|
||
<workbench-order-detail :row="selectedRow" mode="items" :detail-request="orderExpectionOrder.detail" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'picking'" class="detail-page order-picking-wrapper">
|
||
<p>配货明细加载中...</p>
|
||
</div>
|
||
<div v-else-if="activeTab === 'archive'" class="detail-page order-archive-wrapper">
|
||
<archive-order-panel
|
||
:order-id="selectedRow?.id || null"
|
||
:delivery-order-code="selectedRow?.delivery_order_code || ''"
|
||
/>
|
||
</div>
|
||
<div v-else-if="activeTab === 'exceptions'" class="detail-page">
|
||
<el-alert title="系统异常" type="error" :closable="false" description="库存不足或物流接口调用失败。" />
|
||
</div>
|
||
<div v-else class="detail-page order-log-wrapper">
|
||
<log :data="selectedRow" />
|
||
</div>
|
||
</KeepAlive>
|
||
</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"
|
||
/>
|
||
|
||
<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>
|
||
|
||
<manual-create-pending-order-dialog v-model="manualCreateDialogVisible" @success="loadData" />
|
||
<excel-import-pending-order-dialog v-model="importOrderDialogVisible" @success="loadData" />
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, 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 {
|
||
expectionColumns,
|
||
expectionOrderAvailableFields,
|
||
expectionOrderbuttonList,
|
||
exceptionToolbarButtons,
|
||
type ToolbarButtonConfig,
|
||
translateOrderField,
|
||
formatOrderTime,
|
||
getTagType,
|
||
fillExpressCompanyScanFieldOptions
|
||
} from './config/order-common-config'
|
||
|
||
const EXPORT_TIME_PROPS = new Set([
|
||
'create_at',
|
||
'updated_at',
|
||
'pay_time',
|
||
'place_order_time',
|
||
'operate_time',
|
||
'delivery_time'
|
||
])
|
||
import WorkbenchOrderDetail from './component/WorkbenchOrderDetail.vue'
|
||
import ArchiveOrderPanel from './component/ArchiveOrderPanel.vue'
|
||
import log from './component/log.vue'
|
||
import ManualCreatePendingOrderDialog from './component/ManualCreatePendingOrderDialog.vue'
|
||
import ExcelImportPendingOrderDialog from './component/ExcelImportPendingOrderDialog.vue'
|
||
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 { exportUpperTableRows } from './utils/export'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { createPendingToolbarController } from './utils/toolbar-actions'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(expectionOrderAvailableFields)))
|
||
|
||
const activeTab = ref('items')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const exportLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const actionLoading = ref(false)
|
||
const manualCreateDialogVisible = ref(false)
|
||
const importOrderDialogVisible = ref(false)
|
||
const resolveExceptionDialogVisible = ref(false)
|
||
const resolveExceptionLoading = ref(false)
|
||
const resolveExceptionOrderIds = ref<number[]>([])
|
||
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(expectionColumns)
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedOrderId = ref<number | string | null>(null)
|
||
const detailVisible = ref(true)
|
||
|
||
const quickSearch = ref('')
|
||
const toolbarButtons = exceptionToolbarButtons
|
||
|
||
const scrollContainerRef = ref<HTMLElement | null>(null)
|
||
const isDragging = ref(false)
|
||
const startX = ref(0)
|
||
const scrollLeftStart = 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
|
||
scrollLeftStart.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 = scrollLeftStart.value - walk
|
||
}
|
||
|
||
const handleMouseUp = () => {
|
||
isDragging.value = false
|
||
}
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedOrderId.value) || null
|
||
})
|
||
|
||
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(() => {
|
||
loadData()
|
||
loadFilterData()
|
||
loadOrderMetaOptions()
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = buildWhereConditions(scanBox.value?.getConditions?.() || {})
|
||
if (quickSearch.value) {
|
||
where.delivery_order_code = {
|
||
operator: 'like',
|
||
value: quickSearch.value,
|
||
type: 'text'
|
||
}
|
||
}
|
||
const params = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where,
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC' as const
|
||
}
|
||
}
|
||
const res: any = await orderExpectionOrder.list(params)
|
||
if (res && (res.code === 200 || res.code === 1)) {
|
||
const responseData = res.data || {}
|
||
list.value = responseData.list || []
|
||
pagination.total = responseData.pagination?.total || responseData.total || (responseData.list ? responseData.list.length : 0)
|
||
} 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 buildWhereConditions(rawConditions: Record<string, any>) {
|
||
const where: Record<string, any> = {}
|
||
Object.keys(rawConditions || {}).forEach((key) => {
|
||
const condition = rawConditions[key]
|
||
const normalizedKey = key === 'order_code' ? 'delivery_order_code' : key
|
||
if (condition && typeof condition === 'object' && 'operator' in condition) {
|
||
where[normalizedKey] = Array.isArray(condition.value)
|
||
? { ...condition, value: condition.value[0] ?? '', type: 'text' }
|
||
: condition
|
||
return
|
||
}
|
||
if (condition !== undefined && condition !== null && condition !== '') {
|
||
where[normalizedKey] = {
|
||
operator: 'eq',
|
||
value: Array.isArray(condition) ? condition[0] ?? '' : condition,
|
||
type: 'text'
|
||
}
|
||
}
|
||
})
|
||
return where
|
||
}
|
||
|
||
async function loadFilterData() {
|
||
try {
|
||
const [storesRes]: any = await Promise.all([
|
||
indexApi.loadStores({ type: 'order' })
|
||
])
|
||
if (storesRes?.code === 200) {
|
||
const f = availableFieldsRef.find((i: any) => i.value === 'store_id')
|
||
if (f) f.options = storesRes.stores || []
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
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 onQuickSearch() {
|
||
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,
|
||
handleExport
|
||
}
|
||
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)
|
||
}
|
||
|
||
async function handleExport() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先勾选要导出的订单')
|
||
return
|
||
}
|
||
exportLoading.value = true
|
||
try {
|
||
exportUpperTableRows({
|
||
rows: selectionRows.value,
|
||
columns: columns.value,
|
||
fileName: `异常订单-${Date.now()}.xlsx`,
|
||
transformCell: (prop, value) =>
|
||
EXPORT_TIME_PROPS.has(String(prop)) ? formatOrderTime(value) : translateOrderField(prop, value)
|
||
})
|
||
ElMessage.success('导出完成')
|
||
} catch (error) {
|
||
ElMessage.error('导出失败')
|
||
} finally {
|
||
exportLoading.value = false
|
||
}
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
function openManualCreateDialog() {
|
||
manualCreateDialogVisible.value = true
|
||
}
|
||
|
||
function openImportOrderDialog() {
|
||
importOrderDialogVisible.value = true
|
||
}
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
hasNoSelection: !hasSelection.value,
|
||
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
|
||
},
|
||
submitStorageAllocate,
|
||
submitUpdateOrderMeta,
|
||
submitCloneOrder,
|
||
submitAllocateExpress,
|
||
resetAllocateDialog,
|
||
resetStorageAllocateDialog,
|
||
resetUpdateOrderMetaDialog,
|
||
resetCloneOrderDialog
|
||
} = createPendingToolbarController({
|
||
loadData,
|
||
handleExport,
|
||
openColumnConfigPanel,
|
||
toggleDetailVisible,
|
||
openManualCreateDialog,
|
||
openImportOrderDialog,
|
||
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
|
||
}
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
exportLoading: exportLoading.value,
|
||
actionLoading: actionLoading.value,
|
||
storageAllocateLoading: storageAllocateLoading.value,
|
||
allocateLoading: allocateLoading.value,
|
||
updateOrderMetaLoading: updateOrderMetaLoading.value,
|
||
cloneOrderLoading: cloneOrderLoading.value,
|
||
resolveExceptionLoading: resolveExceptionLoading.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())
|
||
}
|
||
</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;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.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>
|
||
|