2026-08-29 18:16:18 +08:00

396 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="order-management-wrapper" :style="{ height: containerHeight }">
<!-- 多标签模式 -->
<template v-if="!singlePage">
<!-- 顶部多标签页区域(对齐 stock/stockManagement 的 tab-section) -->
<div class="tab-section">
<div class="tabs-header-action">
<!-- <el-button size="small" @click="workbenchDialogVisible = true">统一查询</el-button> -->
<!-- <el-button size="small" @click="bindByWaybillDialogVisible = true">按运单绑定包材</el-button> -->
<el-button size="small" :loading="badgeLoading" @click="refreshBadgeCounts">刷新角标</el-button>
</div>
<el-tabs
v-model="activeTab"
@tab-change="handleTabChange"
tab-position="top"
type="border-card"
class="tab-container"
>
<el-tab-pane
v-for="tab in tabs"
:key="tab.name"
:name="tab.name"
:lazy="false"
>
<template #label>
<span class="custom-tab-label">
{{ tab.label }}
<el-badge
:value="tab.count"
:max="99"
:hidden="tab.count === 0"
class="tab-badge"
/>
</span>
</template>
</el-tab-pane>
</el-tabs>
</div>
<!-- 主内容区容器(对齐 stock/stockManagement 的 main-container) -->
<div class="main-container">
<transition name="tab-fade" mode="out-in">
<component :is="activeComponent" :key="activeTab" />
</transition>
</div>
</template>
<!-- 单页模式:直接渲染默认页签组件 -->
<div v-else class="tab-container single-page-container">
<component :is="defaultTab.component" />
</div>
<order-workbench-list-dialog v-model="workbenchDialogVisible" />
<BindPackageMaterialByWaybillDialog v-model="bindByWaybillDialogVisible" />
</div>
</template>
<script setup lang="ts">
import { ref, watch, onMounted, computed, markRaw } from 'vue'
import { useRoute } from 'vue-router'
import { useSettingsStore } from '@/stores/modules/settings'
import { orderBadgeCount } from '@/api/order.index/orderindex'
import ReviewOrder from './reviewOrder.vue'
import PendingOrder from './pendingOrder.vue'
import OutboundOrder from './outboundOrder.vue'
import ExceptionOrder from './exceptionOrder.vue'
import DeliveryOrder from './deliveryOrder.vue'
import EntrustWarehouse from './entrustWarehouse.vue'
import DeliveryException from './deliveryException.vue'
import ArchiveOrder from './archiveOrder.vue'
import OrderWorkbenchListDialog from './component/OrderWorkbenchListDialog.vue'
import BindPackageMaterialByWaybillDialog from './component/BindPackageMaterialByWaybillDialog.vue'
import { safeInvoke } from '@/utils/safe-invoke'
import { ORDER_PAGE_CONFIG } from './config/order-common-config'
const route = useRoute()
const settingsStore = useSettingsStore()
const singlePage = ORDER_PAGE_CONFIG.singlePage
const badgeLoading = ref(false)
const workbenchDialogVisible = ref(false)
const bindByWaybillDialogVisible = ref(false)
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
/** 单页模式下使用的默认标签(始终为 tabs 第一项) */
const defaultTab = computed(() => tabs.value[0]!)
const activeTab = ref('pendingOrder')
type OrderTabItem = {
name: string
label: string
count: number | string
component: any
}
/** 当前激活页签对应的组件(渲染在主内容区 main-container 中,对齐 stock/stockManagement) */
const activeComponent = computed(() => {
const tab = tabs.value.find((t) => t.name === activeTab.value)
return tab?.component
})
const tabs = ref<OrderTabItem[]>([
{
name: 'reviewOrder',
label: '待审核订单',
count: 5,
component: markRaw(ReviewOrder)
},
{
name: 'pendingOrder',
label: '待处理订单',
count: 10,
component: markRaw(PendingOrder)
},
{
name: 'exceptionOrder',
label: '待处理异常订单',
count: 3,
component: markRaw(ExceptionOrder)
},
{
name: 'outboundOrder',
label: '待出库订单',
count: 0,
component: markRaw(OutboundOrder)
},
{
name: 'entrustWarehouse',
label: '委托外仓订单',
count: 0,
component: markRaw(EntrustWarehouse)
},
{
name: 'deliveryOrder',
label: '配送订单',
count: 0,
component: markRaw(DeliveryOrder)
},
{
name: 'deliveryException',
label: '配送异常订单',
count: 0,
component: markRaw(DeliveryException)
},
{
name: 'archiveOrder',
label: '归档订单',
count: 0,
component: markRaw(ArchiveOrder)
}
])
const badgeToTabMap: Record<string, string> = {
reviewOrder: 'reviewOrder',
pendingOrder: 'pendingOrder',
outboundOrder: 'outboundOrder',
expectionOrder: 'exceptionOrder',
entrustOrder: 'entrustWarehouse',
deliveryOrder: 'deliveryOrder',
deliveryExpectionOrder: 'deliveryException',
archiveOrder: 'archiveOrder'
}
async function loadBadgeCounts() {
if (badgeLoading.value) return
badgeLoading.value = true
try {
const res: any = await orderBadgeCount()
if (!res || ![1, 200].includes(res.code) || !res.data) return
const data = res.data as Record<string, number | string>
// 就地更新 count,避免整表替换导致 el-tabs 子项反复重建、事件重入
for (const tab of tabs.value) {
const badgeKey = Object.keys(badgeToTabMap).find((key) => badgeToTabMap[key] === tab.name)
if (!badgeKey) continue
tab.count = data[badgeKey] ?? 0
}
} catch (error) {
console.error('order.badgeCount error:', error)
} finally {
badgeLoading.value = false
}
}
function refreshBadgeCounts() {
safeInvoke(() => loadBadgeCounts())
}
/**
* 首屏 / 外部导航时从地址栏恢复 tab。
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
* 非法 / 缺失 tab 时纯本地归位到「待处理订单」,绝不写回路由。
*/
watch(
() => route.query.tab,
(newTab) => {
const validTabs = tabs.value.map((tab) => tab.name)
const raw = newTab === undefined || newTab === null ? '' : String(newTab).trim()
if (raw && validTabs.includes(raw)) {
activeTab.value = raw
return
}
activeTab.value = 'pendingOrder'
},
{ immediate: true }
)
onMounted(() => {
loadBadgeCounts()
})
// 切换标签(使用 tab-change:在 v-model 更新之后触发,避免与 tab-click 重入)
const handleTabChange = (tabName: string | number) => {
safeInvoke(() => {
const name = String(tabName)
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
if (activeTab.value === name) {
return
}
activeTab.value = name
return loadBadgeCounts()
})
}
</script>
<style lang="scss" scoped>
.order-management-wrapper {
position: relative;
width: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ===== 顶部多标签页区域(对齐 stock/stockManagement 的 tab-section) ===== */
.tab-section {
flex-shrink: 0;
position: relative;
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;
}
.tabs-header-action {
position: absolute;
top: 4px;
right: 16px;
height: 38px;
display: flex;
align-items: center;
z-index: 2;
}
.tab-container {
display: flex;
flex-direction: column;
:deep(.el-tabs__header) {
margin-bottom: 0;
flex-shrink: 0;
}
:deep(.el-tabs__header.is-top) {
padding: 4px 12px 0;
background: #f8fbff;
border-bottom: 1px solid #e8eef7;
margin: 0;
}
:deep(.el-tabs__nav-wrap::after) {
display: none;
}
:deep(.el-tabs__item.is-top) {
height: 38px;
line-height: 38px;
padding: 0 20px;
border-radius: 6px 6px 0 0;
color: #606266;
font-size: 14px;
font-weight: 500;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
border: 1px solid transparent;
border-bottom: none;
margin-right: 4px;
}
:deep(.el-tabs__item.is-top:hover) {
color: #409eff;
background-color: rgba(64, 158, 255, 0.05);
}
:deep(.el-tabs__item.is-top.is-active) {
color: #409eff;
font-weight: 600;
background: #ffffff;
border-color: #e8eef7;
border-bottom: 2px solid #ffffff;
margin-bottom: -1px;
position: relative;
z-index: 1;
}
:deep(.el-tabs__active-bar) {
height: 2px;
border-radius: 2px;
background-color: #409eff;
bottom: 0;
}
/* 隐藏内容区,仅展示标签头(对齐 stock/stockManagement) */
:deep(.el-tabs__content) {
display: none;
}
}
.custom-tab-label {
display: inline-flex;
align-items: center;
gap: 6px;
}
.tab-badge {
:deep(.el-badge__content) {
font-size: 12px;
height: 18px;
line-height: 18px;
padding: 0 6px;
&.is-fixed {
top: -2px;
right: -8px;
}
}
}
// 当数量很大时显示为红色
:deep(.el-badge__content) {
&.is-danger {
background-color: #f56c6c;
}
}
/* ===== 主内容区容器(对齐 stock/stockManagement 的 main-container) ===== */
.main-container {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
background: #fff;
border: 1px solid #e8eef7;
border-top: none;
border-radius: 0 0 6px 6px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
overflow: hidden;
}
/* ========== 单页模式 ========== */
.single-page-container {
flex: 1;
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;
:deep(> *) {
flex: 1;
overflow: auto;
min-height: 0;
}
}
/* ===== 页签切换淡入淡出(对齐 storage/generalreport 的 tab-fade) ===== */
.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>