- task-progress 新增 tags 表单字段类型与 SelectedTags 组件,任务弹窗可展示 已选订单/运单/出库单标签并支持逐个移除,样式对齐「编辑投递计划」输入行 - 更新备注、更新订单备注/地址、同步订单号、分配储位、批量异步任务等表单, 以及待处理/异常/复核/波次面板接入该能力,提交前可核对并调整已选项 - 新增 orderTagItems 工具:按行或按 ids 顺序生成标签,兼容 id / order_id 与 delivery_order_code / order_code 等字段差异 - waybill.warehouse 新增 updateReceive、updateReceiveTaskProgress 异步接口, 运单页新增「更新揽收状态」工具栏按钮,接入任务进度轮询、结果汇总与列表刷新 - 库存批量编辑、出库单批量作废、收货列表等页面同步接入已选项标签展示 - UnifiedTaskProgressDialog 补充 remove-field-item 事件透传,保持各任务弹窗行为一致
1197 lines
39 KiB
Vue
1197 lines
39 KiB
Vue
<!--
|
||
╔══════════════════════════════════════════════════════════════╗
|
||
║ 【页面模板 v2】— 基于 waveOrder2 架构设计 ║
|
||
╚══════════════════════════════════════════════════════════════╝
|
||
|
||
===== 快速复制使用 =====
|
||
1. 复制整个 views/mode/ 文件夹 → 重命名为你的页面名(如 views/order/myPage/)
|
||
2. 修改 defineOptions name(如 'MyPage')
|
||
3. 编辑 config/template-config.ts:
|
||
a. 在 FIELD_DICT 中添加页面字段
|
||
b. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||
c. 在 TabPageApiConfig 中接入真实接口
|
||
4. 在 router/map.ts 中添加路由
|
||
|
||
===== 页面结构 =====
|
||
┌─────────────────────────────────────────────────────────┐
|
||
│ TabArea(多标签页切换,可关闭) │
|
||
├──────────┬──────────────────────────────────────────────┤
|
||
│ ScanBox │ OrderToolbarButtonGroup(工具栏按钮组) │
|
||
│ 筛选面板 │ ┌──────────────────────────────────────────┐│
|
||
│ │ │ UpperTable(表格) ││
|
||
│ │ │ - OperationCellRenderer(操作列) ││
|
||
│ │ ├──────────────────────────────────────────┤│
|
||
│ │ │ 分隔条(可拖拽) ││
|
||
│ │ ├──────────────────────────────────────────┤│
|
||
│ │ │ DetailPanel / LogPanel(明细/日志面板) ││
|
||
│ │ └──────────────────────────────────────────┘│
|
||
└──────────┴──────────────────────────────────────────────┘
|
||
-->
|
||
<template>
|
||
<div class="page-wrapper" :style="{ height: containerHeight }">
|
||
<!-- ===== 多标签模式:显示顶部标签栏 ===== -->
|
||
<template v-if="PAGE_CONFIG.showTabArea && !PAGE_CONFIG.singlePage">
|
||
<div class="tab-section">
|
||
<TabArea
|
||
:tabs="tabList"
|
||
:default-active="activeTabName"
|
||
page-key="express.waybill"
|
||
@tab-change="handleTabChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- ===== 主内容区 ===== -->
|
||
<div class="main-container">
|
||
<div class="order-sub-container">
|
||
<!-- 左侧:ScanBox 筛选面板 -->
|
||
<ScanBox
|
||
ref="scanBoxRef"
|
||
:cache-key="currentScanBoxCacheKey"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="dynamicScanBoxFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<!-- 右侧:内容区 -->
|
||
<div class="main-content">
|
||
<transition name="tab-fade" mode="out-in">
|
||
<div :key="activeTabName" class="tab-content-inner">
|
||
<!-- 工具栏按钮组 -->
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<OrderToolbarButtonGroup
|
||
:buttons="currentToolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 上下分栏区域:详情面板启用时才显示分栏 + 详情 -->
|
||
<template v-if="PAGE_CONFIG.enableDetailPanel">
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<!-- 上半:表格 -->
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<UpperTable
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`template-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'id'"
|
||
:columns="currentColumns"
|
||
table-size="small"
|
||
:pagination="pagination"
|
||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||
:show-selection="currentTabConfig?.upperTable.showSelection ?? true"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@sort-change="handleSortChange"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<!-- 动态列插槽:根据 columnSlots 配置自动渲染 -->
|
||
<template
|
||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||
:key="`columnSlots-${colProp}`"
|
||
#[`column-${colProp}`]="{ row }"
|
||
>
|
||
<!-- 操作列:渲染操作按钮 -->
|
||
<OperationCellRenderer
|
||
v-if="slotConfig.type === 'operation'"
|
||
:buttons="currentTabConfig?.operationButtons"
|
||
:row="row"
|
||
@operation-action="handleOperationAction"
|
||
/>
|
||
<!-- 其他列:标签/文本渲染 -->
|
||
<ColumnCellRenderer
|
||
v-else
|
||
:config="slotConfig"
|
||
:value="row[colProp]"
|
||
/>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
|
||
<!-- 分隔条(可拖拽) -->
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
|
||
<!-- 下半:明细面板 -->
|
||
<div v-if="selectedRow" class="lower-level" :style="lowerPaneStyle">
|
||
<div class="detail-header">
|
||
<el-tabs v-model="activeDetailTab" class="detail-tab">
|
||
<el-tab-pane
|
||
v-for="tab in currentDetailTabs"
|
||
:key="tab.name"
|
||
:label="tab.label"
|
||
:name="tab.name"
|
||
/>
|
||
</el-tabs>
|
||
</div>
|
||
<div class="detail-container">
|
||
<component
|
||
:is="activeDetailTabComponent"
|
||
:row="selectedDetail"
|
||
:detail-config="currentDetailConfig"
|
||
:api-method="currentDetailTabApiMethod"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 未选中行时的占位 -->
|
||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 详情面板禁用:表格占满全高 -->
|
||
<template v-else>
|
||
<div class="upper-wrapper upper-wrapper--full">
|
||
<UpperTable
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`template-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'id'"
|
||
:columns="currentColumns"
|
||
table-size="small"
|
||
:pagination="pagination"
|
||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||
:show-selection="currentTabConfig?.upperTable.showSelection ?? false"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@current-change="handleRowClick"
|
||
@row-click="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
@sort-change="handleSortChange"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<template
|
||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||
:key="`columnSlots-${colProp}`"
|
||
#[`column-${colProp}`]="{ row }"
|
||
>
|
||
<OperationCellRenderer
|
||
v-if="slotConfig.type === 'operation'"
|
||
:buttons="currentTabConfig?.operationButtons"
|
||
:row="row"
|
||
@operation-action="handleOperationAction"
|
||
/>
|
||
<ColumnCellRenderer
|
||
v-else
|
||
:config="slotConfig"
|
||
:value="row[colProp]"
|
||
/>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</transition>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ===== 功能按钮表单(pages/ 目录下的组件) ===== -->
|
||
<!-- 运单批量转入退件登记(returnUnpack.transferByWaybills):入参取自勾选运单的 id -->
|
||
<TransferByWaybillsDialog
|
||
v-model:visible="transferByWaybillsVisible"
|
||
:rows="selectedRows"
|
||
@success="handleTransferByWaybillsSuccess"
|
||
/>
|
||
|
||
<AsyncExportProgressDialog
|
||
v-model:visible="exportDialogVisible"
|
||
title="运单导出"
|
||
:loading="exportLoading"
|
||
:progress-percent="exportProgressPercent"
|
||
:progress-status="exportProgressStatus"
|
||
:status-label="exportStatusLabel"
|
||
:task-id="exportTaskProgress.taskId"
|
||
:message="exportTaskProgress.message"
|
||
:error="exportTaskProgress.error"
|
||
:meta="exportTaskProgress"
|
||
/>
|
||
|
||
<!-- 批量更新揽收状态(waybill.warehouse.updateReceive 异步任务) -->
|
||
<TaskProgressDialog
|
||
v-if="receiveProgressVisible"
|
||
:visible="receiveProgressVisible"
|
||
title="更新揽收状态"
|
||
:polling="receiveProgressPolling"
|
||
:task-id="receiveProgressState.taskId"
|
||
:progress-percent="receiveProgressState.progress"
|
||
:status-label="receiveProgressStatusLabel"
|
||
:error-text="receiveProgressState.error"
|
||
@close="closeReceiveProgress"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
// ============================================================
|
||
// ★★★ 第一步:修改组件名 ★★★
|
||
// ============================================================
|
||
defineOptions({ name: 'WaybillWarehouse' })
|
||
|
||
import { ref, computed, onMounted, reactive } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { getExpressList, getPlatformList, loadStores } from '@/api/index/index'
|
||
import TabArea from '@/components/TabArea/index.vue'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||
import OperationCellRenderer from './components/OperationCellRenderer.vue'
|
||
import TransferByWaybillsDialog from './components/TransferByWaybillsDialog.vue'
|
||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||
import TaskProgressDialog from '@/components/TaskProgressDialog.vue'
|
||
import OrderToolbarButtonGroup from '@/components/ToolbarButtonGroup/index.vue'
|
||
import { waybillWarehouseDetail } from '@/api/waybill.warehouse'
|
||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||
import { useTaskProgress } from '@/composables/useTaskProgress'
|
||
import {
|
||
extractStoreListFromResponse,
|
||
mapExpressListToCompanySelectOptions,
|
||
mapStoreListToSelectOptions
|
||
} from '@/utils/storeScanOptions'
|
||
import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/components/ToolbarButtonGroup/types'
|
||
import {
|
||
PAGE_CONFIG,
|
||
tabPages,
|
||
resolveTabConfig,
|
||
getTabToolbarButtons,
|
||
buildWhereConditions,
|
||
type TabPageConfig,
|
||
type DetailTabConfig,
|
||
type ToolbarButtonConfig,
|
||
} from './config/template-config'
|
||
|
||
// ============================================================
|
||
// 容器高度
|
||
// ============================================================
|
||
const settingsStore = useSettingsStore()
|
||
const containerHeight = computed(() =>
|
||
'100%' /* 高度由布局层(.app-router-page 的 flex:1)提供,不再自己算 vh */
|
||
)
|
||
|
||
// ============================================================
|
||
// 标签页
|
||
// ============================================================
|
||
const tabList = computed(() =>
|
||
tabPages.map((t) => ({ name: t.name, label: t.label }))
|
||
)
|
||
const activeTabName = ref(tabPages[0]?.name ?? 'tab1')
|
||
|
||
/** 当前激活标签页的完整配置 */
|
||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||
const raw = tabPages.find((t) => t.name === activeTabName.value)
|
||
if (!raw) return undefined
|
||
return resolveTabConfig(raw)
|
||
})
|
||
|
||
/** 当前 ScanBox 缓存 key */
|
||
const currentScanBoxCacheKey = computed(
|
||
() => currentTabConfig.value?.scanBoxCacheKey ?? 'template-default'
|
||
)
|
||
|
||
/** 当前 ScanBox 筛选字段(支持动态选项注入) */
|
||
const currentScanBoxFields = computed(
|
||
() => currentTabConfig.value?.scanBoxFields ?? []
|
||
)
|
||
|
||
/** 动态 ScanBox 字段(深拷贝后可注入 API 选项) */
|
||
const dynamicScanBoxFields = ref<Record<string, any>[]>([])
|
||
|
||
/** 同步当前标签页的 ScanBox 字段到动态副本 */
|
||
function syncScanBoxFields() {
|
||
dynamicScanBoxFields.value = JSON.parse(JSON.stringify(currentScanBoxFields.value))
|
||
}
|
||
|
||
/** 注入 ScanBox 下拉选项 */
|
||
function injectScanBoxOptions(fieldValue: string, options: { label: string; value: string | number }[]) {
|
||
const field = dynamicScanBoxFields.value.find((f: any) => f.value === fieldValue)
|
||
if (field) {
|
||
field.options = options
|
||
}
|
||
}
|
||
|
||
/** 加载物流编码、平台、货主下拉选项 */
|
||
async function loadScanBoxOptions() {
|
||
try {
|
||
const [expressRes, platformRes, storesRes] = await Promise.all([
|
||
getExpressList({ systemOnly: true }),
|
||
getPlatformList({ systemOnly: true }),
|
||
loadStores()
|
||
])
|
||
const expressPayload = expressRes?.data ?? expressRes
|
||
const expressRaw: any[] = Array.isArray(expressPayload)
|
||
? expressPayload
|
||
: expressPayload?.list ?? expressPayload?.items ?? expressPayload?.records ?? []
|
||
const platformPayload = platformRes?.data ?? platformRes
|
||
const platformRaw: any[] = Array.isArray(platformPayload)
|
||
? platformPayload
|
||
: platformPayload?.list ?? platformPayload?.items ?? platformPayload?.records ?? []
|
||
const storesRaw = extractStoreListFromResponse(storesRes)
|
||
|
||
const expressOptions = mapExpressListToCompanySelectOptions(expressRaw)
|
||
|
||
const platformOptions = platformRaw.map((item: any) => ({
|
||
label: `${item.code ?? item.platform_code ?? ''} — ${item.name ?? item.platform_name ?? ''}`,
|
||
value: String(item.code ?? item.platform_code ?? '')
|
||
})).filter((opt: any) => opt.value)
|
||
|
||
const storeOptions = mapStoreListToSelectOptions(storesRaw)
|
||
|
||
injectScanBoxOptions('logistics_code', expressOptions)
|
||
injectScanBoxOptions('platform_code', platformOptions)
|
||
injectScanBoxOptions('store_name', storeOptions)
|
||
} catch (error) {
|
||
console.error('[WaybillWarehouse] 加载筛选选项失败:', error)
|
||
ElMessage.error('加载筛选选项失败,请刷新页面重试')
|
||
}
|
||
}
|
||
|
||
/** 当前表格列 */
|
||
const currentColumns = computed(
|
||
() => currentTabConfig.value?.upperTable.columns ?? []
|
||
)
|
||
|
||
/** 当前列插槽配置 */
|
||
const currentColumnSlots = computed(
|
||
() => currentTabConfig.value?.columnSlots ?? {}
|
||
)
|
||
|
||
/** 当前明细面板配置 */
|
||
const currentDetailConfig = computed(
|
||
() => currentTabConfig.value?.detailConfig ?? []
|
||
)
|
||
|
||
/** 当前明细标签页列表 */
|
||
const currentDetailTabs = computed<DetailTabConfig[]>(
|
||
() => currentTabConfig.value?.detailTabs ?? []
|
||
)
|
||
|
||
/** 当前激活的明细标签页组件 */
|
||
const activeDetailTabComponent = computed(() => {
|
||
const tab = currentDetailTabs.value.find(
|
||
(t) => t.name === activeDetailTab.value
|
||
)
|
||
return tab?.component ?? null
|
||
})
|
||
|
||
/** 当前激活明细标签页对应的 API 方法 */
|
||
const currentDetailTabApiMethod = computed(() => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api) return undefined
|
||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||
if (!tab) return undefined
|
||
|
||
let componentCfg: unknown
|
||
switch (tab.componentKey) {
|
||
case 'DetailPanel':
|
||
componentCfg = cfg.api.detail
|
||
break
|
||
case 'LogPanel':
|
||
componentCfg = cfg.api.log
|
||
break
|
||
default:
|
||
return undefined
|
||
}
|
||
|
||
if (typeof componentCfg === 'function') {
|
||
return componentCfg
|
||
}
|
||
return undefined
|
||
})
|
||
|
||
// ============================================================
|
||
// 工具栏按钮系统
|
||
// ============================================================
|
||
|
||
/** 当前标签页的工具栏按钮列表 */
|
||
const currentToolbarButtons = computed<OrderToolbarButtonConfig[]>(() => {
|
||
const btns = getTabToolbarButtons(activeTabName.value)
|
||
return btns.map((btn: ToolbarButtonConfig) => ({
|
||
key: btn.key,
|
||
label: btn.label,
|
||
size: btn.size,
|
||
type: btn.type,
|
||
plain: btn.plain,
|
||
loadingKey: btn.loadingKey,
|
||
disabledKey: btn.disabledKey,
|
||
action: btn.action,
|
||
dynamicLabelKey: btn.dynamicLabelKey,
|
||
buttonType: btn.buttonType,
|
||
dropdownOptions: btn.dropdownOptions
|
||
}))
|
||
})
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
noSelection: selectedRows.value.length === 0
|
||
}))
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
loading: loading.value,
|
||
exportLoading: exportLoading.value,
|
||
receiveLoading: receiveLoading.value
|
||
}))
|
||
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.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
|
||
}
|
||
|
||
// ============================================================
|
||
// 工具栏动作分发
|
||
// ============================================================
|
||
|
||
const {
|
||
exportLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
submitExportTask
|
||
} = useAsyncExportTask({
|
||
storageKey: 'waybill:warehouse:exportTaskId',
|
||
submitExport: (payload) => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api?.export) throw new Error('导出接口未配置')
|
||
return cfg.api.export(payload)
|
||
},
|
||
queryProgress: (params) => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api?.exportProgress) throw new Error('导出进度接口未配置')
|
||
return cfg.api.exportProgress(params)
|
||
}
|
||
})
|
||
|
||
function buildExportAllPayload() {
|
||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||
const where = buildWhereConditions(conditions)
|
||
return {
|
||
where,
|
||
sort: currentSort.prop
|
||
? { field: currentSort.prop, order: currentSort.order === 'ascending' ? 'asc' : 'desc' }
|
||
: undefined
|
||
}
|
||
}
|
||
|
||
function buildExportSelectedPayload() {
|
||
if (!selectedRows.value.length) {
|
||
ElMessage.warning('请先勾选需要导出的运单')
|
||
throw new Error('no_selection')
|
||
}
|
||
const ids = selectedRows.value.map((r: any) => r.id).filter(Boolean)
|
||
return {
|
||
where: { ids },
|
||
sort: currentSort.prop
|
||
? { field: currentSort.prop, order: currentSort.order === 'ascending' ? 'asc' : 'desc' }
|
||
: undefined
|
||
}
|
||
}
|
||
|
||
async function handleExportSelected() {
|
||
try {
|
||
await submitExportTask(buildExportSelectedPayload())
|
||
} catch (e: any) {
|
||
if (e?.message === 'no_selection') return
|
||
ElMessage.error(e?.message || '导出失败')
|
||
}
|
||
}
|
||
|
||
async function handleExportAll() {
|
||
try {
|
||
await submitExportTask(buildExportAllPayload())
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '导出失败')
|
||
}
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||
handleExportSelected: () => { void handleExportSelected() },
|
||
handleExportAll: () => { void handleExportAll() },
|
||
openTransferByWaybillsDialog: () => { openTransferByWaybillsDialog() },
|
||
handleUpdateReceive: () => { void handleUpdateReceive() }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: string) {
|
||
const handler = toolbarActionMap[action]
|
||
if (handler) {
|
||
handler()
|
||
return
|
||
}
|
||
console.warn('[WaybillWarehouse] 未处理的工具栏动作:', action)
|
||
}
|
||
|
||
// ============================================================
|
||
// 操作列按钮事件处理
|
||
// ============================================================
|
||
async function handleOperationAction(key: string, row: Record<string, any>) {
|
||
console.log('[WaybillWarehouse] 操作列按钮:', key, row)
|
||
switch (key) {
|
||
case 'viewDetail':
|
||
// 行点击已处理详情展示
|
||
break
|
||
default:
|
||
console.warn('[WaybillWarehouse] 未处理的操作按钮:', key)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// ★★★ 第二步:接入真实接口 ★★★
|
||
// ============================================================
|
||
const listData = ref<Record<string, any>[]>([])
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({
|
||
currentPage: 1,
|
||
pageSize: 20,
|
||
total: 0
|
||
})
|
||
|
||
const currentSort = reactive({ prop: '', order: '' })
|
||
|
||
const loadData = async () => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
loading.value = true
|
||
const startTime = performance.now()
|
||
|
||
try {
|
||
if (cfg.api) {
|
||
// 使用真实接口
|
||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||
const params = cfg.api.buildListParams
|
||
? cfg.api.buildListParams({
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
conditions,
|
||
sort: currentSort.prop ? { prop: currentSort.prop, order: currentSort.order } : undefined
|
||
})
|
||
: {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where: conditions
|
||
}
|
||
|
||
const res = await cfg.api.list(params)
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
const parsed = cfg.api.parseListResponse
|
||
? cfg.api.parseListResponse(res)
|
||
: { list: res.data?.list ?? res.list ?? [], total: res.data?.pagination?.total ?? res.total ?? 0 }
|
||
listData.value = parsed.list
|
||
pagination.total = parsed.total
|
||
} else {
|
||
throw new Error(res?.message || '接口返回异常')
|
||
}
|
||
} else {
|
||
// ★ 未配置 API 时使用模拟数据(替换为真实接口后删除)
|
||
console.log('[WaybillWarehouse] 未配置 API,使用空数据。请在 tabPages 中配置 api 字段。')
|
||
listData.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e: any) {
|
||
console.error('[WaybillWarehouse] 加载列表失败:', e)
|
||
ElMessage.error(e?.message || '获取列表数据失败')
|
||
listData.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Math.round(performance.now() - startTime)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// ScanBox 筛选事件
|
||
// ============================================================
|
||
const scanBoxRef = ref<any>(null)
|
||
const presetTree = ref<any[]>([])
|
||
|
||
const handleConditionChange = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
const handleConditionReset = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
const handleConditionClear = () => {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
// ============================================================
|
||
// UpperTable 事件
|
||
// ============================================================
|
||
const upperTableRef = ref<any>(null)
|
||
const selectedRows = ref<Record<string, any>[]>([])
|
||
|
||
const handleSortChange = ({ prop, order }: any) => {
|
||
currentSort.prop = prop
|
||
currentSort.order = order
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handlePageChange = (page: number) => {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
const handlePageSizeChange = (size: number) => {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleSelectionChange = (rows: Record<string, any>[]) => {
|
||
selectedRows.value = rows
|
||
}
|
||
|
||
// ============================================================
|
||
// 运单批量转入退件登记(returnUnpack.transferByWaybills)
|
||
// ============================================================
|
||
const transferByWaybillsVisible = ref(false)
|
||
|
||
/** 运单批量转入:使用当前勾选的运单行(入参 ids 取运单表主键 id) */
|
||
function openTransferByWaybillsDialog() {
|
||
if (!selectedRows.value.length) {
|
||
ElMessage.warning('请先勾选需要转入退件登记的运单')
|
||
return
|
||
}
|
||
transferByWaybillsVisible.value = true
|
||
}
|
||
|
||
/** 转入后刷新列表(部分失败时也刷新,明细由弹窗结果区展示) */
|
||
function handleTransferByWaybillsSuccess() {
|
||
void loadData()
|
||
}
|
||
|
||
// ============================================================
|
||
// 批量更新揽收状态(waybill.warehouse.updateReceive)
|
||
// ============================================================
|
||
|
||
/** 提交中(按钮 loading / 防重复提交) */
|
||
const receiveLoading = ref(false)
|
||
|
||
/** 解析异步任务响应体(兼容 data / data.data 嵌套) */
|
||
function parseReceiveTaskPayload(res: any): Record<string, any> {
|
||
if (!res || typeof res !== 'object') return {}
|
||
const root = res as Record<string, any>
|
||
const nested = root.data
|
||
if (!nested || typeof nested !== 'object' || Array.isArray(nested)) return root
|
||
const deep = nested.data
|
||
if (
|
||
deep
|
||
&& typeof deep === 'object'
|
||
&& !Array.isArray(deep)
|
||
&& (deep.task_id || deep.taskId || deep.status || deep.progress !== undefined)
|
||
) {
|
||
return deep
|
||
}
|
||
return nested
|
||
}
|
||
|
||
/** 进度接口响应 → useTaskProgress 期望结构(频率字段做兼容归一) */
|
||
function normalizeReceiveProgress(res: any) {
|
||
const payload = parseReceiveTaskPayload(res)
|
||
const rawStatus = String(payload.status || '').toLowerCase()
|
||
// 任务不存在/已过期:按失败处理,避免无意义轮询到超时
|
||
const status = rawStatus === 'not_found' ? 'failed' : rawStatus
|
||
|
||
const total = Number(payload.total ?? payload.total_count ?? payload.totalCount ?? 0)
|
||
const processed = Number(
|
||
payload.processed
|
||
?? payload.processed_count
|
||
?? payload.processedCount
|
||
?? payload.current
|
||
?? payload.done
|
||
?? 0
|
||
)
|
||
const rawProgress = Number(payload.progress)
|
||
const progress = Number.isFinite(rawProgress)
|
||
? rawProgress
|
||
: total > 0
|
||
? Math.round((processed / total) * 100)
|
||
: undefined
|
||
|
||
return {
|
||
status,
|
||
progress,
|
||
message: String(payload.message || ''),
|
||
error: rawStatus === 'not_found'
|
||
? (payload.message || '任务不存在或已过期')
|
||
: String(payload.error || ''),
|
||
result: payload
|
||
}
|
||
}
|
||
|
||
const {
|
||
visible: receiveProgressVisible,
|
||
polling: receiveProgressPolling,
|
||
state: receiveProgressState,
|
||
startPolling: startReceivePolling,
|
||
close: closeReceiveProgress
|
||
} = useTaskProgress({
|
||
interval: 1500,
|
||
// 200 次 × 1.5s ≈ 5 分钟上限,超时后提示刷新查看结果
|
||
maxAttempts: 200,
|
||
pollFn: async (taskId: string) => {
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api?.updateReceiveProgress) throw new Error('揽收进度接口未配置')
|
||
const res = await cfg.api.updateReceiveProgress({ task_id: taskId })
|
||
return normalizeReceiveProgress(res)
|
||
},
|
||
onSuccess: async () => {
|
||
ElMessage.success('揽收状态更新完成')
|
||
upperTableRef.value?.clearSelection?.()
|
||
selectedRows.value = []
|
||
await loadData()
|
||
},
|
||
onError: (error: string) => {
|
||
ElMessage.error(error || '揽收状态更新失败')
|
||
}
|
||
})
|
||
|
||
const receiveProgressStatusLabel = computed(() => {
|
||
const map: Record<string, string> = {
|
||
submitted: '已提交',
|
||
running: '处理中',
|
||
success: '已完成',
|
||
completed: '已完成',
|
||
failed: '失败',
|
||
error: '错误'
|
||
}
|
||
return map[receiveProgressState.status] || receiveProgressState.status || '—'
|
||
})
|
||
|
||
/** 勾选运单 → 提交揽收状态更新任务 → 轮询进度 */
|
||
async function handleUpdateReceive() {
|
||
if (receiveLoading.value) return
|
||
if (!selectedRows.value.length) {
|
||
ElMessage.warning('请先勾选需要更新揽收状态的运单')
|
||
return
|
||
}
|
||
|
||
const waybillCodes = selectedRows.value
|
||
.map((row: any) => String(row?.waybill_code ?? row?.waybillCode ?? '').trim())
|
||
.filter(Boolean)
|
||
|
||
if (!waybillCodes.length) {
|
||
ElMessage.warning('勾选的运单缺少运单号,无法更新揽收状态')
|
||
return
|
||
}
|
||
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg?.api?.updateReceive) {
|
||
ElMessage.error('揽收状态更新接口未配置')
|
||
return
|
||
}
|
||
|
||
receiveLoading.value = true
|
||
try {
|
||
const res = await cfg.api.updateReceive({ waybillCodes })
|
||
const payload = parseReceiveTaskPayload(res)
|
||
const taskId = String(payload.task_id || payload.taskId || '').trim()
|
||
if (!taskId) {
|
||
throw new Error(payload.message || res?.message || '揽收状态更新任务提交失败')
|
||
}
|
||
ElMessage.success(`已提交 ${waybillCodes.length} 个运单的揽收状态更新任务`)
|
||
// 异步任务:不 await,轮询由进度弹窗接管
|
||
void startReceivePolling(taskId)
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '揽收状态更新失败')
|
||
} finally {
|
||
receiveLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 明细面板
|
||
// ============================================================
|
||
const detailVisible = ref(PAGE_CONFIG.enableDetailPanel)
|
||
const selectedRow = ref<Record<string, any> | null>(null)
|
||
const selectedDetail = ref<Record<string, any> | null>(null)
|
||
const activeDetailTab = ref('detail')
|
||
|
||
const handleRowClick = async (row: Record<string, any>) => {
|
||
if (!PAGE_CONFIG.enableDetailPanel) return
|
||
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
selectedRow.value = row
|
||
|
||
try {
|
||
const detailRes = await waybillWarehouseDetail({
|
||
id: row.id,
|
||
waybillCode: row.waybill_code
|
||
})
|
||
if (detailRes && (detailRes.code === 1 || detailRes.code === 200)) {
|
||
const raw = detailRes.data ?? detailRes
|
||
// 展平嵌套的详情结构:order / logistics / status_info / weight / package
|
||
selectedDetail.value = {
|
||
...raw,
|
||
...(raw.order || {}),
|
||
...(raw.logistics || {}),
|
||
...(raw.status_info || {}),
|
||
...(raw.weight || {}),
|
||
...(raw.package || {})
|
||
}
|
||
} else {
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
} catch {
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 标签页切换
|
||
// ============================================================
|
||
const handleTabChange = (tabName: string) => {
|
||
if (activeTabName.value === tabName) return
|
||
activeTabName.value = tabName
|
||
pagination.currentPage = 1
|
||
currentSort.prop = ''
|
||
currentSort.order = ''
|
||
selectedRow.value = null
|
||
selectedDetail.value = null
|
||
selectedRows.value = []
|
||
activeDetailTab.value = 'detail'
|
||
syncScanBoxFields()
|
||
loadScanBoxOptions()
|
||
loadData()
|
||
}
|
||
|
||
// ============================================================
|
||
// 分栏拖拽
|
||
// ============================================================
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } =
|
||
useVerticalSplitPane({ defaultLowerPercent: 38 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
// ============================================================
|
||
// 初始化
|
||
// ============================================================
|
||
onMounted(() => {
|
||
syncScanBoxFields()
|
||
loadScanBoxOptions()
|
||
loadData()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* ================================================================
|
||
整体布局(对齐 storage/entry 的列表页骨架)
|
||
================================================================ */
|
||
.page-wrapper {
|
||
position: relative;
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* ---- 主内容区(无顶部标签页,直接全圆角) ---- */
|
||
.main-container {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
background: #fff;
|
||
border: 1px solid #e8eef7;
|
||
border-radius: 6px;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.order-sub-container {
|
||
display: flex;
|
||
height: 100%;
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
|
||
:deep(.scan-box-container) {
|
||
flex: 0 0 220px;
|
||
flex-shrink: 0;
|
||
height: 100%;
|
||
}
|
||
}
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 10px;
|
||
overflow: hidden;
|
||
min-width: 0;
|
||
}
|
||
|
||
.tab-content-inner {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
/* ---- 工具栏 ---- */
|
||
.toolbar {
|
||
margin-bottom: 3px;
|
||
padding: 6px 10px;
|
||
border: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
background-color: #fff;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
|
||
.toolbar-left {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.toolbar-right {
|
||
flex: 0 0 auto;
|
||
margin-left: 10px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
gap: 10px;
|
||
}
|
||
}
|
||
|
||
/* ---- 分栏区域(对齐 storage/entry 的列表页骨架) ---- */
|
||
.split-stack {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper--full {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper :deep(.upper-table-container) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.upper-wrapper :deep(.table-container) {
|
||
height: auto !important;
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper :deep(.el-table__body-wrapper) {
|
||
overflow: auto;
|
||
}
|
||
|
||
/* 分隔条(对齐 storage/entry: 6px, #e4e7ed) */
|
||
.pane-resizer {
|
||
flex: 0 0 6px;
|
||
min-height: 6px;
|
||
background: #e4e7ed;
|
||
cursor: row-resize;
|
||
flex-shrink: 0;
|
||
position: relative;
|
||
z-index: 2;
|
||
|
||
&:hover {
|
||
background: #dcdfe6;
|
||
}
|
||
}
|
||
|
||
/* 底部分栏详情面板(对齐 storage/entry: flex 0 0 38%, border-top) */
|
||
.lower-level {
|
||
flex: 0 0 38%;
|
||
height: 38%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
|
||
.detail-header {
|
||
background-color: #fafafa;
|
||
border-bottom: 1px solid #ebeef5;
|
||
padding: 0 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
height: 42px;
|
||
min-height: 42px;
|
||
box-sizing: border-box;
|
||
|
||
.detail-tab {
|
||
flex: 1;
|
||
min-width: 0;
|
||
margin-bottom: -1px;
|
||
|
||
:deep(.el-tabs__header) {
|
||
margin: 0;
|
||
border-bottom: none;
|
||
}
|
||
|
||
:deep(.el-tabs__nav-wrap::after) {
|
||
display: none;
|
||
}
|
||
|
||
:deep(.el-tabs__active-bar) {
|
||
display: none;
|
||
}
|
||
|
||
:deep(.el-tabs__item) {
|
||
height: 40px;
|
||
line-height: 40px;
|
||
font-size: 13px;
|
||
padding: 0 16px;
|
||
color: #606266;
|
||
border: 1px solid transparent;
|
||
border-bottom: none;
|
||
border-radius: 4px 4px 0 0;
|
||
transition: color 0.2s;
|
||
}
|
||
|
||
:deep(.el-tabs__item:hover) {
|
||
color: var(--el-color-primary);
|
||
}
|
||
|
||
:deep(.el-tabs__item.is-active) {
|
||
color: var(--el-color-primary);
|
||
background-color: #fff;
|
||
border-color: #ebeef5;
|
||
border-bottom-color: #fff;
|
||
}
|
||
}
|
||
}
|
||
|
||
.detail-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
/* 详情区外壳与 order/waveOrder「团购波次」一致:不留上/下间距(明细面板自带
|
||
padding: 6px 10px 8px),只留左右 10px */
|
||
padding: 0 10px;
|
||
overflow: auto;
|
||
}
|
||
}
|
||
|
||
/* 无选中项占位(对齐 storage/entry) */
|
||
.no-selection {
|
||
flex: 0 0 38%;
|
||
height: 38%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #909399;
|
||
background-color: #fff;
|
||
border-top: 1px solid #ebeef5;
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 14px;
|
||
}
|
||
}
|
||
|
||
/* ---- 过渡动画 ---- */
|
||
.tab-fade-enter-active,
|
||
.tab-fade-leave-active {
|
||
transition: opacity 0.2s ease;
|
||
opacity: 1;
|
||
}
|
||
|
||
.tab-fade-enter-from,
|
||
.tab-fade-leave-to {
|
||
opacity: 0;
|
||
}
|
||
</style>
|