mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
feat: 发货物流增加发货仓商品页支持按仓查看与批量分配 SKU
This commit is contained in:
@@ -61,6 +61,8 @@ export namespace ProductSkuDTO {
|
||||
skuCode?: string;
|
||||
/** 关键字(模糊查询 SKU 名称、SKU 编码) */
|
||||
keywords?: string;
|
||||
warehouseId?: number;
|
||||
unassignedOnly?: boolean;
|
||||
}
|
||||
|
||||
/** 商品 SKU 查询 DTO(用于批量查询) */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { WarehouseDTO, WarehouseVO } from './types';
|
||||
|
||||
import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
@@ -59,3 +60,28 @@ export async function updateWarehouseBindApi(
|
||||
export async function removeWarehouseBindApi(bindId: number) {
|
||||
return requestClient.delete(`/ec/warehouse/bind/${bindId}`);
|
||||
}
|
||||
|
||||
/** 发货仓商品分页(仓权限) */
|
||||
export async function getWarehouseSkuPageApi(
|
||||
params: PageQueryDTO<WarehouseDTO.SkuFilters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<ProductSkuVO.Info>>(
|
||||
'/ec/warehouse/skus/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUnassignedWarehouseSkuCountApi() {
|
||||
return requestClient.get<{ count: number }>(
|
||||
'/ec/warehouse/skus/unassigned-count',
|
||||
);
|
||||
}
|
||||
|
||||
export async function batchAssignWarehouseSkusApi(
|
||||
data: WarehouseDTO.SkuBatchAssign,
|
||||
) {
|
||||
return requestClient.post<{ updated: number }>(
|
||||
'/ec/warehouse/skus/batch-assign',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,17 @@ export namespace WarehouseDTO {
|
||||
priority?: number;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/** 发货仓商品筛选 */
|
||||
export interface SkuFilters {
|
||||
keywords?: string;
|
||||
warehouseId?: number;
|
||||
unassignedOnly?: boolean;
|
||||
}
|
||||
|
||||
/** 批量分配默认发货仓;warehouseId 空=取消分配 */
|
||||
export interface SkuBatchAssign {
|
||||
skuIds: number[];
|
||||
warehouseId?: number | null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ export namespace WarehouseVO {
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
bindCount?: number;
|
||||
/** 默认发此仓的 SKU 数 */
|
||||
skuCount?: number;
|
||||
binds?: Bind[];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { defineStore } from 'pinia';
|
||||
export type ColSidebarKind =
|
||||
| 'company'
|
||||
| 'ec-shop'
|
||||
| 'ec-warehouse'
|
||||
| 'pdd-shop'
|
||||
| 'pdd-publish-agent';
|
||||
|
||||
@@ -28,6 +29,7 @@ const AGENT_DEFAULT_LAYOUT: ColSidebarLayout = {
|
||||
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
|
||||
return {
|
||||
'ec-shop': { ...DEFAULT_LAYOUT },
|
||||
'ec-warehouse': { ...DEFAULT_LAYOUT },
|
||||
'pdd-shop': { ...DEFAULT_LAYOUT },
|
||||
company: { ...DEFAULT_LAYOUT },
|
||||
'pdd-publish-agent': { ...AGENT_DEFAULT_LAYOUT },
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 发货仓双栏页:左栏 WarehouseSidebarList,宽度/收起走全局持久化。
|
||||
*/
|
||||
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||
import type { WarehouseSidebarScope } from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { ColPage } from '@vben/common-ui';
|
||||
|
||||
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
|
||||
import WarehouseSidebarList from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||
|
||||
defineOptions({ name: 'EcWarehouseColPage' });
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
scope?: WarehouseSidebarScope;
|
||||
selectedWarehouseId?: number;
|
||||
autoContentHeight?: boolean;
|
||||
leftMinWidth?: number;
|
||||
leftMaxWidth?: number;
|
||||
leftCollapsedWidth?: number;
|
||||
leftCollapsible?: boolean;
|
||||
resizable?: boolean;
|
||||
splitHandle?: boolean;
|
||||
splitLine?: boolean;
|
||||
}>(),
|
||||
{
|
||||
scope: 'all',
|
||||
selectedWarehouseId: undefined,
|
||||
autoContentHeight: true,
|
||||
leftMinWidth: 16,
|
||||
leftMaxWidth: 36,
|
||||
leftCollapsedWidth: 3,
|
||||
leftCollapsible: true,
|
||||
resizable: true,
|
||||
splitHandle: false,
|
||||
splitLine: false,
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:scope': [scope: WarehouseSidebarScope];
|
||||
'update:selectedWarehouseId': [id: number | undefined];
|
||||
select: [
|
||||
payload: {
|
||||
scope: WarehouseSidebarScope;
|
||||
warehouse: WarehouseVO.Info | null;
|
||||
},
|
||||
];
|
||||
}>();
|
||||
|
||||
const { width: leftWidth, collapsed: leftCollapsed } =
|
||||
useColSidebarLayout('ec-warehouse');
|
||||
|
||||
const listRef = ref<InstanceType<typeof WarehouseSidebarList> | null>(null);
|
||||
|
||||
function refreshSidebar() {
|
||||
void listRef.value?.refresh();
|
||||
}
|
||||
|
||||
defineExpose({ refreshSidebar });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="ec-warehouse-col-page h-full min-h-0">
|
||||
<ColPage
|
||||
v-model:left-width="leftWidth"
|
||||
v-model:left-collapsed="leftCollapsed"
|
||||
:auto-content-height="autoContentHeight"
|
||||
:left-min-width="leftMinWidth"
|
||||
:left-max-width="leftMaxWidth"
|
||||
:left-collapsed-width="leftCollapsedWidth"
|
||||
:left-collapsible="leftCollapsible"
|
||||
:right-width="100 - leftWidth"
|
||||
:resizable="resizable"
|
||||
:split-handle="splitHandle"
|
||||
:split-line="splitLine"
|
||||
content-class="!p-2 sm:!p-3"
|
||||
>
|
||||
<template #left="{ isCollapsed, expand, collapse }">
|
||||
<div
|
||||
class="flex h-full min-h-0 flex-col"
|
||||
:class="
|
||||
isCollapsed
|
||||
? 'warehouse-sidebar-collapsed-mark min-w-[56px] overflow-visible'
|
||||
: 'min-w-0 overflow-hidden'
|
||||
"
|
||||
>
|
||||
<WarehouseSidebarList
|
||||
ref="listRef"
|
||||
fluid
|
||||
:collapsed="!!isCollapsed"
|
||||
show-collapse-action
|
||||
:scope="scope"
|
||||
:selected-warehouse-id="selectedWarehouseId"
|
||||
@collapse="collapse"
|
||||
@expand="expand"
|
||||
@update:scope="emit('update:scope', $event)"
|
||||
@update:selected-warehouse-id="
|
||||
emit('update:selectedWarehouseId', $event)
|
||||
"
|
||||
@select="emit('select', $event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<slot />
|
||||
</ColPage>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ec-warehouse-col-page :deep([data-panel]:has(.warehouse-sidebar-collapsed-mark)),
|
||||
.ec-warehouse-col-page
|
||||
:deep(
|
||||
[data-panel-group-direction]
|
||||
> *:first-child:has(.warehouse-sidebar-collapsed-mark)
|
||||
) {
|
||||
flex: 0 0 56px !important;
|
||||
width: 56px !important;
|
||||
min-width: 56px !important;
|
||||
max-width: 56px !important;
|
||||
overflow: visible;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,455 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 发货仓侧栏:全部 / 未分配 / 指定仓;交互对齐 ShopSidebarList。
|
||||
*/
|
||||
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Empty,
|
||||
Input,
|
||||
message,
|
||||
Spin,
|
||||
Tag,
|
||||
Tooltip,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
getUnassignedWarehouseSkuCountApi,
|
||||
getWarehousePageApi,
|
||||
} from '#/api/ec/warehouse';
|
||||
|
||||
defineOptions({ name: 'WarehouseSidebarList' });
|
||||
|
||||
export type WarehouseSidebarScope = 'all' | 'unassigned' | 'warehouse';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
scope?: WarehouseSidebarScope;
|
||||
/** scope=warehouse 时选中的仓 id */
|
||||
selectedWarehouseId?: number;
|
||||
fluid?: boolean;
|
||||
showCollapseAction?: boolean;
|
||||
collapsed?: boolean;
|
||||
}>(),
|
||||
{
|
||||
scope: 'all',
|
||||
selectedWarehouseId: undefined,
|
||||
fluid: false,
|
||||
showCollapseAction: false,
|
||||
collapsed: false,
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:scope': [scope: WarehouseSidebarScope];
|
||||
'update:selectedWarehouseId': [id: number | undefined];
|
||||
select: [
|
||||
payload: {
|
||||
scope: WarehouseSidebarScope;
|
||||
warehouse: WarehouseVO.Info | null;
|
||||
},
|
||||
];
|
||||
collapse: [];
|
||||
expand: [];
|
||||
}>();
|
||||
|
||||
const WarehouseIcon = createIconifyIcon('lucide:warehouse');
|
||||
const BoxesIcon = createIconifyIcon('lucide:boxes');
|
||||
const InboxIcon = createIconifyIcon('lucide:inbox');
|
||||
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
|
||||
const ChevronUpIcon = createIconifyIcon('lucide:chevron-up');
|
||||
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
|
||||
|
||||
const keyword = ref('');
|
||||
const warehouses = ref<WarehouseVO.Info[]>([]);
|
||||
const loading = ref(false);
|
||||
const unassignedCount = ref(0);
|
||||
const pagination = ref({ current: 1, pageSize: 20, total: 0 });
|
||||
|
||||
const totalPages = computed(() => {
|
||||
const { total, pageSize } = pagination.value;
|
||||
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||
});
|
||||
|
||||
const allSelected = computed(() => props.scope === 'all');
|
||||
const unassignedSelected = computed(() => props.scope === 'unassigned');
|
||||
|
||||
async function loadUnassignedCount() {
|
||||
try {
|
||||
const res = await getUnassignedWarehouseSkuCountApi();
|
||||
unassignedCount.value = Number(res?.count ?? 0);
|
||||
} catch {
|
||||
unassignedCount.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function searchWarehouses(resetPage = false) {
|
||||
if (resetPage) {
|
||||
pagination.value.current = 1;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await getWarehousePageApi({
|
||||
page: pagination.value.current,
|
||||
pageSize: pagination.value.pageSize,
|
||||
filters: {
|
||||
keywords: keyword.value || undefined,
|
||||
status: 1,
|
||||
},
|
||||
});
|
||||
warehouses.value = result.records ?? [];
|
||||
pagination.value.total = result.total ?? 0;
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取仓库列表失败');
|
||||
warehouses.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function resetSearch() {
|
||||
keyword.value = '';
|
||||
void searchWarehouses(true);
|
||||
}
|
||||
|
||||
function goPage(page: number) {
|
||||
const next = Math.min(totalPages.value, Math.max(1, page));
|
||||
if (next === pagination.value.current) return;
|
||||
pagination.value.current = next;
|
||||
void searchWarehouses();
|
||||
}
|
||||
|
||||
function selectAll() {
|
||||
emit('update:scope', 'all');
|
||||
emit('update:selectedWarehouseId', undefined);
|
||||
emit('select', { scope: 'all', warehouse: null });
|
||||
}
|
||||
|
||||
function selectUnassigned() {
|
||||
emit('update:scope', 'unassigned');
|
||||
emit('update:selectedWarehouseId', undefined);
|
||||
emit('select', { scope: 'unassigned', warehouse: null });
|
||||
}
|
||||
|
||||
function selectWarehouse(wh: WarehouseVO.Info) {
|
||||
emit('update:scope', 'warehouse');
|
||||
emit('update:selectedWarehouseId', wh.id);
|
||||
emit('select', { scope: 'warehouse', warehouse: wh });
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
await Promise.all([loadUnassignedCount(), searchWarehouses()]);
|
||||
}
|
||||
|
||||
defineExpose({ refresh });
|
||||
|
||||
onMounted(() => {
|
||||
void refresh();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="collapsed"
|
||||
class="flex h-full min-h-0 w-full flex-col items-center gap-1 pb-2 pt-3"
|
||||
>
|
||||
<Tooltip title="展开仓库列表">
|
||||
<Button type="text" size="small" class="!px-1" @click="emit('expand')">
|
||||
<PanelOpenIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<div
|
||||
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
|
||||
>
|
||||
<Tooltip title="全部 SKU">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||
:class="
|
||||
allSelected
|
||||
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||
: undefined
|
||||
"
|
||||
@click="selectAll"
|
||||
>
|
||||
<div
|
||||
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip title="未分配">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||
:class="
|
||||
unassignedSelected
|
||||
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||
: undefined
|
||||
"
|
||||
@click="selectUnassigned"
|
||||
>
|
||||
<div
|
||||
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<Spin
|
||||
:spinning="loading"
|
||||
size="small"
|
||||
wrapper-class-name="warehouse-sidebar-collapsed-spin"
|
||||
>
|
||||
<div class="flex w-full flex-col items-center gap-1.5">
|
||||
<Tooltip
|
||||
v-for="wh in warehouses"
|
||||
:key="wh.id"
|
||||
:title="`${wh.name}(${wh.skuCount ?? 0})`"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||
:class="
|
||||
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||
: undefined
|
||||
"
|
||||
@click="selectWarehouse(wh)"
|
||||
>
|
||||
<div
|
||||
class="flex h-9 w-9 items-center justify-center rounded-md border border-border bg-card text-xs font-medium"
|
||||
>
|
||||
{{ (wh.name || wh.code || '?').slice(0, 1) }}
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="totalPages > 1"
|
||||
class="flex shrink-0 flex-col items-center gap-0.5"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-6 !px-1"
|
||||
:disabled="pagination.current <= 1 || loading"
|
||||
@click="goPage(pagination.current - 1)"
|
||||
>
|
||||
<ChevronUpIcon class="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<span class="text-[10px] leading-none text-muted-foreground">
|
||||
{{ pagination.current }}/{{ totalPages }}
|
||||
</span>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-6 !px-1"
|
||||
:disabled="pagination.current >= totalPages || loading"
|
||||
@click="goPage(pagination.current + 1)"
|
||||
>
|
||||
<ChevronDownIcon class="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card
|
||||
v-else
|
||||
class="flex h-full flex-col overflow-hidden"
|
||||
:class="fluid ? 'w-full min-w-0' : 'w-[320px] shrink-0'"
|
||||
:body-style="{
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '8px',
|
||||
minHeight: 0,
|
||||
minWidth: 0,
|
||||
overflow: 'hidden',
|
||||
padding: '12px',
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<span class="flex items-center gap-2 text-base font-semibold">
|
||||
<WarehouseIcon class="h-4 w-4" />
|
||||
发货仓
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-if="showCollapseAction" #extra>
|
||||
<Tooltip title="收起仓库列表">
|
||||
<Button type="text" size="small" class="!px-1" @click="emit('collapse')">
|
||||
<PanelCloseIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</template>
|
||||
|
||||
<div class="flex min-w-0 shrink-0 items-center gap-2">
|
||||
<Input
|
||||
v-model:value="keyword"
|
||||
placeholder="名称/编码"
|
||||
allow-clear
|
||||
class="min-w-0 flex-1"
|
||||
@press-enter="searchWarehouses(true)"
|
||||
/>
|
||||
<Button type="primary" class="shrink-0" @click="searchWarehouses(true)">
|
||||
搜索
|
||||
</Button>
|
||||
<Button class="shrink-0" @click="resetSearch">重置</Button>
|
||||
</div>
|
||||
|
||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto">
|
||||
<Card
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="cursor-pointer !shadow-none hover:border-primary"
|
||||
:class="allSelected ? 'border-primary bg-primary/5' : undefined"
|
||||
@click="selectAll"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="min-w-0 truncate text-sm font-medium">全部</span>
|
||||
<span class="shrink-0 text-xs text-muted-foreground">全部 SKU</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="cursor-pointer !shadow-none hover:border-primary"
|
||||
:class="unassignedSelected ? 'border-primary bg-primary/5' : undefined"
|
||||
@click="selectUnassigned"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="min-w-0 truncate text-sm font-medium">未分配</span>
|
||||
<Tag class="m-0 shrink-0">{{ unassignedCount }}</Tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Spin
|
||||
:spinning="loading"
|
||||
wrapper-class-name="warehouse-sidebar-list-spin"
|
||||
>
|
||||
<Empty
|
||||
v-if="!loading && warehouses.length === 0"
|
||||
class="py-8"
|
||||
description="暂无启用仓库"
|
||||
/>
|
||||
<div v-else class="flex flex-col gap-2">
|
||||
<Card
|
||||
v-for="wh in warehouses"
|
||||
:key="wh.id"
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="cursor-pointer !shadow-none hover:border-primary"
|
||||
:class="
|
||||
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||
? 'border-primary bg-primary/5'
|
||||
: undefined
|
||||
"
|
||||
@click="selectWarehouse(wh)"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-card"
|
||||
>
|
||||
<WarehouseIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="min-w-0 truncate text-sm font-medium">
|
||||
{{ wh.name }}
|
||||
</span>
|
||||
<Tag class="m-0 shrink-0">{{ wh.skuCount ?? 0 }}</Tag>
|
||||
</div>
|
||||
<div class="truncate text-xs text-muted-foreground">
|
||||
{{ wh.code }}
|
||||
<template v-if="wh.province || wh.city">
|
||||
· {{ [wh.province, wh.city].filter(Boolean).join(' ') }}
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
|
||||
>
|
||||
<Button
|
||||
size="small"
|
||||
class="shrink-0"
|
||||
:disabled="pagination.current <= 1 || loading"
|
||||
@click="goPage(pagination.current - 1)"
|
||||
>
|
||||
上一页
|
||||
</Button>
|
||||
<span
|
||||
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
|
||||
>
|
||||
{{ pagination.current }} / {{ totalPages }}
|
||||
<span class="ml-1 opacity-70">({{ pagination.total }})</span>
|
||||
</span>
|
||||
<Button
|
||||
size="small"
|
||||
class="shrink-0"
|
||||
:disabled="pagination.current >= totalPages || loading"
|
||||
@click="goPage(pagination.current + 1)"
|
||||
>
|
||||
下一页
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.warehouse-sidebar-collapsed-spin),
|
||||
:deep(.warehouse-sidebar-collapsed-spin .ant-spin-container) {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
:deep(.warehouse-sidebar-list-spin),
|
||||
:deep(.warehouse-sidebar-list-spin .ant-spin-container) {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,334 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 发货仓商品:左栏仓筛选,右栏 SKU 列表与批量分配默认仓。
|
||||
*/
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||
import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||
import type { WarehouseSidebarScope } from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
message,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
batchAssignWarehouseSkusApi,
|
||||
getEnabledWarehousesApi,
|
||||
getWarehouseSkuPageApi,
|
||||
} from '#/api/ec/warehouse';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
import EcWarehouseColPage from '#/views/ec/components/EcWarehouseColPage.vue';
|
||||
|
||||
defineOptions({ name: 'WarehouseSkuManagement' });
|
||||
|
||||
const AssignIcon = createIconifyIcon('lucide:package-plus');
|
||||
const ClearIcon = createIconifyIcon('lucide:unlink');
|
||||
|
||||
const scope = ref<WarehouseSidebarScope>('all');
|
||||
const selectedWarehouseId = ref<number | undefined>(undefined);
|
||||
const selectedWarehouseName = ref<string | undefined>(undefined);
|
||||
const colPageRef = ref<InstanceType<typeof EcWarehouseColPage> | null>(null);
|
||||
|
||||
const loading = ref(false);
|
||||
const hasSelected = ref(false);
|
||||
const keywords = ref('');
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const assignOpen = ref(false);
|
||||
const assignLoading = ref(false);
|
||||
const assignTargetId = ref<number | undefined>(undefined);
|
||||
const assignWarehouseOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
const showCheckboxColumn = useActionColumnVisible(['ec:warehouse:update']);
|
||||
|
||||
const titleText = computed(() => {
|
||||
if (scope.value === 'unassigned') return '未分配 SKU';
|
||||
if (scope.value === 'warehouse') {
|
||||
return selectedWarehouseName.value
|
||||
? `发货仓「${selectedWarehouseName.value}」的 SKU`
|
||||
: '发货仓 SKU';
|
||||
}
|
||||
return '全部 SKU';
|
||||
});
|
||||
|
||||
const tableBaseColumns: VxeGridProps<ProductSkuVO.Info>['columns'] = [
|
||||
{ type: 'seq' as const, minWidth: 'auto', title: '序号' },
|
||||
{ field: 'productName', title: '商品', minWidth: 140 },
|
||||
{ field: 'name', title: 'SKU', minWidth: 120 },
|
||||
{ field: 'skuCode', title: '编码', minWidth: 120 },
|
||||
{ field: 'warehouseName', title: '发货仓', minWidth: 120 },
|
||||
{
|
||||
field: 'weightG',
|
||||
title: '实重(g)',
|
||||
minWidth: 90,
|
||||
},
|
||||
];
|
||||
|
||||
const checkboxColumn: NonNullable<
|
||||
VxeGridProps<ProductSkuVO.Info>['columns']
|
||||
>[number] = {
|
||||
type: 'checkbox' as const,
|
||||
width: 48,
|
||||
};
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
showCheckboxColumn.value
|
||||
? [checkboxColumn, ...(tableBaseColumns ?? [])]
|
||||
: (tableBaseColumns ?? []),
|
||||
);
|
||||
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '商品/SKU/编码',
|
||||
allowClear: true,
|
||||
onChange: (e: Event) => {
|
||||
keywords.value = (e.target as HTMLInputElement).value;
|
||||
},
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'keywords',
|
||||
label: '关键字',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
handleSubmit: async () => gridReloadRef.value?.(),
|
||||
handleReset: async () => {
|
||||
keywords.value = '';
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
}));
|
||||
|
||||
function buildFilters() {
|
||||
return {
|
||||
keywords: keywords.value || undefined,
|
||||
warehouseId:
|
||||
scope.value === 'warehouse' ? selectedWarehouseId.value : undefined,
|
||||
unassignedOnly: scope.value === 'unassigned' ? true : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const gridOptions: VxeGridProps<ProductSkuVO.Info> = {
|
||||
columns: tableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { keyField: 'id' },
|
||||
checkboxConfig: { highlight: true },
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50, 100] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getWarehouseSkuPageApi({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: buildFilters(),
|
||||
});
|
||||
return { items: data.records, total: data.total };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '发货仓商品',
|
||||
gridEvents: {
|
||||
checkboxAll: () => syncSelection(),
|
||||
checkboxChange: () => syncSelection(),
|
||||
},
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
syncVxeGridColumns(gridApi, tableColumns);
|
||||
|
||||
function syncSelection() {
|
||||
const vxeTable = gridApi.grid;
|
||||
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
hasSelected.value = rows.length > 0;
|
||||
}
|
||||
|
||||
function onSidebarSelect(payload: {
|
||||
scope: WarehouseSidebarScope;
|
||||
warehouse: WarehouseVO.Info | null;
|
||||
}) {
|
||||
scope.value = payload.scope;
|
||||
selectedWarehouseId.value = payload.warehouse?.id;
|
||||
selectedWarehouseName.value = payload.warehouse?.name;
|
||||
hasSelected.value = false;
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function loadAssignOptions() {
|
||||
const list = await getEnabledWarehousesApi();
|
||||
assignWarehouseOptions.value = (list ?? []).map((w) => ({
|
||||
label: `${w.name}(${w.code})`,
|
||||
value: w.id,
|
||||
}));
|
||||
}
|
||||
|
||||
function getSelectedSkuIds(): number[] {
|
||||
const rows: ProductSkuVO.Info[] =
|
||||
gridApi.grid?.getCheckboxRecords?.() ?? [];
|
||||
return rows.map((r) => r.id).filter((id) => id != null);
|
||||
}
|
||||
|
||||
async function openAssignSelected() {
|
||||
const ids = getSelectedSkuIds();
|
||||
if (!ids.length) {
|
||||
message.warning('请先勾选 SKU');
|
||||
return;
|
||||
}
|
||||
assignTargetId.value =
|
||||
scope.value === 'warehouse' ? selectedWarehouseId.value : undefined;
|
||||
await loadAssignOptions();
|
||||
assignOpen.value = true;
|
||||
}
|
||||
|
||||
async function confirmAssign() {
|
||||
const ids = getSelectedSkuIds();
|
||||
if (!ids.length) {
|
||||
message.warning('请先勾选 SKU');
|
||||
return;
|
||||
}
|
||||
if (assignTargetId.value == null) {
|
||||
message.warning('请选择目标发货仓');
|
||||
return;
|
||||
}
|
||||
assignLoading.value = true;
|
||||
try {
|
||||
const res = await batchAssignWarehouseSkusApi({
|
||||
skuIds: ids,
|
||||
warehouseId: assignTargetId.value,
|
||||
});
|
||||
message.success(`已更新 ${res?.updated ?? ids.length} 个 SKU`);
|
||||
assignOpen.value = false;
|
||||
hasSelected.value = false;
|
||||
gridApi.reload();
|
||||
colPageRef.value?.refreshSidebar();
|
||||
} finally {
|
||||
assignLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function clearAssign() {
|
||||
const ids = getSelectedSkuIds();
|
||||
if (!ids.length) {
|
||||
message.warning('请先勾选 SKU');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '取消发货仓分配',
|
||||
content: `确定将选中的 ${ids.length} 个 SKU 设为未分配?`,
|
||||
okText: '确定',
|
||||
cancelText: '取消',
|
||||
async onOk() {
|
||||
const res = await batchAssignWarehouseSkusApi({
|
||||
skuIds: ids,
|
||||
warehouseId: null,
|
||||
});
|
||||
message.success(`已取消 ${res?.updated ?? ids.length} 个分配`);
|
||||
hasSelected.value = false;
|
||||
gridApi.reload();
|
||||
colPageRef.value?.refreshSidebar();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EcWarehouseColPage
|
||||
ref="colPageRef"
|
||||
:scope="scope"
|
||||
:selected-warehouse-id="selectedWarehouseId"
|
||||
@select="onSidebarSelect"
|
||||
>
|
||||
<Card
|
||||
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
|
||||
:body-style="{
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
padding: 0,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<span class="text-base font-semibold">{{ titleText }}</span>
|
||||
</template>
|
||||
<template #extra>
|
||||
<Space wrap size="small">
|
||||
<PermissionGate code="ec:warehouse:update">
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!hasSelected"
|
||||
@click="openAssignSelected"
|
||||
>
|
||||
<AssignIcon class="mr-1 h-4 w-4" />
|
||||
批量分配到仓
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="ec:warehouse:update">
|
||||
<Button danger :disabled="!hasSelected" @click="clearAssign">
|
||||
<ClearIcon class="mr-1 h-4 w-4" />
|
||||
取消分配
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-hidden">
|
||||
<Grid :loading="loading" />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
v-model:open="assignOpen"
|
||||
title="批量分配发货仓"
|
||||
:confirm-loading="assignLoading"
|
||||
ok-text="确定分配"
|
||||
destroy-on-close
|
||||
@ok="confirmAssign"
|
||||
>
|
||||
<div class="space-y-3 py-2">
|
||||
<div class="text-sm text-muted-foreground">
|
||||
已选 {{ getSelectedSkuIds().length }} 个 SKU,将设置其默认发货仓。
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-sm">目标发货仓</div>
|
||||
<Select
|
||||
v-model:value="assignTargetId"
|
||||
class="w-full"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
placeholder="选择发货仓"
|
||||
:options="assignWarehouseOptions"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</EcWarehouseColPage>
|
||||
</template>
|
||||
Reference in New Issue
Block a user