971 lines
32 KiB
Vue
971 lines
32 KiB
Vue
<template>
|
||
<div class="order-management-wrapper" :style="{ height: containerHeight }">
|
||
<!-- ===== 多标签模式:显示顶部多标签页 ===== -->
|
||
<template v-if="WAVEORDER2_PAGE_CONFIG.showTabArea && !WAVEORDER2_PAGE_CONFIG.singlePage">
|
||
<div class="tab-section">
|
||
<TabArea
|
||
:tabs="tabList"
|
||
:default-active="activeTabName"
|
||
@tab-change="handleTabChange"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- ===== 标签页隐藏时的提示条 ===== -->
|
||
<!-- <div
|
||
v-if="!WAVEORDER2_PAGE_CONFIG.showTabArea && !WAVEORDER2_PAGE_CONFIG.singlePage"
|
||
class="tab-hidden-bar"
|
||
>
|
||
<span class="tab-hidden-hint">多标签页区域已隐藏</span>
|
||
</div> -->
|
||
|
||
<!-- ===== 主内容区(结构与 waveOrder 子面板完全一致) ===== -->
|
||
<div class="tab-container main-container">
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBoxRef"
|
||
:cache-key="currentScanBoxCacheKey"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="currentScanBoxFields"
|
||
@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">
|
||
<order-toolbar-button-group
|
||
:buttons="currentToolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 上下分栏区域:详情面板启用时才显示分栏 + 详情 -->
|
||
<template v-if="WAVEORDER2_PAGE_CONFIG.enableDetailPanel">
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`wave-order2-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'wave_no'"
|
||
: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="`${columnSlotsKey}-${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>
|
||
</upper-table>
|
||
</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">
|
||
<upper-table
|
||
ref="upperTableRef"
|
||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||
default-align="center"
|
||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||
:column-config-schema-version="1"
|
||
:table-id="`wave-order2-table-${activeTabName}`"
|
||
:data="listData"
|
||
:row-key="'wave_no'"
|
||
: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="`${columnSlotsKey}-${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>
|
||
</upper-table>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</transition>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ===== 功能按钮表单(pages/ 目录下的组件) ===== -->
|
||
<FetchGroupOrderForm
|
||
v-model:visible="fetchGroupOrderFormVisible"
|
||
@success="handleFormSuccess"
|
||
/>
|
||
|
||
<BatchOperationForm
|
||
v-model:visible="batchOperationFormVisible"
|
||
:config="batchOperationConfig"
|
||
:selected-ids="batchOperationSelectedIds"
|
||
:selected-rows="selectedRows"
|
||
:extracted-payload="batchOperationExtractedPayload"
|
||
@success="handleFormSuccess"
|
||
/>
|
||
|
||
<!-- ===== 待处理订单弹窗 ===== -->
|
||
<el-dialog
|
||
v-model="pendingOrderDialogVisible"
|
||
:title="pendingOrderDialogTitle"
|
||
width="92vw"
|
||
destroy-on-close
|
||
append-to-body
|
||
align-center
|
||
@closed="handlePendingOrderDialogClosed"
|
||
>
|
||
<PendingOrderListPanel
|
||
v-if="pendingOrderDialogVisible && pendingOrderDialogWaveNo"
|
||
:wave-no="pendingOrderDialogWaveNo"
|
||
/>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, computed, onMounted, reactive } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import TabArea from './components/TabArea.vue'
|
||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||
import OperationCellRenderer from './components/public/OperationCellRenderer.vue'
|
||
import PendingOrderListPanel from '@/views/order/waveOrder/component/PendingOrderListPanel.vue'
|
||
import { resolveWavePickCompleteWaveId } from '@/views/order/waveOrder/composables/useWavePickComplete'
|
||
import { pickWavePickComplete } from '@/api/pick/pick'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import FetchGroupOrderForm from './pages/FetchGroupOrderForm.vue'
|
||
import BatchOperationForm from './pages/BatchOperationForm.vue'
|
||
import {
|
||
WAVEORDER2_PAGE_CONFIG,
|
||
waveOrder2Tabs,
|
||
waveOrder2TabPages,
|
||
resolveTabConfig,
|
||
getTabToolbarButtons,
|
||
BATCH_OPERATION_CONFIGS
|
||
} from './config/waveorder-config'
|
||
import type {
|
||
TabPageConfig,
|
||
DetailTabConfig,
|
||
WaveOrder2ToolbarButtonConfig,
|
||
BatchOperationConfig
|
||
} from './config/waveorder-config'
|
||
|
||
defineOptions({ name: 'WaveOrder2' })
|
||
|
||
const settingsStore = useSettingsStore()
|
||
|
||
// ===== 容器高度(与 waveOrder 一致) =====
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() => {
|
||
return shortcutExpanded.value
|
||
? 'calc(100vh - 150px)'
|
||
: 'calc(100vh - 100px)'
|
||
})
|
||
|
||
// ===== 标签页 =====
|
||
const tabList = ref(waveOrder2Tabs.map((t) => ({ name: t.name, label: t.label })))
|
||
const activeTabName = ref(waveOrder2Tabs[0]?.name ?? 'tab1')
|
||
|
||
/** 当前激活标签页的完整配置(运行时由 resolveTabConfig 展开 key 引用) */
|
||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||
const raw = waveOrder2TabPages.find((t) => t.name === activeTabName.value)
|
||
if (!raw) return undefined
|
||
return resolveTabConfig(raw)
|
||
})
|
||
|
||
/** 当前标签页的 ScanBox 缓存 key */
|
||
const currentScanBoxCacheKey = computed(() => {
|
||
return currentTabConfig.value?.scanBoxCacheKey ?? 'wave-order2-default'
|
||
})
|
||
|
||
/** 当前标签页的 ScanBox 筛选字段 */
|
||
const currentScanBoxFields = computed(() => {
|
||
return currentTabConfig.value?.scanBoxFields ?? []
|
||
})
|
||
|
||
/** 当前标签页的表格列 */
|
||
const currentColumns = computed(() => {
|
||
return currentTabConfig.value?.upperTable.columns ?? []
|
||
})
|
||
|
||
/** 当前标签页的列插槽配置 */
|
||
const currentColumnSlots = computed(() => {
|
||
return currentTabConfig.value?.columnSlots ?? {}
|
||
})
|
||
|
||
/** 当前标签页的明细面板配置 */
|
||
const currentDetailConfig = computed(() => {
|
||
return currentTabConfig.value?.detailConfig ?? []
|
||
})
|
||
|
||
/** 当前标签页的明细标签页列表 */
|
||
const currentDetailTabs = computed<DetailTabConfig[]>(() => {
|
||
return currentTabConfig.value?.detailTabs ?? []
|
||
})
|
||
|
||
/** 当前激活的明细标签页对应的组件 */
|
||
const activeDetailTabComponent = computed(() => {
|
||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||
return tab?.component ?? null
|
||
})
|
||
|
||
/** 当前激活明细标签页对应的 API 方法(函数=source='api',对象=source='list'返回 undefined) */
|
||
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
|
||
|
||
// 根据 componentKey 匹配对应的 API 配置
|
||
let componentCfg: unknown
|
||
switch (tab.componentKey) {
|
||
case 'DetailPanel':
|
||
componentCfg = cfg.api.detail
|
||
break
|
||
case 'LogPanel':
|
||
componentCfg = cfg.api.log
|
||
break
|
||
default:
|
||
return undefined
|
||
}
|
||
|
||
// 函数 → 直接返回作为 apiMethod;对象 { source:'list' } → 组件用行数据
|
||
if (typeof componentCfg === 'function') {
|
||
return componentCfg
|
||
}
|
||
return undefined
|
||
})
|
||
|
||
|
||
// ============================================================
|
||
// 工具栏按钮系统(参照 orderManagement 设计)
|
||
// ============================================================
|
||
|
||
/** 当前标签页的工具栏按钮列表(从 WAVEORDER2_TOOLBAR_BUTTONS 获取) */
|
||
const currentToolbarButtons = computed<ToolbarButtonConfig[]>(() => {
|
||
const btns = getTabToolbarButtons(activeTabName.value)
|
||
return btns.map((btn: WaveOrder2ToolbarButtonConfig) => ({
|
||
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: false,
|
||
batchAutoGroupingLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchAutoGrouping',
|
||
batchFinishAutoGroupingLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchFinishAutoGrouping',
|
||
batchCancelLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchCancel',
|
||
batchAllocateExpressLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchAllocateExpress',
|
||
batchAllocateStorageLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchAllocateStorage',
|
||
batchRemoveExceptionOrdersLoading: batchOpLoading.value && currentBatchOpAction.value === 'batchRemoveExceptionOrders'
|
||
}))
|
||
|
||
/** 按钮动态标签映射 */
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
/** 工具栏布局 key(变化时触发 OrderToolbarButtonGroup 重排) */
|
||
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 toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||
handleExportWaybill: () => { console.log('[WaveOrder2] 导出(不含明细)', activeTabName.value) },
|
||
handleExportItem: () => { console.log('[WaveOrder2] 导出(含明细)', activeTabName.value) }
|
||
}
|
||
|
||
/** 统一工具栏按钮点击处理 */
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (handler) {
|
||
handler()
|
||
return
|
||
}
|
||
// 功能按钮:打开对应表单
|
||
handleFunctionButtonAction(action)
|
||
}
|
||
|
||
// ============================================================
|
||
// 操作列按钮事件处理
|
||
// ============================================================
|
||
|
||
/** 操作列 action 按钮回调 */
|
||
async function handleOperationAction(key: string, row: Record<string, any>) {
|
||
switch (key) {
|
||
case 'handleOrders':
|
||
openPendingOrdersByWave(row)
|
||
break
|
||
case 'batchPick':
|
||
// confirm 已在 OperationCellRenderer 中处理
|
||
await handleWavePickComplete(row)
|
||
break
|
||
default:
|
||
console.warn('[WaveOrder2] 未处理的操作按钮:', key)
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 处理订单 — 打开待处理订单弹窗
|
||
// ============================================================
|
||
|
||
const pendingOrderDialogVisible = ref(false)
|
||
const pendingOrderDialogWaveNo = ref('')
|
||
const pendingOrderDialogTitle = computed(() =>
|
||
pendingOrderDialogWaveNo.value
|
||
? `待处理订单 - ${pendingOrderDialogWaveNo.value}`
|
||
: '待处理订单'
|
||
)
|
||
|
||
function openPendingOrdersByWave(row: Record<string, any>) {
|
||
const waveNo = String(row?.wave_no || '').trim()
|
||
if (!waveNo) {
|
||
ElMessage.warning('当前波次缺少波次号')
|
||
return
|
||
}
|
||
pendingOrderDialogWaveNo.value = waveNo
|
||
pendingOrderDialogVisible.value = true
|
||
}
|
||
|
||
function handlePendingOrderDialogClosed() {
|
||
pendingOrderDialogWaveNo.value = ''
|
||
loadData()
|
||
}
|
||
|
||
// ============================================================
|
||
// 批量拣货 — 调用拣货接口
|
||
// ============================================================
|
||
|
||
async function handleWavePickComplete(row: Record<string, any>) {
|
||
const waveId = resolveWavePickCompleteWaveId(row)
|
||
if (!waveId) {
|
||
ElMessage.warning('当前波次缺少可用的波次 ID')
|
||
return
|
||
}
|
||
|
||
const waveNo = String(row?.wave_no ?? row?.wave_code ?? waveId).trim()
|
||
|
||
try {
|
||
const res = (await pickWavePickComplete({ wave_id: waveId })) as Record<string, any>
|
||
if (res?.code !== undefined && res?.code !== null && res?.code !== 1 && res?.code !== 200 && res?.code !== 0) {
|
||
throw new Error(res?.message || res?.tip || '批量拣货失败')
|
||
}
|
||
ElMessage.success(`波次「${waveNo}」批量拣货已完成`)
|
||
loadData()
|
||
} catch (e: any) {
|
||
if (e?.message && e?.message !== 'cancel') {
|
||
ElMessage.error(e?.message || '批量拣货失败')
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================
|
||
// 功能按钮表单状态
|
||
// ============================================================
|
||
|
||
/** 团购单抓取表单 */
|
||
const fetchGroupOrderFormVisible = ref(false)
|
||
|
||
/** 批量操作表单 */
|
||
const batchOperationFormVisible = ref(false)
|
||
const batchOperationConfig = ref<BatchOperationConfig | null>(null)
|
||
const batchOperationSelectedIds = ref<string[] | number[]>([])
|
||
/** 多字段提取结果(idField 为数组时使用),直接作为请求体 */
|
||
const batchOperationExtractedPayload = ref<Record<string, any[]> | null>(null)
|
||
const batchOpLoading = ref(false)
|
||
const currentBatchOpAction = ref('')
|
||
|
||
/** 功能按钮 action → 表单打开逻辑 */
|
||
function handleFunctionButtonAction(action: string) {
|
||
switch (action) {
|
||
case 'openFetchGroupOrderForm':
|
||
openFetchGroupOrderForm()
|
||
break
|
||
case 'openBatchAutoGroupingForm':
|
||
case 'openBatchFinishAutoGroupingForm':
|
||
case 'openBatchCancelForm':
|
||
case 'openBatchAllocateExpressForm':
|
||
case 'openBatchAllocateStorageForm':
|
||
case 'openBatchRemoveExceptionOrdersForm':
|
||
openBatchOperationForm(action)
|
||
break
|
||
default:
|
||
console.warn('[WaveOrder2] 未处理的工具栏动作:', action)
|
||
}
|
||
}
|
||
|
||
function openFetchGroupOrderForm() {
|
||
fetchGroupOrderFormVisible.value = true
|
||
}
|
||
|
||
function openBatchOperationForm(action: string) {
|
||
if (!selectedRows.value.length) {
|
||
ElMessage.warning('请先选择波次')
|
||
return
|
||
}
|
||
|
||
// 根据 action 推导对应的批量操作 key
|
||
const opKey = action.replace('open', '').replace('Form', '')
|
||
// openBatchAutoGroupingForm → BatchAutoGrouping → batchAutoGrouping
|
||
const configKey = opKey.charAt(0).toLowerCase() + opKey.slice(1)
|
||
|
||
const cfg = BATCH_OPERATION_CONFIGS[configKey]
|
||
if (!cfg) {
|
||
console.warn('[WaveOrder2] 未找到批量操作配置:', configKey)
|
||
return
|
||
}
|
||
|
||
currentBatchOpAction.value = cfg.action
|
||
batchOperationConfig.value = { ...cfg }
|
||
|
||
const idField = cfg.idField ?? 'wave_id'
|
||
|
||
if (Array.isArray(idField)) {
|
||
// 多字段模式:提取所有字段,组装为 { field1: [...], field2: [...] }
|
||
const payload: Record<string, any[]> = {}
|
||
for (const field of idField) {
|
||
payload[field] = []
|
||
}
|
||
for (const row of selectedRows.value) {
|
||
for (const field of idField) {
|
||
const val = (row as any)[field]
|
||
payload[field]!.push(val !== undefined && val !== null ? val : null)
|
||
}
|
||
}
|
||
batchOperationExtractedPayload.value = payload
|
||
// selectedIds 用第一个字段的值供 UI 展示
|
||
const firstField = idField[0]
|
||
batchOperationSelectedIds.value = firstField ? (payload[firstField]?.filter((v: any) => v !== null) ?? []) : []
|
||
} else {
|
||
// 单字段模式(支持逗号分隔 fallback)
|
||
batchOperationExtractedPayload.value = null
|
||
const idFields = (idField as string).split(',').map((f: string) => f.trim())
|
||
batchOperationSelectedIds.value = selectedRows.value
|
||
.map((r: any) => {
|
||
for (const field of idFields) {
|
||
const val = r[field]
|
||
if (val !== undefined && val !== null && val !== '') return val
|
||
}
|
||
return null
|
||
})
|
||
.filter((v: any) => v !== null)
|
||
}
|
||
batchOperationFormVisible.value = true
|
||
}
|
||
|
||
/** 表单操作成功后刷新列表 */
|
||
function handleFormSuccess() {
|
||
selectedRows.value = []
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
/** 切换标签页时重置状态并加载新数据 */
|
||
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'
|
||
loadData()
|
||
}
|
||
|
||
// ===== 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()
|
||
}
|
||
|
||
function handleSortChange({ prop, order }: any) {
|
||
currentSort.prop = prop
|
||
currentSort.order = order
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
// ===== 列表数据 =====
|
||
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 {
|
||
listData.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e: any) {
|
||
console.error('[WaveOrder2] 加载列表失败:', e)
|
||
ElMessage.error(e?.message || '获取列表数据失败')
|
||
listData.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Math.round(performance.now() - startTime)
|
||
}
|
||
}
|
||
|
||
const handlePageChange = (page: number) => {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
const handlePageSizeChange = (size: number) => {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
// ===== UpperTable =====
|
||
const upperTableRef = ref<any>(null)
|
||
const selectedRows = ref<Record<string, any>[]>([])
|
||
|
||
const handleSelectionChange = (rows: Record<string, any>[]) => {
|
||
selectedRows.value = rows
|
||
}
|
||
|
||
// ===== 明细面板 =====
|
||
const detailVisible = ref(WAVEORDER2_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 (!WAVEORDER2_PAGE_CONFIG.enableDetailPanel) return
|
||
|
||
const cfg = currentTabConfig.value
|
||
if (!cfg) return
|
||
selectedRow.value = row
|
||
|
||
// 根据 DetailPanel 的 api 配置决定数据来源
|
||
const detailCfg = cfg.api?.detail
|
||
// 直接传函数 = source='api'(与 list 字段写法一致)
|
||
if (typeof detailCfg === 'function') {
|
||
try {
|
||
const detailRes = await detailCfg({ wave_id: row.wave_id ?? row.id, wave_no: row.wave_no })
|
||
if (detailRes && (detailRes.code === 1 || detailRes.code === 200)) {
|
||
selectedDetail.value = detailRes.data ?? detailRes
|
||
return
|
||
}
|
||
} catch (e) {
|
||
console.warn('[WaveOrder2] 获取明细失败,使用列表行数据:', e)
|
||
}
|
||
}
|
||
|
||
// source='list' 或 API 失败:直接使用列表行数据
|
||
selectedDetail.value = { ...row }
|
||
}
|
||
|
||
// ===== 分栏拖拽(使用 useVerticalSplitPane,与 waveOrder 一致) =====
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
|
||
defaultLowerPercent: 38
|
||
})
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
// ===== 初始化 & 标签页切换时重新加载 =====
|
||
onMounted(() => {
|
||
loadData()
|
||
})
|
||
|
||
// 当 currentTabConfig 变化(如列配置变更)时,列插槽的 key 也会变,触发重新渲染
|
||
const columnSlotsKey = computed(() => {
|
||
return `${activeTabName.value}-${Object.keys(currentColumnSlots.value).join(',')}`
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* ===== 引入 waveOrder 共享样式(scan-box / toolbar / split-stack / pane-resizer / lower-level 等) ===== */
|
||
@use "../orderManagement/styles/order-sub.scss";
|
||
|
||
/* ================================================================
|
||
整体布局容器
|
||
================================================================ */
|
||
.order-management-wrapper {
|
||
position: relative;
|
||
width: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* ================================================================
|
||
1. 顶部多标签页区域(抽离组件)
|
||
================================================================ */
|
||
.tab-section {
|
||
flex-shrink: 0;
|
||
background: #fff;
|
||
border: 1px solid #e8eef7;
|
||
border-bottom: none;
|
||
border-radius: 6px 6px 0 0;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.tab-hidden-bar {
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 4px 16px;
|
||
background: #fff;
|
||
border: 1px dashed #dcdfe6;
|
||
border-bottom: none;
|
||
border-radius: 6px 6px 0 0;
|
||
|
||
.tab-hidden-hint {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
}
|
||
|
||
/* ================================================================
|
||
2. 主内容区容器
|
||
================================================================ */
|
||
.main-container {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
background: #fff;
|
||
border: 1px solid #e8eef7;
|
||
border-radius: 0 0 6px 6px;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* ================================================================
|
||
3. ScanBox"筛选/过滤"标签样式(对齐页面顶部 TabArea 风格)
|
||
================================================================ */
|
||
.main-container {
|
||
:deep(.scan-box-container .scan-tabs) {
|
||
flex-shrink: 0;
|
||
border-bottom: 1px solid #e8eef7;
|
||
background: #f8fbff;
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__header) {
|
||
margin: 0;
|
||
padding: 4px 8px 0;
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__nav-wrap::after) {
|
||
display: none;
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__active-bar) {
|
||
display: none;
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__item) {
|
||
height: 38px;
|
||
line-height: 38px;
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
padding: 0 20px;
|
||
color: #606266;
|
||
border: 1px solid transparent;
|
||
border-bottom: none;
|
||
border-radius: 6px 6px 0 0;
|
||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||
margin-right: 4px;
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__item:hover) {
|
||
color: #409eff;
|
||
background-color: rgba(64, 158, 255, 0.05);
|
||
}
|
||
|
||
:deep(.scan-box-container .scan-tabs .el-tabs__item.is-active) {
|
||
color: #409eff;
|
||
font-weight: 600;
|
||
background: #ffffff;
|
||
border-color: #e8eef7;
|
||
border-bottom-color: #fff;
|
||
}
|
||
}
|
||
|
||
/* ================================================================
|
||
补充:工具栏信息文字
|
||
================================================================ */
|
||
.toolbar-info {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* ================================================================
|
||
补充:空提示样式
|
||
================================================================ */
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
/* ================================================================
|
||
无选中行时的占位(与 waveOrder 保持一致)
|
||
================================================================ */
|
||
.no-selection {
|
||
flex: 0 0 38%;
|
||
height: 38%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
}
|
||
|
||
/* ================================================================
|
||
标签页切换过渡动画
|
||
================================================================ */
|
||
.main-content {
|
||
position: relative;
|
||
}
|
||
|
||
.tab-content-inner {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
/* fade + slide 混合过渡 */
|
||
.tab-fade-enter-active,
|
||
.tab-fade-leave-active {
|
||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||
}
|
||
|
||
.tab-fade-enter-from {
|
||
opacity: 0;
|
||
transform: translateY(8px);
|
||
}
|
||
|
||
.tab-fade-leave-to {
|
||
opacity: 0;
|
||
transform: translateY(-8px);
|
||
}
|
||
|
||
.tab-fade-leave-active {
|
||
position: absolute;
|
||
width: 100%;
|
||
}
|
||
</style> |