433 lines
13 KiB
Vue
433 lines
13 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="orderManagement:archiveOrder"
|
||
width="250px"
|
||
: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">
|
||
<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 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-archive-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 #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="fulfillment" />
|
||
<el-tab-pane label="订单日志" name="logs" />
|
||
</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" :detail-request="fetchArchiveOrderDetail" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'items'" class="detail-page order-detail-wrapper">
|
||
<order-items-detail-panel :row="selectedRow" :detail-request="fetchArchiveOrderDetail" />
|
||
</div>
|
||
<div v-else-if="activeTab === 'fulfillment'" class="detail-page">
|
||
<p>履约历程加载中...</p>
|
||
</div>
|
||
<div v-else class="detail-page order-log-wrapper">
|
||
<log :data="selectedRow" />
|
||
</div>
|
||
</KeepAlive>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="no-selection" v-else :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</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 { 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 { orderArchiveOrder } from '@/api/order.archiveorder/orderarchiveorder'
|
||
|
||
import {
|
||
archiveAvailableFields,
|
||
archiveColumns,
|
||
archiveOrderToolbarButtons,
|
||
type ToolbarButtonConfig,
|
||
translateOrderField,
|
||
getTagType,
|
||
fillExpressCompanyScanFieldOptions,
|
||
fillStoreScanFieldOptions,
|
||
extractStoreListFromResponse
|
||
} from './config/order-common-config'
|
||
import PendingOrderDetailPanel from './component/PendingOrderDetailPanel.vue'
|
||
import OrderItemsDetailPanel from './component/OrderItemsDetailPanel.vue'
|
||
import log from './component/log.vue'
|
||
import OrderExportProgressDialog from './component/OrderExportProgressDialog.vue'
|
||
import { createOrderPageExport } from './utils/order-page-export'
|
||
import { parseOrderListResponse } from './utils/order-index-helpers'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { createSimpleListToolbarController } from './utils/toolbar-actions'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(archiveAvailableFields)))
|
||
|
||
const activeTab = ref('detail')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const columns = ref(archiveColumns)
|
||
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedOrderId = ref<number | string | null>(null)
|
||
const detailVisible = ref(true)
|
||
|
||
const quickSearch = ref('')
|
||
const toolbarButtons = archiveOrderToolbarButtons
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedOrderId.value) || null
|
||
})
|
||
|
||
/** order.archiveOrder.list:where 禁止传入 warehouse_id / warehouseId */
|
||
function sanitizeArchiveListWhere(where: Record<string, any>) {
|
||
const w = { ...where }
|
||
delete w.warehouse_id
|
||
delete w.warehouseId
|
||
return w
|
||
}
|
||
|
||
/** order.archiveOrder.detail:归档页使用 history 模型 */
|
||
function fetchArchiveOrderDetail(data: Record<string, any>) {
|
||
return orderArchiveOrder.detail({
|
||
...data,
|
||
tableType: 'history'
|
||
})
|
||
}
|
||
|
||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } = useVerticalSplitPane({
|
||
defaultLowerPercent: 38
|
||
})
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden'
|
||
}))
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
function translateField(fieldValue: string, value: any) {
|
||
const field = availableFieldsRef.find((f: any) => f.value === fieldValue)
|
||
if (field && field.options) {
|
||
const option = field.options.find((opt: any) => opt.value === value)
|
||
return option ? option.label : value
|
||
}
|
||
return value
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadData()
|
||
loadFilterData()
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const params = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where: buildWhere(),
|
||
sort: {
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC' as const
|
||
}
|
||
}
|
||
const res: any = await orderArchiveOrder.list(params)
|
||
if (res && (res.code === 200 || res.code === 1)) {
|
||
const data = parseOrderListResponse(res)
|
||
list.value = data.list
|
||
pagination.total = data.total
|
||
} 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 buildWhere() {
|
||
let where = buildWhereConditions(scanBox.value?.getConditions?.() || {})
|
||
if (quickSearch.value) {
|
||
where.delivery_order_code = {
|
||
operator: 'like',
|
||
value: quickSearch.value,
|
||
type: 'text'
|
||
}
|
||
}
|
||
return sanitizeArchiveListWhere(where)
|
||
}
|
||
|
||
const pageExport = createOrderPageExport({
|
||
scopeKey: 'archiveOrder',
|
||
buildWhere,
|
||
buildSort: () => ({
|
||
sortField: 'updated_at',
|
||
sortOrder: 'DESC'
|
||
}),
|
||
selectionRows,
|
||
columns,
|
||
fileNamePrefix: '归档订单',
|
||
storageKey: 'orderManagement:archiveOrder:exportTaskId'
|
||
})
|
||
|
||
const {
|
||
exportLoading,
|
||
exportSelectionLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
handleExport,
|
||
handleExportSelection
|
||
} = pageExport
|
||
|
||
async function loadFilterData() {
|
||
try {
|
||
const [storesRes, expressRes]: any = await Promise.all([
|
||
indexApi.loadStores({ type: 'order' }),
|
||
indexApi.getExpressList({})
|
||
])
|
||
fillStoreScanFieldOptions(availableFieldsRef, extractStoreListFromResponse(storesRes))
|
||
const expressData: any = expressRes?.data
|
||
const expressRaw = expressData?.list || expressData || []
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, expressRaw)
|
||
} catch (e) {
|
||
fillStoreScanFieldOptions(availableFieldsRef, [])
|
||
fillExpressCompanyScanFieldOptions(availableFieldsRef, [])
|
||
}
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function 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?.()
|
||
}
|
||
|
||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||
exportLoading: exportLoading.value,
|
||
exportSelectionLoading: exportSelectionLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||
hasNoSelection: selectionRows.value.length === 0
|
||
}))
|
||
|
||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const { actionMap: toolbarActionMap } = createSimpleListToolbarController({
|
||
loadData,
|
||
handleExport,
|
||
handleExportSelection,
|
||
openColumnConfigPanel,
|
||
toggleDetailVisible
|
||
})
|
||
|
||
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";
|
||
</style>
|
||
|