refactor: 重构拼多多渠道同步任务和数据只关联渠道店铺

This commit is contained in:
2026-08-21 11:12:19 +08:00
parent b4fae1acb5
commit 7e4b0d3e55
28 changed files with 478 additions and 197 deletions
@@ -96,6 +96,9 @@ async function open(id: number, shopLabel?: string) {
detail.value = null;
try {
detail.value = await getPddOrderDetailApi(id);
if (detail.value?.shopName) {
shopName.value = detail.value.shopName;
}
} catch (error) {
console.error(error);
message.error('加载订单详情失败');
@@ -126,7 +129,7 @@ defineExpose({ open, close });
{{ detail.orderSn }}
</DescriptionsItem>
<DescriptionsItem label="店铺">
{{ shopName || `店铺#${detail.shopId}` }}
{{ detail.shopName || shopName || `店铺#${detail.shopId}` }}
</DescriptionsItem>
<DescriptionsItem label="运单号">
{{ detail.trackingNumber || '-' }}
@@ -2,16 +2,14 @@
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PddOrderDTO, PddOrderVO } from '#/api/channel/pdd/order';
import type { PddShopVO } from '#/api/channel/pdd/shop';
import type { ShopDTO, ShopVO } from '#/api/ec/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, ref, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import { Button, Card, Image, Space, Tag, Tooltip, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getPddOrderPageApi } from '#/api/channel/pdd/order';
import { getShopPageApi } from '#/api/ec/shop';
import PddShopColPage from '#/views/channel/pdd/components/PddShopColPage.vue';
import dayjs from 'dayjs';
@@ -20,8 +18,6 @@ import PddOrderDetailDrawer from './components/PddOrderDetailDrawer.vue';
defineOptions({ name: 'PddOrderManagement' });
const PLATFORM_CODE_PDD = 'pdd';
const ORDER_STATUS_MAP: Record<number, { color: string; text: string }> = {
1: { text: '待发货', color: 'orange' },
2: { text: '已发货待签收', color: 'blue' },
@@ -37,11 +33,8 @@ const REFUND_STATUS_MAP: Record<number, { color: string; text: string }> = {
const loading = ref(false);
const detailDrawerRef = ref<InstanceType<typeof PddOrderDetailDrawer>>();
/** 左侧选中的拼多多渠道店铺 ID */
/** 左侧选中的拼多多渠道店铺 ID(与订单 shopId 一致) */
const selectedPddShopId = ref<number | undefined>(undefined);
/** 渠道店铺 ID → 内部店铺 ID(订单表 shop_id 为 ec_shop.id) */
const ecShopIdByPddShopId = ref<Record<number, number>>({});
const shopNameById = ref<Record<number, string>>({});
const DEFAULT_LIST_DAYS = 7;
@@ -97,34 +90,6 @@ function goodsSpecTooltip(row: PddOrderVO.Info) {
return text || undefined;
}
async function loadShopMappings() {
try {
const data = await getShopPageApi({
page: 1,
pageSize: 500,
filters: {} as ShopDTO.Filters,
});
const list = (data.records ?? []).filter(
(s: ShopVO.Info) =>
s.platformCode === PLATFORM_CODE_PDD ||
!!s.pddShop ||
!!s.externalShopId,
);
const ecMap: Record<number, number> = {};
const nameMap: Record<number, string> = {};
for (const s of list) {
nameMap[s.id] = s.name;
if (s.externalShopId != null) {
ecMap[s.externalShopId] = s.id;
}
}
ecShopIdByPddShopId.value = ecMap;
shopNameById.value = nameMap;
} catch {
message.error('获取店铺映射失败');
}
}
function onShopSelect(shop: PddShopVO.Info | null) {
if (!shop) {
selectedPddShopId.value = undefined;
@@ -132,13 +97,7 @@ function onShopSelect(shop: PddShopVO.Info | null) {
return;
}
selectedPddShopId.value = shop.id;
const ecShopId = ecShopIdByPddShopId.value[shop.id];
if (ecShopId == null) {
message.warning('该拼多多店铺尚未绑定内部店铺,暂无订单数据');
searchForm.value.shopId = -1;
return;
}
searchForm.value.shopId = ecShopId;
searchForm.value.shopId = shop.id;
}
const gridOptions: VxeGridProps<PddOrderVO.Info> = {
@@ -374,12 +333,8 @@ watch(selectedPddShopId, () => {
});
function openDetail(row: PddOrderVO.Info) {
detailDrawerRef.value?.open(row.id, shopNameById.value[row.shopId]);
detailDrawerRef.value?.open(row.id, row.shopName);
}
onMounted(async () => {
await loadShopMappings();
});
</script>
<template>
@@ -406,7 +361,7 @@ onMounted(async () => {
>
<Grid class="pdd-order-grid h-full min-h-0" :loading="loading">
<template #shopName="{ row }">
{{ shopNameById[row.shopId] || `店铺#${row.shopId}` }}
{{ row.shopName || `店铺#${row.shopId}` }}
</template>
<template #goods="{ row }">