951 lines
30 KiB
Vue
951 lines
30 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="orderManagement:pendingOrder"
|
||
width="250px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:initial-conditions="initialConditions"
|
||
: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" ref="toolbarLeftRef" @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 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-pending-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-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-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-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-waybill_codes="{ row }">
|
||
<div v-if="extractWaybillCodes(row).length" class="waybill-cell">
|
||
<div class="waybill-list">
|
||
<span
|
||
v-for="code in extractWaybillCodes(row)"
|
||
:key="code"
|
||
class="waybill-link"
|
||
role="button"
|
||
tabindex="0"
|
||
@click.stop="openWaybillQr(code)"
|
||
@keydown.enter.prevent="openWaybillQr(code)"
|
||
>
|
||
{{ code }}
|
||
</span>
|
||
</div>
|
||
<el-tooltip content="复制快递单号" placement="top">
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
:icon="CopyDocument"
|
||
class="waybill-copy-btn"
|
||
@click.stop="copyWaybillCodes(row)"
|
||
/>
|
||
</el-tooltip>
|
||
</div>
|
||
<span v-else>-</span>
|
||
</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-inspection_status="{ row }">
|
||
<el-tag :type="getTagType('inspection_status', row.inspection_status)" size="small">
|
||
{{ translateOrderField('inspection_status', row.inspection_status) }}
|
||
</el-tag>
|
||
</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="picking" /> -->
|
||
<el-tab-pane label="订单日志" name="logs" />
|
||
<el-tab-pane label="运单作业" name="waybill" />
|
||
<!-- <el-tab-pane label="归档订单" name="archive" /> -->
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<KeepAlive>
|
||
<div v-if="activeTab === 'detail'" class="detail-page order-detail-wrapper">
|
||
<pending-order-detail-panel :row="selectedRow" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'items'" class="detail-page order-detail-wrapper">
|
||
<order-items-detail-panel :row="selectedRow" />
|
||
</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 === 'logs'" class="detail-page order-log-wrapper">
|
||
<log :data="selectedRow" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'waybill'" class="detail-page order-waybill-wrapper">
|
||
<express-waybill-panel :row="selectedRow" table-type="order" />
|
||
</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"
|
||
/>
|
||
<sync-order-ids-form
|
||
v-model="syncOrderIdsDialogVisible"
|
||
:order-count="selectionRows.length"
|
||
:loading="syncOrderIdsLoading"
|
||
@closed="resetSyncOrderIdsDialog"
|
||
@submit="submitSyncOrderIds"
|
||
/>
|
||
|
||
<manual-create-pending-order-dialog v-model="manualCreateDialogVisible" @success="loadData" />
|
||
<excel-import-pending-order-dialog v-model="importOrderDialogVisible" @success="loadData" />
|
||
<qrcode-dialog v-model:visible="qrDialogVisible" :code="currentWaybillCode" />
|
||
</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, computed } from 'vue'
|
||
import { useRoute } from 'vue-router'
|
||
import { ElMessage } from 'element-plus'
|
||
import { CopyDocument } from '@element-plus/icons-vue'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import { orderPendingOrder } from '@/api/order.pendingorder/orderpendingOrder'
|
||
import * as indexApi from '@/api/index/index'
|
||
|
||
import {
|
||
pendingCloums,
|
||
pendingAvailableFields,
|
||
pendingToolbarButtons,
|
||
type ToolbarButtonConfig,
|
||
translateOrderField,
|
||
getTagType,
|
||
fillExpressCompanyScanFieldOptions,
|
||
fillStoreScanFieldOptions,
|
||
extractStoreListFromResponse
|
||
} from './config/order-common-config'
|
||
import ArchiveOrderPanel from './component/ArchiveOrderPanel.vue'
|
||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.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 SyncOrderIdsForm from './form/SyncOrderIdsForm.vue'
|
||
import ExpressWaybillPanel from './component/ExpressWaybillPanel.vue'
|
||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||
import { createOrderPageExport } from './utils/order-page-export'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { createPendingToolbarController } from './utils/toolbar-actions'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import QrcodeDialog from '@/components/QR/qrcode.vue'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const scrollContainerRef = ref<HTMLElement | null>(null)
|
||
const route = useRoute()
|
||
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
|
||
defaultLowerPercent: 38,
|
||
})
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden'
|
||
}))
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(pendingAvailableFields)))
|
||
|
||
const activeTab = ref('detail')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const actionLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
|
||
const buildPendingColumns = () => {
|
||
const source = Array.isArray(pendingCloums) ? [...pendingCloums] : []
|
||
const inspectionColumn = { prop: 'inspection_status', label: '复核', width: '100' }
|
||
if (!source.some((col: any) => String(col?.prop || '') === 'inspection_status')) {
|
||
const insertAfterIndex = source.findIndex((col: any) => String(col?.prop || '') === 'sync_status')
|
||
if (insertAfterIndex >= 0) {
|
||
source.splice(insertAfterIndex + 1, 0, inspectionColumn)
|
||
} else {
|
||
source.push(inspectionColumn)
|
||
}
|
||
}
|
||
if (source.some((col: any) => String(col?.prop || '') === 'print_status')) {
|
||
return source
|
||
}
|
||
|
||
const printColumn = { prop: 'print_status', label: '打印状态', width: '100' }
|
||
const insertAfterIndex = source.findIndex((col: any) => String(col?.prop || '') === 'post_status')
|
||
if (insertAfterIndex >= 0) {
|
||
source.splice(insertAfterIndex + 1, 0, printColumn)
|
||
} else {
|
||
source.push(printColumn)
|
||
}
|
||
return source
|
||
}
|
||
|
||
const columns = ref(buildPendingColumns())
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedOrderId = ref<number | string | null>(null)
|
||
const detailVisible = ref(true)
|
||
|
||
const quickSearch = ref('')
|
||
const toolbarButtons = pendingToolbarButtons
|
||
const qrDialogVisible = ref(false)
|
||
const currentWaybillCode = ref('')
|
||
const initialConditions = computed(() => {
|
||
const waveNo = String(route.query.wave_no || '').trim()
|
||
if (!waveNo) return undefined
|
||
|
||
return {
|
||
type: 'custom',
|
||
conditions: {
|
||
wave_no: {
|
||
field: 'wave_no',
|
||
type: 'text',
|
||
operator: 'eq',
|
||
value: waveNo
|
||
}
|
||
}
|
||
}
|
||
})
|
||
|
||
// Toolbar 滚动与拖拽逻辑
|
||
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 expressCodeOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const platformCodeOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const manualCreateDialogVisible = ref(false)
|
||
const importOrderDialogVisible = ref(false)
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedOrderId.value) || null
|
||
})
|
||
|
||
/** order.pendingOrder.list:where 禁止传入 warehouse_id / warehouseId */
|
||
function sanitizePendingListWhere(where: Record<string, any>) {
|
||
const w = { ...where }
|
||
delete w.warehouse_id
|
||
delete w.warehouseId
|
||
return w
|
||
}
|
||
|
||
/** 规范为接口要求的正整数订单 ID(列表行 id) */
|
||
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
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadData()
|
||
loadOrderMetaOptions()
|
||
loadStoreOptions()
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
|
||
const queryParams = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where: buildExportWhere(),
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC' as const
|
||
}
|
||
}
|
||
|
||
try {
|
||
const res = await orderPendingOrder.list(queryParams)
|
||
if (res && (res.code === 1 || res.code === 200) && res.data) {
|
||
list.value = res.data.list || []
|
||
pagination.total = res.data.pagination?.total || res.data.total || 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
|
||
}
|
||
|
||
function buildExportWhere() {
|
||
let where = buildWhereConditions(scanBox.value?.getConditions?.() || {})
|
||
const routeWaveNo = String(route.query.wave_no || '').trim()
|
||
if (routeWaveNo) {
|
||
where.wave_no = {
|
||
operator: 'eq',
|
||
value: routeWaveNo,
|
||
type: 'text'
|
||
}
|
||
}
|
||
if (quickSearch.value) {
|
||
where.delivery_order_code = {
|
||
operator: 'like',
|
||
value: quickSearch.value,
|
||
type: 'text'
|
||
}
|
||
}
|
||
return sanitizePendingListWhere(where)
|
||
}
|
||
|
||
const pageExport = createOrderPageExport({
|
||
scopeKey: 'pendingOrder',
|
||
buildWhere: buildExportWhere,
|
||
buildSort: () => ({
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC'
|
||
}),
|
||
selectionRows,
|
||
columns,
|
||
fileNamePrefix: '待处理订单',
|
||
storageKey: 'orderManagement:pendingOrder:exportTaskId'
|
||
})
|
||
|
||
const {
|
||
exportLoading,
|
||
exportSelectionLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
handleExport,
|
||
handleExportSelection
|
||
} = pageExport
|
||
|
||
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 openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
function openManualCreateDialog() {
|
||
manualCreateDialogVisible.value = true
|
||
}
|
||
|
||
function openImportOrderDialog() {
|
||
importOrderDialogVisible.value = true
|
||
}
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
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: toolbarActionMap,
|
||
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,
|
||
syncOrderIdsDialogVisible,
|
||
syncOrderIdsLoading,
|
||
waveSingleFetchLoading
|
||
},
|
||
submitStorageAllocate,
|
||
submitUpdateOrderMeta,
|
||
submitCloneOrder,
|
||
submitSyncOrderIds,
|
||
submitAllocateExpress,
|
||
resetAllocateDialog,
|
||
resetStorageAllocateDialog,
|
||
resetUpdateOrderMetaDialog,
|
||
resetCloneOrderDialog,
|
||
resetSyncOrderIdsDialog
|
||
} = createPendingToolbarController({
|
||
loadData,
|
||
handleExport,
|
||
handleExportSelection,
|
||
openColumnConfigPanel,
|
||
toggleDetailVisible,
|
||
openManualCreateDialog,
|
||
openImportOrderDialog,
|
||
getSelectedRows: () => selectionRows.value,
|
||
getSelectedIds,
|
||
pendingApi: orderPendingOrder,
|
||
actionLoading,
|
||
clearSelection: () => {
|
||
upperTable.value?.clearSelection?.()
|
||
selectionRows.value = []
|
||
hasSelection.value = false
|
||
},
|
||
expressCodeOptions,
|
||
platformCodeOptions
|
||
})
|
||
|
||
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,
|
||
syncOrderIdsLoading: syncOrderIdsLoading.value,
|
||
waveSingleFetchLoading: waveSingleFetchLoading.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())
|
||
}
|
||
|
||
function parseWaybillCodes(raw: unknown): string[] {
|
||
if (Array.isArray(raw)) {
|
||
return raw.map((item) => String(item ?? '').trim()).filter(Boolean)
|
||
}
|
||
const text = String(raw ?? '').trim()
|
||
if (!text) return []
|
||
if (text.startsWith('[') && text.endsWith(']')) {
|
||
try {
|
||
const parsed = JSON.parse(text)
|
||
if (Array.isArray(parsed)) {
|
||
return parsed.map((item) => String(item ?? '').trim()).filter(Boolean)
|
||
}
|
||
} catch {
|
||
// ignore invalid json
|
||
}
|
||
}
|
||
if (text.includes(',')) {
|
||
return text.split(',').map((item) => item.trim()).filter(Boolean)
|
||
}
|
||
return [text]
|
||
}
|
||
|
||
function extractWaybillCodes(row: any): string[] {
|
||
const raw = row?.express_numbers ?? row?.waybill_codes ?? row?.express_code
|
||
return parseWaybillCodes(raw)
|
||
}
|
||
|
||
function openWaybillQr(code: string) {
|
||
if (!code) return
|
||
currentWaybillCode.value = code
|
||
qrDialogVisible.value = true
|
||
}
|
||
|
||
function waybillCodesText(row: any): string {
|
||
return extractWaybillCodes(row).join(',')
|
||
}
|
||
|
||
async function copyWaybillCodes(row: any) {
|
||
const text = waybillCodesText(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 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
|
||
}
|
||
|
||
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)
|
||
const platformField = availableFieldsRef.find((i: any) => i.value === 'sys_platform_name')
|
||
if (platformField) {
|
||
platformField.options = mapNameOptions(platformRaw, ['name', 'platform_name'])
|
||
}
|
||
} catch {
|
||
expressCodeOptions.value = []
|
||
platformCodeOptions.value = []
|
||
const logisticsField = availableFieldsRef.find((i: any) => i.value === 'logistics_name')
|
||
if (logisticsField) logisticsField.options = []
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, [])
|
||
const platformField = availableFieldsRef.find((i: any) => i.value === 'sys_platform_name')
|
||
if (platformField) platformField.options = []
|
||
}
|
||
}
|
||
|
||
async function loadStoreOptions() {
|
||
try {
|
||
const storesRes: any = await indexApi.loadStores({ type: 'order' })
|
||
fillStoreScanFieldOptions(availableFieldsRef, extractStoreListFromResponse(storesRes))
|
||
} catch {
|
||
fillStoreScanFieldOptions(availableFieldsRef, [])
|
||
}
|
||
}
|
||
|
||
function getSelectedIds(): number[] {
|
||
const ids: number[] = []
|
||
for (const item of selectionRows.value) {
|
||
const n = normalizePositiveIntId(item?.id)
|
||
if (n !== null) ids.push(n)
|
||
}
|
||
return ids
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "./styles/order-sub.scss";
|
||
|
||
.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; /* Firefox */
|
||
&::-webkit-scrollbar {
|
||
display: none; /* Chrome/Safari */
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
.detail-page {
|
||
height: 100%;
|
||
overflow-x: hidden;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.order-detail-wrapper,
|
||
.order-picking-wrapper,
|
||
.order-archive-wrapper,
|
||
.order-log-wrapper,
|
||
.order-waybill-wrapper {
|
||
height: 100%;
|
||
}
|
||
|
||
.waybill-cell {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 4px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.waybill-link {
|
||
color: var(--el-color-primary);
|
||
cursor: pointer;
|
||
}
|
||
|
||
.waybill-list {
|
||
display: flex;
|
||
flex: 1;
|
||
flex-direction: column;
|
||
gap: 2px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.waybill-copy-btn {
|
||
flex-shrink: 0;
|
||
padding: 0;
|
||
height: auto;
|
||
}
|
||
</style>
|
||
|