557 lines
18 KiB
Vue
557 lines
18 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="orderManagement:outboundOrder"
|
||
width="220px"
|
||
: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"
|
||
/>
|
||
</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-outbound-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-post_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('post_status', row.post_status))">
|
||
{{ translateOrderField('post_status', row.post_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-storage_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('storage_status', row.storage_status))">
|
||
{{ translateOrderField('storage_status', row.storage_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-print_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('print_status', row.print_status))">
|
||
{{ translateOrderField('print_status', row.print_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-pick_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('pick_status', row.pick_status))">
|
||
{{ translateOrderField('pick_status', row.pick_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-pack_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('pack_status', row.pack_status))">
|
||
{{ translateOrderField('pack_status', row.pack_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-sync_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('sync_status', row.sync_status))">
|
||
{{ translateOrderField('sync_status', row.sync_status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-is_urgency="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('is_urgency', row.is_urgency))">
|
||
{{ translateOrderField('is_urgency', row.is_urgency) }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-outbound_status="{ row }">
|
||
<span :class="getStatusTextClass(getTagType('outbound_status', row.outbound_status))">
|
||
{{ translateOrderField('outbound_status', row.outbound_status) }}
|
||
</span>
|
||
</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-tab-pane label="运单作业" name="waybill" />
|
||
<el-tab-pane label="手动出库" name="manualOutbound" />
|
||
</el-tabs>
|
||
</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="fetchOutboundOrderDetail" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'items'" :key="`items-${selectedOrderId}`" class="detail-page order-detail-wrapper">
|
||
<order-items-detail-panel :key="selectedOrderId" :row="selectedRow" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'logs'" :key="`logs-${selectedOrderId}`" class="detail-page order-log-wrapper">
|
||
<log :key="selectedOrderId" :data="selectedRow" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'waybill'" :key="`waybill-${selectedOrderId}`" class="detail-page order-waybill-wrapper">
|
||
<express-waybill-panel :key="selectedOrderId" :row="selectedRow" table-type="order" @data-changed="loadData" />
|
||
</div>
|
||
<div v-else :key="`manual-${selectedOrderId}`" class="detail-page order-manual-outbound-wrapper">
|
||
<outbound-manual-outbound-form
|
||
:key="selectedOrderId"
|
||
ref="manualOutboundRef"
|
||
:orderId="selectedOrderId"
|
||
@success="handleManualOutboundSuccess"
|
||
@loading-change="handleManualLoadingChange"
|
||
/>
|
||
</div>
|
||
<el-alert
|
||
v-if="activeTab === 'manualOutbound' && manualResult"
|
||
type="success"
|
||
:closable="false"
|
||
show-icon
|
||
class="manual-result"
|
||
:title="`已处理 ${manualResult.totalSelected} 条,创建 ${manualResult.totalCreated} 条,跳过 ${manualResult.totalSkipped} 条,超时 ${manualResult.totalTimeout} 条`"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div class="no-selection" v-else :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<order-export-columns-dialog
|
||
v-model:visible="exportColumnsDialogVisible"
|
||
:mode="exportColumnsMode"
|
||
:loading="exportColumnsLoading"
|
||
:storage-key="exportColumnsStorageKey"
|
||
@confirm="confirmExportColumns"
|
||
/>
|
||
|
||
<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 { computed, nextTick, onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import * as indexApi from '@/api/index/index'
|
||
import { orderOutboundOrder } from '@/api/order.outboundorder/orderoutboundOrder'
|
||
import {
|
||
buildPendingStyleColumns,
|
||
outboundAvailableFields,
|
||
outboundColumns,
|
||
outboundToolbarButtons,
|
||
type ToolbarButtonConfig,
|
||
translateOrderField,
|
||
getTagType,
|
||
getStatusTextClass,
|
||
fillExpressCompanyScanFieldOptions,
|
||
fillStoreScanFieldOptions,
|
||
extractStoreListFromResponse
|
||
} from './config/order-common-config'
|
||
import log from './component/log.vue'
|
||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.vue'
|
||
import OutboundManualOutboundForm from './component/OutboundManualOutboundForm.vue'
|
||
import ExpressWaybillPanel from './component/ExpressWaybillPanel.vue'
|
||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||
import OrderExportColumnsDialog from './component/OrderExportColumnsDialog.vue'
|
||
import { createOrderPageExport } from './utils/order-page-export'
|
||
import { buildOrderWhereConditions, parseOrderListResponse } 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 { createSimpleListToolbarController } from './utils/toolbar-actions'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const manualOutboundRef = ref<any>(null)
|
||
const presetTree = ref<any[]>([])
|
||
const activeTab = ref('detail')
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const manualLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(outboundAvailableFields)))
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const columns = ref(buildPendingStyleColumns(outboundColumns))
|
||
const selectionRows = ref<any[]>([])
|
||
const selectedOrderId = ref<number | string | null>(null)
|
||
const detailVisible = ref(true)
|
||
const toolbarButtons = outboundToolbarButtons
|
||
|
||
const manualResult = ref<any>(null)
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((item: any) => item.id === selectedOrderId.value) || null
|
||
})
|
||
|
||
/** order.outboundOrder.detail:待出库页订单明细 */
|
||
function fetchOutboundOrderDetail(data: Record<string, any>) {
|
||
return orderOutboundOrder.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
|
||
}
|
||
|
||
/** order.outboundOrder.list:where 禁止传入 warehouse_id / warehouseId */
|
||
function sanitizeOutboundListWhere(where: Record<string, any>) {
|
||
const w = { ...where }
|
||
delete w.warehouse_id
|
||
delete w.warehouseId
|
||
return w
|
||
}
|
||
|
||
function buildWhere() {
|
||
const where = buildOrderWhereConditions(scanBox.value?.getConditions?.() || {})
|
||
return sanitizeOutboundListWhere(where)
|
||
}
|
||
|
||
const pageExport = createOrderPageExport({
|
||
scopeKey: 'outboundOrder',
|
||
buildWhere,
|
||
buildSort: () => ({
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC'
|
||
}),
|
||
selectionRows,
|
||
columns,
|
||
fileNamePrefix: '待出库订单',
|
||
storageKey: 'orderManagement:outboundOrder:exportTaskId'
|
||
})
|
||
|
||
const {
|
||
exportLoading,
|
||
exportSelectionLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
handleExport,
|
||
handleExportWaybill,
|
||
handleExportItem,
|
||
handleExportSelection,
|
||
handleExportSelectionWaybill,
|
||
handleExportSelectionItem,
|
||
exportColumnsDialogVisible,
|
||
exportColumnsMode,
|
||
exportColumnsLoading,
|
||
exportColumnsStorageKey,
|
||
confirmExportColumns
|
||
} = pageExport
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const res: any = await orderOutboundOrder.list({
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where: buildWhere(),
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC' as const
|
||
}
|
||
})
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
const data = parseOrderListResponse(res)
|
||
list.value = data.list
|
||
pagination.total = data.total
|
||
} else {
|
||
list.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (error) {
|
||
list.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('获取待出库订单失败')
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
loadData()
|
||
}
|
||
|
||
async function handleToolbarManualOutbound() {
|
||
if (!selectedOrderId.value) {
|
||
ElMessage.warning('请先选择订单')
|
||
return
|
||
}
|
||
if (activeTab.value !== 'manualOutbound') {
|
||
activeTab.value = 'manualOutbound'
|
||
await nextTick()
|
||
}
|
||
await manualOutboundRef.value?.submitManualOutbound?.()
|
||
}
|
||
|
||
function handleManualOutboundSuccess(data: any) {
|
||
manualResult.value = data || null
|
||
loadData()
|
||
}
|
||
|
||
function handleManualLoadingChange(value: boolean) {
|
||
manualLoading.value = value
|
||
}
|
||
|
||
function handleRowClick(row: any) {
|
||
selectedOrderId.value = row?.id || null
|
||
}
|
||
|
||
function onSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadData()
|
||
loadOrderMetaOptions()
|
||
})
|
||
|
||
useOrderListPageCleanup({
|
||
list,
|
||
selectionRows,
|
||
selectedOrderId,
|
||
onCleanup: () => {
|
||
manualResult.value = null
|
||
}
|
||
})
|
||
|
||
function normalizeOptionValue(value: unknown) {
|
||
return String(value ?? '').trim()
|
||
}
|
||
|
||
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 = normalizeOptionValue(nameKeys.map((k) => item?.[k]).find((v) => v !== undefined && v !== null && v !== ''))
|
||
if (!name || seen.has(name)) continue
|
||
result.push({ label: name, value: name })
|
||
seen.add(name)
|
||
}
|
||
return result
|
||
}
|
||
|
||
async function loadOrderMetaOptions() {
|
||
try {
|
||
const [expressRes, platformRes, storesRes] = await Promise.all([
|
||
indexApi.getExpressList({ systemOnly: 'true' }),
|
||
indexApi.getPlatformList({ systemOnly: 'true' }),
|
||
indexApi.loadStores()
|
||
])
|
||
const expressData: any = expressRes?.data
|
||
const platformData: any = platformRes?.data
|
||
const expressRaw = expressData?.list || expressData || []
|
||
const platformRaw = platformData?.list || platformData || []
|
||
|
||
const logisticsField = availableFieldsRef.find((i: any) => i.value === 'logistics_name')
|
||
if (logisticsField) logisticsField.options = mapNameOptions(expressRaw, ['name', 'logistics_name', 'express_name'])
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, expressRaw)
|
||
fillStoreScanFieldOptions(availableFieldsRef, extractStoreListFromResponse(storesRes))
|
||
const platformField = availableFieldsRef.find((i: any) => i.value === 'sys_platform_name')
|
||
if (platformField) platformField.options = mapNameOptions(platformRaw, ['name', 'platform_name'])
|
||
} catch {
|
||
const logisticsField = availableFieldsRef.find((i: any) => i.value === 'logistics_name')
|
||
if (logisticsField) logisticsField.options = []
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, [])
|
||
fillStoreScanFieldOptions(availableFieldsRef, [])
|
||
const platformField = availableFieldsRef.find((i: any) => i.value === 'sys_platform_name')
|
||
if (platformField) platformField.options = []
|
||
}
|
||
}
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
exportLoading: exportLoading.value,
|
||
exportSelectionLoading: exportSelectionLoading.value,
|
||
manualLoading: manualLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
hasNoOutboundTarget: selectedOrderId.value == null || selectedOrderId.value === '',
|
||
hasNoSelection: selectionRows.value.length === 0
|
||
}))
|
||
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
const { actionMap: baseToolbarActionMap } = createSimpleListToolbarController({
|
||
loadData,
|
||
handleExport,
|
||
handleExportWaybill,
|
||
handleExportItem,
|
||
handleExportSelection,
|
||
handleExportSelectionWaybill,
|
||
handleExportSelectionItem,
|
||
openColumnConfigPanel,
|
||
toggleDetailVisible
|
||
})
|
||
|
||
const toolbarActionMap: Record<string, () => void | Promise<void>> = {
|
||
...baseToolbarActionMap,
|
||
handleToolbarManualOutbound: () => handleToolbarManualOutbound()
|
||
}
|
||
|
||
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";
|
||
|
||
.manual-result {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
/* 详情区外壳只保留左右 10px(订单明细/商品明细/订单日志面板自带 padding: 6px 10px 8px),
|
||
与 stock/external_stock 各面板保持一致 */
|
||
.order-sub-container .main-content .lower-level .detail-container {
|
||
padding: 0 10px;
|
||
}
|
||
|
||
.detail-page {
|
||
height: 100%;
|
||
overflow-x: hidden;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.order-detail-wrapper,
|
||
.order-log-wrapper,
|
||
.order-waybill-wrapper,
|
||
.order-manual-outbound-wrapper {
|
||
height: 100%;
|
||
}
|
||
</style>
|