fix: show pallets across warehouses by default

This commit is contained in:
2026-09-10 16:03:01 +08:00
parent dc1cbfcf4a
commit 4382351569
2 changed files with 23 additions and 9 deletions
@@ -31,19 +31,33 @@ describe('PalletsView', () => {
vi.mocked(updatePallet).mockReset().mockResolvedValue(null)
})
it('loads the all-warehouse pallet summary when the page opens', async () => {
it('loads the all-warehouse pallet list and summary when the page opens', async () => {
vi.mocked(getPalletSummary).mockResolvedValueOnce({ totalCount: 250, idleCount: 100, occupiedCount: 98, scrappedCount: 52 })
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(getPalletSummary).toHaveBeenCalledWith('', {})
expect(listPallets).toHaveBeenCalledWith('', { page: 1, size: 10, keyword: undefined, palletType: undefined, status: undefined })
expect(getPalletSummary).toHaveBeenCalledWith('', { page: 1, size: 10, keyword: undefined, palletType: undefined, status: undefined })
expect(wrapper.get('[aria-label="托盘管理列表"]').text()).toContain('PLT-1')
expect(wrapper.get('[aria-label="托盘管理列表"]').text()).not.toContain('请先选择仓库后查询')
expect(wrapper.get('[aria-label="海外托盘数量概览"]').text()).toContain('托盘总数250')
expect(wrapper.get('[aria-label="海外托盘数量概览"]').text()).toContain('闲置托盘100')
expect(wrapper.get('[aria-label="海外托盘数量概览"]').text()).toContain('占用托盘98')
expect(wrapper.get('[aria-label="海外托盘数量概览"]').text()).toContain('已报废52')
})
it('reloads all warehouses when the filters are reset', async () => {
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
await flushPromises()
vi.mocked(listPallets).mockClear()
wrapper.findComponent(QueryToolbar).vm.$emit('reset', { warehouseId: '', code: '', type: '', status: '' })
await flushPromises()
expect(listPallets).toHaveBeenCalledWith('', { page: 1, size: 10, keyword: undefined, palletType: undefined, status: undefined })
})
it('loads the current detail version and keeps the edit open on a conflict', async () => {
vi.mocked(updatePallet).mockRejectedValueOnce(Object.assign(new Error('version conflict'), { code: 'A0409' }))
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
@@ -35,7 +35,7 @@ const total = ref(0)
const summary = ref<PalletSummaryDto>({ totalCount: 0, idleCount: 0, occupiedCount: 0, scrappedCount: 0 })
const filters = ref<QueryModel>({ warehouseId: '', code: '', type: '', status: '' })
const fields = computed<QueryField[]>(() => [
{ key: 'warehouseId', type: 'select', label: '仓库', width: 240, placeholder: contextLoading.value ? '仓库加载中' : '请选择仓库', options: warehouses.value.map((item) => ({ label: `${item.warehouseName}(${item.warehouseCode})`, value: String(item.id) })), props: { filterable: true, clearable: true, disabled: contextLoading.value } },
{ key: 'warehouseId', type: 'select', label: '仓库', width: 240, placeholder: contextLoading.value ? '仓库加载中' : '全部仓库', options: warehouses.value.map((item) => ({ label: `${item.warehouseName}(${item.warehouseCode})`, value: String(item.id) })), props: { filterable: true, clearable: true, disabled: contextLoading.value } },
{ key: 'code', type: 'input', label: '托盘编码', placeholder: '请输入托盘编码', width: 180 },
{ key: 'type', type: 'select', label: '托盘类型', placeholder: '全部类型', width: 160, options: ['WOOD', 'PLASTIC', 'METAL', 'PAPER', 'FUMIGATION_FREE'].map((value) => ({ label: palletTypeLabel(value), value })) },
{ key: 'status', type: 'select', label: '状态', placeholder: '全部状态', width: 140, options: [{ label: '闲置', value: 'IDLE' }, { label: '占用', value: 'OCCUPIED' }, { label: '已报废', value: 'SCRAPPED' }] },
@@ -63,14 +63,12 @@ async function loadWarehouses() {
warehouses.value = []; filters.value.warehouseId = ''; rows.value = []; total.value = 0
contextLoading.value = true; loadError.value = null; loadErrorKind.value = 'context'
try {
const [warehousePage, platformFbaWarehouses, overallSummary] = await Promise.all([
const [warehousePage, platformFbaWarehouses] = await Promise.all([
listReceivingOverseasWarehouses(),
listAllPlatformWarehouses({ warehouseType: 'FBA', status: 'ACTIVE' }),
getPalletSummary('', {}),
])
warehouses.value = warehousePage.records
fbaWarehouses.value = platformFbaWarehouses
summary.value = overallSummary
}
catch (error) { loadError.value = getApiErrorDetails(error, '海外仓列表加载失败,请重试') }
finally { contextLoading.value = false }
@@ -121,17 +119,19 @@ async function save() {
}
function search(model: QueryModel) { page.value = 1; void load(model) }
function resetSearch(model: QueryModel) { page.value = 1; void load(model) }
function openDetail(source: object) { const row = source as PalletListItem; void router.push({ name: 'overseas-pallet-detail', params: { palletId: row.id }, query: { warehouseId: row.warehouseId } }) }
onMounted(loadWarehouses)
async function initialize() { await loadWarehouses(); if (!loadError.value) await load() }
onMounted(initialize)
</script>
<template>
<AdminPage><OperationErrorToast :details="mutationError" />
<section class="summary-grid" aria-label="海外托盘数量概览"><article><span>托盘总数</span><strong>{{ summary.totalCount }}</strong></article><article><span>闲置托盘</span><strong class="idle">{{ summary.idleCount }}</strong></article><article><span>占用托盘</span><strong class="occupied">{{ summary.occupiedCount }}</strong></article><article><span>已报废</span><strong>{{ summary.scrappedCount }}</strong></article></section>
<ListPageLayout aria-label="托盘管理列表">
<template #toolbar><QueryToolbar v-model="filters" class="surface-panel" :fields="fields" :loading="loading || contextLoading" ariaLabel="托盘筛选" preference-key="overseas-pallets-query" @search="search" @reset="page = 1; rows = []; total = 0" /></template>
<template #toolbar><QueryToolbar v-model="filters" class="surface-panel" :fields="fields" :loading="loading || contextLoading" ariaLabel="托盘筛选" preference-key="overseas-pallets-query" @search="search" @reset="resetSearch" /></template>
<template v-if="loadError" #state><LoadErrorState title="托盘数据加载失败" :message="loadError.message" :loading="loading || contextLoading" @retry="retryLoad"><template #details><ApiErrorMeta :details="loadError" /></template></LoadErrorState></template>
<section v-if="!loadError" class="surface-panel table-panel"><DataTable v-model:page="page" v-model:page-size="pageSize" :data="rows" :columns="columns" :loading="loading" :total="total" preference-key="overseas-pallets" row-key="id" :empty-text="filters.warehouseId ? '暂无托盘' : '请先选择仓库后查询'" @update:page="load()" @update:page-size="page = 1; load()">
<section v-if="!loadError" class="surface-panel table-panel"><DataTable v-model:page="page" v-model:page-size="pageSize" :data="rows" :columns="columns" :loading="loading" :total="total" preference-key="overseas-pallets" row-key="id" empty-text="暂无托盘" @update:page="load()" @update:page-size="page = 1; load()">
<template #toolbar-actions><el-button v-if="access.can(permission.palletCreate)" type="primary" @click="openCreate"><Plus :size="16" />新增托盘</el-button></template>
<template #actions="{ row }"><el-button size="small" plain type="primary" @click="openDetail(row)"><Eye :size="15" />查看</el-button><el-button v-if="access.can(permission.palletEdit)" size="small" plain @click="openEdit(row)"><Pencil :size="15" />编辑</el-button></template>
<template #pagination-left>共 {{ total }} 条托盘</template>