refactor: 发品去掉主内部商品绑定,改由订单同步兜底建品

This commit is contained in:
2026-10-09 14:15:12 +08:00
parent 7fa0729722
commit 59b3ada695
6 changed files with 4 additions and 123 deletions
@@ -4,7 +4,6 @@ export namespace PddGoodsPublishDTO {
pddShopId: number;
/** 关联系统草稿:发布成功后回写 goods_commit_id */
systemDraftId?: number;
primaryProductId: number;
goodsName: string;
goodsDesc?: string;
catId: number;
@@ -2,8 +2,6 @@
/**
* 拼多多发布编辑器壳:编排 form + composables + 卡片,不含业务算法细节。
*/
import type { ProductVO } from '#/api/ec/product/types';
import {
onBeforeUnmount,
onMounted,
@@ -39,11 +37,8 @@ import {
Tag,
Tooltip,
Upload,
message,
} from 'ant-design-vue';
import { getProductPageApi } from '#/api/ec/product';
import CatPropertyField from './components/CatPropertyField.vue';
import SpecAxesCard from './components/SpecAxesCard.vue';
import SkuTableCard from './components/SkuTableCard.vue';
@@ -83,9 +78,6 @@ const hydratingDraft = ref(false);
const skuRows = ref<SkuRow[]>([]);
const specAxes = ref<SpecAxis[]>([]);
const specCatalog = ref<SpecCatalogItem[]>([]);
const productOptions = ref<{ label: string; value: number; name: string }[]>(
[],
);
/** 环依赖:specs ↔ sku,用可变实现在装配后回填 */
let syncSkuRowsFromSpecsImpl: (opts?: {
@@ -139,23 +131,6 @@ rebuildPreservingImpl = specs.rebuildSpecCatalogPreservingUserData;
buildSpecCatalogImpl = specs.buildSpecCatalog;
clearSkuRowsImpl = sku.clearSkuRows;
async function loadProducts(keyword = '') {
try {
const data = await getProductPageApi({
page: 1,
pageSize: 50,
filters: keyword ? { keywords: keyword } : {},
});
productOptions.value = (data.records ?? []).map((p: ProductVO.Info) => ({
label: `${p.name}${p.productCode ? ` (${p.productCode})` : ''}`,
value: p.id,
name: p.name,
}));
} catch {
message.error('加载内部商品失败');
}
}
function handleClose() {
resetAll();
emit('close');
@@ -178,8 +153,6 @@ const draft = usePublishDraft({
selectedCatPathLabel: category.selectedCatPathLabel,
allNonSaleProps: category.allNonSaleProps,
nonSaleProps: category.nonSaleProps,
productOptions,
loadProducts,
specAxes,
specCatalog,
normalizeSpecValueSlots: specs.normalizeSpecValueSlots,
@@ -216,17 +189,6 @@ const agent = usePublishAgent({
revokeUploadFiles: images.revokeUploadFiles,
});
watch(
() => form.primaryProductId,
(id) => {
if (!id) return;
const p = productOptions.value.find((x) => x.value === id);
if (p && !form.goodsName) {
form.goodsName = p.name;
}
},
);
watch(
() => props.open ?? true,
(v) => {
@@ -235,7 +197,6 @@ watch(
form.pddShopId = props.presetPddShopId ?? undefined;
}
void category.loadShops();
void loadProducts();
void sku.loadSkuCandidates();
if (props.draftId) {
void draft.hydrateFromDraft(props.draftId);
@@ -250,7 +211,6 @@ onMounted(() => {
form.pddShopId = props.presetPddShopId ?? undefined;
}
void category.loadShops();
void loadProducts();
void sku.loadSkuCandidates();
if (props.draftId) {
void draft.hydrateFromDraft(props.draftId);
@@ -492,19 +452,6 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
<div
class="min-h-0 flex-1 space-y-4 overflow-y-auto overscroll-y-contain px-4 py-3"
>
<Form.Item label="主内部商品" required>
<Select
v-model:value="form.primaryProductId"
show-search
allow-clear
class="w-full"
placeholder="搜索并选择主商品(标题默认带出)"
:filter-option="false"
:options="productOptions"
@search="(kw: string) => loadProducts(kw)"
/>
</Form.Item>
<div
data-agent-field="goodsName"
:class="{ 'agent-typing-field': agentTypingField === 'goodsName' }"
@@ -65,9 +65,6 @@ export function usePublishDraft(options: {
selectedCatPathLabel: Ref<string>;
allNonSaleProps: ComputedRef<PddGoodsPublishVO.CatProperty[]>;
nonSaleProps: ComputedRef<PddGoodsPublishVO.CatProperty[]>;
// products
productOptions: Ref<{ label: string; value: number; name: string }[]>;
loadProducts: (keyword?: string) => Promise<void>;
// specs
specAxes: Ref<SpecAxis[]>;
specCatalog: Ref<SpecCatalogItem[]>;
@@ -110,8 +107,6 @@ export function usePublishDraft(options: {
selectedCatPathLabel,
allNonSaleProps,
nonSaleProps,
productOptions,
loadProducts,
specAxes,
specCatalog,
normalizeSpecValueSlots,
@@ -164,10 +159,6 @@ export function usePublishDraft(options: {
message.warning('请选择渠道店铺');
return false;
}
if (!form.primaryProductId) {
message.warning('请选择主内部商品');
return false;
}
if (!form.goodsName.trim()) {
message.warning('请填写商品标题');
return false;
@@ -361,7 +352,6 @@ export function usePublishDraft(options: {
return {
pddShopId: form.pddShopId!,
primaryProductId: form.primaryProductId!,
goodsName: form.goodsName.trim(),
goodsDesc: form.goodsDesc || undefined,
catId: form.catId!,
@@ -408,7 +398,6 @@ export function usePublishDraft(options: {
loadShops(),
shopId ? loadRootCats() : Promise.resolve(),
shopId ? loadLogistics() : Promise.resolve(),
loadProducts(),
loadSkuCandidates(),
]);
@@ -417,22 +406,6 @@ export function usePublishDraft(options: {
draft.title ||
'';
if (typeof es.goodsDesc === 'string') form.goodsDesc = es.goodsDesc;
if (typeof es.primaryProductId === 'number') {
form.primaryProductId = es.primaryProductId;
if (
form.primaryProductId &&
!productOptions.value.some((p) => p.value === form.primaryProductId)
) {
productOptions.value = [
{
label: `商品#${form.primaryProductId}`,
value: form.primaryProductId,
name: form.goodsName || `商品#${form.primaryProductId}`,
},
...productOptions.value,
];
}
}
const catId =
draft.catId ??
@@ -681,7 +654,6 @@ export function usePublishDraft(options: {
const payloadJson = JSON.stringify({
editorState: {
pddShopId: form.pddShopId,
primaryProductId: form.primaryProductId,
goodsName: form.goodsName,
goodsDesc: form.goodsDesc,
catId: form.catId,
@@ -87,7 +87,6 @@ export type DefaultOptionType = {
/** 发布表单字段(店铺/类目/标题等) */
export type PublishFormFields = {
pddShopId: number | undefined;
primaryProductId: number | undefined;
goodsName: string;
goodsDesc: string;
catPath: number[];
@@ -123,7 +122,6 @@ export function twoPiecesDiscountFromStored(raw: number): number {
export function createEmptyPublishForm(): PublishFormFields {
return {
pddShopId: undefined,
primaryProductId: undefined,
goodsName: '',
goodsDesc: '',
catPath: [],