feat: 新增拼多多商品关联内部商品

This commit is contained in:
2026-08-17 11:10:43 +08:00
parent d91b7cd168
commit fa5c4929c9
16 changed files with 665 additions and 25 deletions
@@ -4,6 +4,7 @@ import type { PddGoodsVO } from '#/api/channel/pdd/goods';
import { ref } from 'vue';
import {
Button,
Descriptions,
DescriptionsItem,
Drawer,
@@ -18,6 +19,10 @@ import { getPddGoodsDetailApi } from '#/api/channel/pdd/goods';
defineOptions({ name: 'PddGoodsDetailDrawer' });
const emit = defineEmits<{
openInternalProduct: [row: PddGoodsVO.Info];
}>();
const openFlag = ref(false);
const loading = ref(false);
const shopName = ref('');
@@ -69,6 +74,14 @@ function close() {
openFlag.value = false;
}
function openInternalProduct() {
if (!detail.value?.productId) {
message.warning('未关联内部商品');
return;
}
emit('openInternalProduct', detail.value);
}
defineExpose({ open, close });
</script>
@@ -113,6 +126,18 @@ defineExpose({ open, close });
<DescriptionsItem label="渠道店铺" :span="2">
{{ shopName || `渠道店#${detail.shopId}` }}
</DescriptionsItem>
<DescriptionsItem label="内部商品" :span="2">
<Button
v-if="detail.productId"
type="link"
size="small"
class="!px-0"
@click="openInternalProduct"
>
{{ detail.productName || `商品#${detail.productId}` }}
</Button>
<span v-else>-</span>
</DescriptionsItem>
<DescriptionsItem label="总库存">
{{ detail.goodsQuantity ?? 0 }}
</DescriptionsItem>
@@ -19,12 +19,14 @@ import { getPddShopPageApi } from '#/api/channel/pdd/shop';
import PddGoodsDetailDrawer from './components/PddGoodsDetailDrawer.vue';
import PddShopDetailModal from '#/views/channel/pdd/shop/components/PddShopDetailModal.vue';
import ProductDetailDrawer from '#/views/ec/product/list/components/ProductDetailDrawer.vue';
defineOptions({ name: 'PddGoodsManagement' });
const loading = ref(false);
const detailDrawerRef = ref<InstanceType<typeof PddGoodsDetailDrawer>>();
const shopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal>>();
const productDetailDrawerRef = ref<InstanceType<typeof ProductDetailDrawer>>();
const shopOptions = ref<{ label: string; value: number }[]>([]);
const shopNameById = ref<Record<number, string>>({});
@@ -88,6 +90,12 @@ const gridOptions: VxeGridProps<PddGoodsVO.Info> = {
showOverflow: 'tooltip' as const,
slots: { default: 'shop' },
},
{
title: '内部商品',
minWidth: 140,
showOverflow: 'tooltip' as const,
slots: { default: 'productName' },
},
{
title: '状态',
width: 90,
@@ -295,6 +303,14 @@ function openShopDetail(row: PddGoodsVO.Info) {
shopDetailModalRef.value?.open(row.shopId);
}
async function openInternalProduct(row: PddGoodsVO.Info) {
if (!row.productId) {
message.warning('未关联内部商品');
return;
}
await productDetailDrawerRef.value?.openById(row.productId, row.productName);
}
async function handleDelete(row: PddGoodsVO.Info) {
try {
await deletePddGoodsApi(row.id);
@@ -330,6 +346,19 @@ onMounted(async () => {
</Button>
</template>
<template #productName="{ row }: { row: PddGoodsVO.Info }">
<Button
v-if="row.productId"
type="link"
size="small"
class="!px-0"
@click="openInternalProduct(row)"
>
{{ row.productName || `商品#${row.productId}` }}
</Button>
<span v-else class="text-slate-400">-</span>
</template>
<template #shop="{ row }: { row: PddGoodsVO.Info }">
<Button
v-if="row.shopId"
@@ -370,8 +399,12 @@ onMounted(async () => {
</template>
</Grid>
<PddGoodsDetailDrawer ref="detailDrawerRef" />
<PddGoodsDetailDrawer
ref="detailDrawerRef"
@open-internal-product="openInternalProduct"
/>
<PddShopDetailModal ref="shopDetailModalRef" />
<ProductDetailDrawer ref="productDetailDrawerRef" />
</Page>
</template>
@@ -248,7 +248,13 @@ async function handleSyncGoods(row: PddShopVO.Info) {
try {
const result = await syncPddGoodsByShopApi(row.id);
message.success(
`同步完成:共 ${result.syncedCount ?? 0} 个商品(新增 ${result.createdCount ?? 0} / 更新 ${result.updatedCount ?? 0}),SKU ${result.skuCount ?? 0}`,
`同步完成:共 ${result.syncedCount ?? 0} 个商品(新增 ${result.createdCount ?? 0} / 更新 ${result.updatedCount ?? 0}),SKU ${result.skuCount ?? 0}${
result.autoCreatedProductCount
? `,自动建内部商品 ${result.autoCreatedProductCount}`
: ''
}${
result.skippedCount ? `,跳过 ${result.skippedCount}` : ''
}`,
);
gridApi.reload();
} catch (error: any) {
@@ -0,0 +1,230 @@
<script lang="ts" setup>
import type { ProductVO } from '#/api/ec/product/types';
import { computed, h, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import {
Descriptions,
DescriptionsItem,
Drawer,
Image,
Spin,
Table,
message,
} from 'ant-design-vue';
import { getProductSkuPageApi } from '#/api/ec/product/sku';
defineOptions({ name: 'ProductDetailDrawer' });
const ImageIcon = createIconifyIcon('lucide:image');
const openFlag = ref(false);
const loading = ref(false);
const product = ref<ProductVO.Info | null>(null);
const formatCost = (val?: number) => `¥${(val ?? 0).toFixed(2)}`;
const skuDataSource = computed(() => product.value?.skus ?? []);
const skuColumns = [
{
title: '图片',
dataIndex: 'imageUrl',
key: 'imageUrl',
width: 72,
align: 'center' as const,
customRender: ({ record }: { record: ProductVO.SkuInfo }) => {
if (record.imageUrl) {
return h(Image, {
src: record.imageUrl,
width: 40,
height: 40,
class: 'object-cover',
preview: true,
});
}
return h(ImageIcon, {
class: 'mx-auto h-5 w-5 text-slate-300 dark:text-[hsl(240deg_5%_45%)]',
});
},
},
{
title: 'SKU 编码',
dataIndex: 'skuCode',
key: 'skuCode',
width: 140,
customRender: ({ text }: { text?: string }) => text || '-',
},
{
title: 'SKU 名称',
dataIndex: 'name',
key: 'name',
ellipsis: true,
},
{
title: '商品成本',
dataIndex: 'productCost',
key: 'productCost',
width: 110,
customRender: ({ record }: { record: ProductVO.SkuInfo }) =>
formatCost(record.productCost),
},
{
title: '运费成本',
dataIndex: 'shippingCost',
key: 'shippingCost',
width: 100,
customRender: ({ record }: { record: ProductVO.SkuInfo }) =>
formatCost(record.shippingCost),
},
{
title: '其他成本',
dataIndex: 'otherCost',
key: 'otherCost',
width: 100,
customRender: ({ record }: { record: ProductVO.SkuInfo }) =>
formatCost(record.otherCost),
},
{
title: '成本生效日',
dataIndex: 'costEffectiveFrom',
key: 'costEffectiveFrom',
width: 120,
customRender: ({ text }: { text?: string }) => text || '-',
},
{
title: '备注',
dataIndex: 'remark',
key: 'remark',
ellipsis: true,
customRender: ({ text }: { text?: string }) => text || '-',
},
];
/** 直接传入已组装好的商品详情 */
function open(record: ProductVO.Info) {
product.value = record;
openFlag.value = true;
}
/**
* 按内部商品 ID 加载只读详情。
* @param productId 内部商品 ID
* @param fallbackName 列表侧已知名称(可选)
*/
async function openById(productId: number, fallbackName?: string) {
if (!productId) {
message.warning('未关联内部商品');
return;
}
openFlag.value = true;
loading.value = true;
product.value = null;
try {
const data = await getProductSkuPageApi({
page: 1,
pageSize: 500,
filters: { productId },
});
const skus = (data.records ?? []) as ProductVO.SkuInfo[];
const first = skus[0];
product.value = {
id: productId,
companyId: first?.companyId ?? 0,
name: fallbackName || first?.productName || `商品#${productId}`,
mainImage: first?.imageUrl,
createTime: first?.createTime ?? '',
updateTime: first?.updateTime ?? '',
skus,
};
} catch (error: any) {
console.error(error);
message.error(error?.message || '加载内部商品详情失败');
openFlag.value = false;
} finally {
loading.value = false;
}
}
function close() {
openFlag.value = false;
}
defineExpose({ open, openById, close });
</script>
<template>
<Drawer
v-model:open="openFlag"
:title="product?.name ? `内部商品 - ${product.name}` : '内部商品详情'"
width="720"
destroy-on-close
>
<Spin :spinning="loading">
<div v-if="product" class="space-y-5">
<div
class="flex flex-col gap-4 rounded-xl border border-slate-200 bg-slate-50/80 p-4 sm:flex-row sm:items-start dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
>
<div
class="flex h-[96px] w-[96px] shrink-0 items-center justify-center overflow-hidden rounded-lg border border-slate-200 bg-white dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
<Image
v-if="product.mainImage"
:src="product.mainImage"
:width="96"
:height="96"
class="object-cover"
:preview="true"
/>
<ImageIcon
v-else
class="h-8 w-8 text-slate-300 dark:text-[hsl(240deg_5%_45%)]"
/>
</div>
<div class="min-w-0 flex-1">
<div
class="mb-3 text-base font-semibold text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
>
{{ product.name }}
</div>
<Descriptions :column="1" size="small" :colon="false">
<DescriptionsItem label="商品编码">
{{ product.productCode || '-' }}
</DescriptionsItem>
<DescriptionsItem label="商品类目">
{{ product.categoryName || '-' }}
</DescriptionsItem>
<DescriptionsItem label="SKU 数量">
{{ product.skus?.length ?? 0 }}
</DescriptionsItem>
<DescriptionsItem label="创建时间">
{{ product.createTime || '-' }}
</DescriptionsItem>
</Descriptions>
</div>
</div>
<div>
<div
class="mb-3 text-sm font-medium text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
>
SKU 明细
</div>
<Table
:columns="skuColumns"
:data-source="skuDataSource"
:pagination="false"
row-key="id"
size="small"
bordered
:scroll="{ x: 700 }"
/>
</div>
</div>
</Spin>
</Drawer>
</template>