mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 21:49:18 +08:00
feat: 新增拼多多店铺管理和商品管理
This commit is contained in:
@@ -0,0 +1,387 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PddGoodsDTO, PddGoodsVO } from '#/api/channel/pdd/goods';
|
||||
import type { PddShopVO } from '#/api/channel/pdd/shop';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Button, Image, Popconfirm, Space, Tag, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePddGoodsApi,
|
||||
getPddGoodsPageApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
|
||||
import PddGoodsDetailDrawer from './components/PddGoodsDetailDrawer.vue';
|
||||
import PddShopDetailModal from '#/views/channel/pdd/shop/components/PddShopDetailModal.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsManagement' });
|
||||
|
||||
const loading = ref(false);
|
||||
const detailDrawerRef = ref<InstanceType<typeof PddGoodsDetailDrawer>>();
|
||||
const shopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal>>();
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const shopNameById = ref<Record<number, string>>({});
|
||||
|
||||
const searchForm = ref({
|
||||
shopId: undefined as number | undefined,
|
||||
goodsName: '',
|
||||
goodsId: '',
|
||||
isOnsale: undefined as number | undefined,
|
||||
});
|
||||
|
||||
const gridReloadRef = ref<null | (() => void)>(null);
|
||||
|
||||
async function loadShops() {
|
||||
try {
|
||||
const data = await getPddShopPageApi({
|
||||
page: 1,
|
||||
pageSize: 500,
|
||||
filters: {},
|
||||
});
|
||||
const list = data.records ?? [];
|
||||
shopOptions.value = list.map((s: PddShopVO.Info) => ({
|
||||
label: s.mallName || `店铺#${s.id}`,
|
||||
value: s.id,
|
||||
}));
|
||||
const map: Record<number, string> = {};
|
||||
for (const s of list) {
|
||||
map[s.id] = s.mallName || `店铺#${s.id}`;
|
||||
}
|
||||
shopNameById.value = map;
|
||||
|
||||
await gridApi.formApi?.updateSchema([
|
||||
{
|
||||
fieldName: 'shopId',
|
||||
componentProps: { options: shopOptions.value },
|
||||
},
|
||||
]);
|
||||
} catch {
|
||||
message.error('获取渠道店铺失败');
|
||||
}
|
||||
}
|
||||
|
||||
const gridOptions: VxeGridProps<PddGoodsVO.Info> = {
|
||||
columns: [
|
||||
{ type: 'seq' as const, width: 56, title: '序号' },
|
||||
{
|
||||
title: '主图',
|
||||
width: 80,
|
||||
align: 'center' as const,
|
||||
showOverflow: false,
|
||||
slots: { default: 'thumb' },
|
||||
},
|
||||
{
|
||||
title: '商品名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
slots: { default: 'goodsName' },
|
||||
},
|
||||
{
|
||||
title: '渠道店铺',
|
||||
minWidth: 140,
|
||||
showOverflow: 'tooltip' as const,
|
||||
slots: { default: 'shop' },
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
width: 90,
|
||||
slots: { default: 'onsale' },
|
||||
},
|
||||
{
|
||||
title: 'SKU',
|
||||
width: 80,
|
||||
slots: { default: 'moreSku' },
|
||||
},
|
||||
{
|
||||
field: 'goodsQuantity',
|
||||
title: '库存',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
field: 'pddCreatedAt',
|
||||
title: '拼多多创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'lastSyncTime',
|
||||
title: '最近同步',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 140,
|
||||
fixed: 'right' as const,
|
||||
showOverflow: false,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true, height: 72 },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }: any) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<PddGoodsDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: searchForm.value.shopId,
|
||||
goodsName: searchForm.value.goodsName || undefined,
|
||||
goodsId: searchForm.value.goodsId || undefined,
|
||||
isOnsale: searchForm.value.isOnsale,
|
||||
},
|
||||
};
|
||||
const data = await getPddGoodsPageApi(params);
|
||||
return {
|
||||
items: data.records ?? [],
|
||||
total: data.total ?? 0,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取拼多多商品失败:', error);
|
||||
message.error('获取拼多多商品失败');
|
||||
return { items: [], total: 0 };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '全部店铺',
|
||||
options: shopOptions.value,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
optionFilterProp: 'label',
|
||||
onChange: (val: number | undefined) => {
|
||||
searchForm.value.shopId = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '渠道店铺',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '商品名称(模糊)',
|
||||
allowClear: true,
|
||||
onChange: (e: any) => {
|
||||
searchForm.value.goodsName = e?.target?.value ?? '';
|
||||
},
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'goodsName',
|
||||
label: '商品名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '拼多多商品ID',
|
||||
allowClear: true,
|
||||
onChange: (e: any) => {
|
||||
searchForm.value.goodsId = e?.target?.value ?? '';
|
||||
},
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'goodsId',
|
||||
label: 'goods_id',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '全部',
|
||||
allowClear: true,
|
||||
options: [
|
||||
{ label: '在架', value: 1 },
|
||||
{ label: '下架', value: 0 },
|
||||
],
|
||||
onChange: (val: number | undefined) => {
|
||||
searchForm.value.isOnsale = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'isOnsale',
|
||||
label: '在架状态',
|
||||
},
|
||||
],
|
||||
submitButtonOptions: { content: '搜索' },
|
||||
resetButtonOptions: { content: '重置' },
|
||||
handleSubmit: async () => {
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
handleReset: async () => {
|
||||
searchForm.value = {
|
||||
shopId: undefined,
|
||||
goodsName: '',
|
||||
goodsId: '',
|
||||
isOnsale: undefined,
|
||||
};
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
}));
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '拼多多渠道商品',
|
||||
});
|
||||
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function openDetail(row: PddGoodsVO.Info) {
|
||||
const shopLabel = row.shopId
|
||||
? shopNameById.value[row.shopId]
|
||||
: undefined;
|
||||
detailDrawerRef.value?.open(row.id, shopLabel);
|
||||
}
|
||||
|
||||
function openShopDetail(row: PddGoodsVO.Info) {
|
||||
if (!row.shopId) {
|
||||
message.warning('该商品未关联渠道店铺');
|
||||
return;
|
||||
}
|
||||
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 loadShops();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid class="pdd-goods-grid">
|
||||
<template #thumb="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Image
|
||||
v-if="row.thumbUrl || row.imageUrl"
|
||||
:src="row.thumbUrl || row.imageUrl"
|
||||
:width="40"
|
||||
:height="40"
|
||||
class="goods-thumb"
|
||||
/>
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
|
||||
<template #goodsName="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Button type="link" size="small" class="!px-0" @click="openDetail(row)">
|
||||
{{ row.goodsName || '-' }}
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<template #shop="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Button
|
||||
v-if="row.shopId"
|
||||
type="link"
|
||||
size="small"
|
||||
class="!px-0"
|
||||
@click="openShopDetail(row)"
|
||||
>
|
||||
{{ shopNameById[row.shopId] || `渠道店#${row.shopId}` }}
|
||||
</Button>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
|
||||
<template #onsale="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Tag :color="row.isOnsale === 1 ? 'success' : 'default'">
|
||||
{{ row.isOnsale === 1 ? '在架' : '下架' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<template #moreSku="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Tag :color="row.isMoreSku === 1 ? 'blue' : 'default'">
|
||||
{{ row.isMoreSku === 1 ? '多SKU' : '单SKU' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Space size="small" :wrap="false">
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定删除该商品及全部 SKU 吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<PddGoodsDetailDrawer ref="detailDrawerRef" />
|
||||
<PddShopDetailModal ref="shopDetailModalRef" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.goods-thumb {
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
:deep(.pdd-goods-grid .vxe-body--column) {
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user