mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
refactor: 去掉拼多多商品手工增删改接口与删除入口
This commit is contained in:
@@ -24,11 +24,6 @@ export async function getPddGoodsDetailApi(id: number) {
|
||||
return requestClient.get<PddGoodsVO.Info>(`/channel/pdd/goods/detail/${id}`);
|
||||
}
|
||||
|
||||
/** 删除拼多多商品及 SKU */
|
||||
export async function deletePddGoodsApi(id: number) {
|
||||
return requestClient.delete<void>(`/channel/pdd/goods/delete/${id}`);
|
||||
}
|
||||
|
||||
/** 按渠道店铺同步商品 */
|
||||
export async function syncPddGoodsByShopApi(pddShopId: number) {
|
||||
return requestClient.post<PddGoodsVO.SyncResult>(
|
||||
|
||||
@@ -68,6 +68,16 @@ export async function getProductSkuByProductAndSkuApi(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 SKU 编码反查内部 SKU(含所属商品 id/名称)
|
||||
*/
|
||||
export async function getProductSkuBySkuCodeApi(skuCode: string) {
|
||||
return requestClient.get<ProductSkuVO.Info>(
|
||||
'/ec/product/sku/find-by-sku-code',
|
||||
{ params: { skuCode } },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据商品名称和 SKU 编码查询商品 SKU
|
||||
*/
|
||||
|
||||
+59
-8
@@ -4,6 +4,7 @@ import type { PddGoodsVO } from '#/api/channel/pdd/goods';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Descriptions,
|
||||
DescriptionsItem,
|
||||
Drawer,
|
||||
@@ -15,6 +16,8 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getPddGoodsDetailApi } from '#/api/channel/pdd/goods';
|
||||
import { getProductSkuBySkuCodeApi } from '#/api/ec/product/sku';
|
||||
import ProductDetailModal from '#/views/ec/product/list/components/ProductDetailModal.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsDetailDrawer' });
|
||||
|
||||
@@ -22,8 +25,18 @@ const openFlag = ref(false);
|
||||
const loading = ref(false);
|
||||
const shopName = ref('');
|
||||
const detail = ref<null | PddGoodsVO.Info>(null);
|
||||
const productDetailModalRef = ref<InstanceType<typeof ProductDetailModal>>();
|
||||
const resolvingOuterId = ref<null | string>(null);
|
||||
|
||||
const skuColumns = [
|
||||
{
|
||||
// POP outer_goods_id:商家外部商品编码(非内部商品)
|
||||
title: '外部商品编码',
|
||||
dataIndex: 'outerGoodsId',
|
||||
key: 'outerGoodsId',
|
||||
ellipsis: true,
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
title: '外部SKU',
|
||||
dataIndex: 'outerId',
|
||||
@@ -40,13 +53,6 @@ const skuColumns = [
|
||||
width: 80,
|
||||
},
|
||||
{ title: '在架', key: 'isSkuOnsale', width: 80 },
|
||||
{
|
||||
title: '外部商品',
|
||||
dataIndex: 'outerGoodsId',
|
||||
key: 'outerGoodsId',
|
||||
ellipsis: true,
|
||||
width: 120,
|
||||
},
|
||||
];
|
||||
|
||||
async function open(id: number, shopLabel?: string) {
|
||||
@@ -69,6 +75,31 @@ function close() {
|
||||
openFlag.value = false;
|
||||
}
|
||||
|
||||
/** 点击外部 SKU:按 sku_code 反查并打开内部商品详情 */
|
||||
async function openInternalProductByOuterId(outerId?: string) {
|
||||
const code = outerId?.trim();
|
||||
if (!code) {
|
||||
message.warning('该规格无外部SKU编码');
|
||||
return;
|
||||
}
|
||||
if (resolvingOuterId.value) {
|
||||
return;
|
||||
}
|
||||
resolvingOuterId.value = code;
|
||||
try {
|
||||
const sku = await getProductSkuBySkuCodeApi(code);
|
||||
if (!sku?.productId) {
|
||||
message.warning(`未匹配到内部商品:${code}`);
|
||||
return;
|
||||
}
|
||||
await productDetailModalRef.value?.openById(sku.productId, sku.productName);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || `未找到内部SKU:${code}`);
|
||||
} finally {
|
||||
resolvingOuterId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open, close });
|
||||
</script>
|
||||
|
||||
@@ -137,7 +168,25 @@ defineExpose({ open, close });
|
||||
:scroll="{ x: 700 }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'isSkuOnsale'">
|
||||
<template v-if="column.key === 'outerGoodsId'">
|
||||
<span :class="record.outerGoodsId ? '' : 'text-slate-400'">
|
||||
{{ record.outerGoodsId || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'outerId'">
|
||||
<Button
|
||||
v-if="record.outerId"
|
||||
type="link"
|
||||
size="small"
|
||||
class="!px-0"
|
||||
:loading="resolvingOuterId === record.outerId"
|
||||
@click="openInternalProductByOuterId(record.outerId)"
|
||||
>
|
||||
{{ record.outerId }}
|
||||
</Button>
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'isSkuOnsale'">
|
||||
<Tag :color="record.isSkuOnsale === 1 ? 'success' : 'default'">
|
||||
{{ record.isSkuOnsale === 1 ? '在架' : '下架' }}
|
||||
</Tag>
|
||||
@@ -146,5 +195,7 @@ defineExpose({ open, close });
|
||||
</Table>
|
||||
</template>
|
||||
</Spin>
|
||||
|
||||
<ProductDetailModal ref="productDetailModalRef" :show-actions="false" />
|
||||
</Drawer>
|
||||
</template>
|
||||
|
||||
@@ -6,13 +6,10 @@ import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Space, Tag, message } from 'ant-design-vue';
|
||||
import { Button, Card, Image, Tag, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePddGoodsApi,
|
||||
getPddGoodsPageApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddGoodsPageApi } from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import PddShopColPage from '#/views/channel/pdd/components/PddShopColPage.vue';
|
||||
@@ -123,7 +120,7 @@ const gridOptions: VxeGridProps<PddGoodsVO.Info> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 140,
|
||||
width: 88,
|
||||
fixed: 'right' as const,
|
||||
showOverflow: false,
|
||||
slots: { default: 'action' },
|
||||
@@ -288,16 +285,6 @@ function openShopDetail(row: PddGoodsVO.Info) {
|
||||
shopDetailModalRef.value?.open(row.shopId);
|
||||
}
|
||||
|
||||
async function handleDelete(row: PddGoodsVO.Info) {
|
||||
try {
|
||||
await deletePddGoodsApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadShopNames();
|
||||
});
|
||||
@@ -373,19 +360,9 @@ onMounted(async () => {
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Space size="small" :wrap="false">
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
<PermissionGate code="channel:pdd:goods:delete">
|
||||
<Popconfirm
|
||||
title="确定删除该商品及全部 SKU 吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
+133
-69
@@ -8,15 +8,26 @@ import { useRouter } from 'vue-router';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Image, Space, Table, Tooltip } from 'ant-design-vue';
|
||||
import { Button, Image, Space, Spin, Table, Tooltip, message } from 'ant-design-vue';
|
||||
|
||||
import { getProductSkuPageApi } from '#/api/ec/product/sku';
|
||||
|
||||
defineOptions({ name: 'ProductDetailModal' });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 是否展示编辑/成本等操作按钮,渠道侧只读可关 */
|
||||
showActions?: boolean;
|
||||
}>(),
|
||||
{ showActions: true },
|
||||
);
|
||||
|
||||
const ChartIcon = createIconifyIcon('lucide:line-chart');
|
||||
const EditIcon = createIconifyIcon('lucide:square-pen');
|
||||
const ImageIcon = createIconifyIcon('lucide:image');
|
||||
|
||||
const product = ref<ProductVO.Info | null>(null);
|
||||
const loading = ref(false);
|
||||
const router = useRouter();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -131,15 +142,60 @@ const [Modal, modalApi] = useVbenModal({
|
||||
footer: false,
|
||||
});
|
||||
|
||||
/** 打开详情模态框 */
|
||||
/** 打开详情模态框(已有完整商品对象) */
|
||||
function open(record: ProductVO.Info) {
|
||||
product.value = record;
|
||||
loading.value = false;
|
||||
modalApi.setState({
|
||||
title: `商品详情 - ${record.name}`,
|
||||
});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按内部商品 ID 加载后打开。
|
||||
* @param productId 内部商品 ID
|
||||
* @param fallbackName 列表侧已知名称(可选)
|
||||
*/
|
||||
async function openById(productId: number, fallbackName?: string) {
|
||||
if (!productId) {
|
||||
message.warning('未关联内部商品');
|
||||
return;
|
||||
}
|
||||
product.value = null;
|
||||
loading.value = true;
|
||||
modalApi.setState({
|
||||
title: fallbackName ? `商品详情 - ${fallbackName}` : '商品详情',
|
||||
});
|
||||
modalApi.open();
|
||||
try {
|
||||
const data = await getProductSkuPageApi({
|
||||
page: 1,
|
||||
pageSize: 500,
|
||||
filters: { productId },
|
||||
});
|
||||
const skus = (data.records ?? []) as ProductVO.SkuInfo[];
|
||||
const first = skus[0];
|
||||
const name = fallbackName || first?.productName || `商品#${productId}`;
|
||||
product.value = {
|
||||
id: productId,
|
||||
companyId: first?.companyId ?? 0,
|
||||
name,
|
||||
mainImage: first?.imageUrl,
|
||||
createTime: first?.createTime ?? '',
|
||||
updateTime: first?.updateTime ?? '',
|
||||
skus,
|
||||
};
|
||||
modalApi.setState({ title: `商品详情 - ${name}` });
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
message.error(error?.message || '加载内部商品详情失败');
|
||||
modalApi.close();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳转经营统计 */
|
||||
function goOverview() {
|
||||
if (!product.value) return;
|
||||
@@ -164,88 +220,96 @@ function handleManageCost() {
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
openById,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<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%)]"
|
||||
>
|
||||
<Spin :spinning="loading">
|
||||
<div v-if="product" class="space-y-5">
|
||||
<!-- 商品基础信息 -->
|
||||
<div
|
||||
class="flex h-[120px] w-[120px] 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%)]"
|
||||
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%)]"
|
||||
>
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:width="120"
|
||||
:height="120"
|
||||
class="object-cover"
|
||||
:preview="true"
|
||||
/>
|
||||
<ImageIcon
|
||||
v-else
|
||||
class="h-10 w-10 text-slate-300 dark:text-[hsl(240deg_5%_45%)]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="min-w-0 flex-1 space-y-2 text-sm">
|
||||
<div class="text-lg font-semibold text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ product.name }}
|
||||
<div
|
||||
class="flex h-[120px] w-[120px] 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="120"
|
||||
:height="120"
|
||||
class="object-cover"
|
||||
:preview="true"
|
||||
/>
|
||||
<ImageIcon
|
||||
v-else
|
||||
class="h-10 w-10 text-slate-300 dark:text-[hsl(240deg_5%_45%)]"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品编码:</span>
|
||||
<span>{{ product.productCode || '-' }}</span>
|
||||
|
||||
<div class="min-w-0 flex-1 space-y-2 text-sm">
|
||||
<div class="text-lg font-semibold text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ product.name }}
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品类目:</span>
|
||||
<span>{{ product.categoryName || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">SKU 数量:</span>
|
||||
<span>{{ product.skus?.length ?? 0 }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">创建时间:</span>
|
||||
<span>{{ product.createTime || '-' }}</span>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品编码:</span>
|
||||
<span>{{ product.productCode || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品类目:</span>
|
||||
<span>{{ product.categoryName || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">SKU 数量:</span>
|
||||
<span>{{ product.skus?.length ?? 0 }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">创建时间:</span>
|
||||
<span>{{ product.createTime || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SKU 明细表 -->
|
||||
<div>
|
||||
<div class="mb-3 text-base font-medium text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
SKU 明细
|
||||
<!-- SKU 明细表 -->
|
||||
<div>
|
||||
<div class="mb-3 text-base 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: 920 }"
|
||||
/>
|
||||
</div>
|
||||
<Table
|
||||
:columns="skuColumns"
|
||||
:data-source="skuDataSource"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
size="small"
|
||||
bordered
|
||||
:scroll="{ x: 920 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end border-t border-slate-200 pt-4 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<Space>
|
||||
<Button @click="modalApi.close()">关闭</Button>
|
||||
<Button @click="goOverview">
|
||||
<ChartIcon class="mr-1 h-4 w-4" />
|
||||
经营统计
|
||||
</Button>
|
||||
<Button @click="handleManageCost">管理成本</Button>
|
||||
<Button type="primary" @click="handleEdit">
|
||||
<EditIcon class="mr-1 h-4 w-4" />
|
||||
编辑商品
|
||||
</Button>
|
||||
</Space>
|
||||
<div class="flex justify-end border-t border-slate-200 pt-4 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<Space>
|
||||
<Button @click="modalApi.close()">关闭</Button>
|
||||
<template v-if="props.showActions">
|
||||
<Button @click="goOverview">
|
||||
<ChartIcon class="mr-1 h-4 w-4" />
|
||||
经营统计
|
||||
</Button>
|
||||
<Button @click="handleManageCost">管理成本</Button>
|
||||
<Button type="primary" @click="handleEdit">
|
||||
<EditIcon class="mr-1 h-4 w-4" />
|
||||
编辑商品
|
||||
</Button>
|
||||
</template>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="!loading" class="py-10 text-center text-slate-400">
|
||||
暂无商品数据
|
||||
</div>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user