mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 03:49:21 +08:00
refactor: 发布类目属性改用 pdd.goods.cat.rule.get
This commit is contained in:
@@ -73,12 +73,12 @@ export async function getPddPublishLogisticsTemplateDetailApi(
|
||||
);
|
||||
}
|
||||
|
||||
/** 类目属性模板 */
|
||||
export async function getPddPublishCatTemplateApi(
|
||||
data: PddGoodsPublishDTO.CatTemplateQuery,
|
||||
/** 类目发布规则(含属性) */
|
||||
export async function getPddPublishCatRuleApi(
|
||||
data: PddGoodsPublishDTO.CatRuleQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.CatTemplate>(
|
||||
'/channel/pdd/goods/publish/meta/cat-template',
|
||||
return requestClient.post<PddGoodsPublishVO.CatRule>(
|
||||
'/channel/pdd/goods/publish/meta/cat-rule',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ export namespace PddGoodsPublishDTO {
|
||||
costTemplateId: number;
|
||||
}
|
||||
|
||||
export interface CatTemplateQuery {
|
||||
export interface CatRuleQuery {
|
||||
pddShopId: number;
|
||||
catId: number;
|
||||
}
|
||||
@@ -174,40 +174,56 @@ export namespace PddGoodsPublishVO {
|
||||
areaText?: string;
|
||||
}
|
||||
|
||||
export interface CatTemplate {
|
||||
id?: number;
|
||||
maxSkuNum?: number;
|
||||
/** 类目发布规则(pdd.goods.cat.rule.get) */
|
||||
export interface CatRule {
|
||||
chooseAllQualifySpec?: boolean;
|
||||
inputMaxSpecNum?: number;
|
||||
singleSpecValueNum?: number;
|
||||
singleItem?: boolean;
|
||||
/** 规格值加和上限 */
|
||||
specNumLimit?: number;
|
||||
priceRangeRatio?: number;
|
||||
properties?: CatProperty[];
|
||||
}
|
||||
|
||||
export interface CatProperty {
|
||||
templatePid?: number;
|
||||
name?: string;
|
||||
nameAlias?: string;
|
||||
refPid?: number;
|
||||
specId?: number;
|
||||
parentId?: number;
|
||||
/** 销售属性对应的父规格 id */
|
||||
parentSpecId?: number;
|
||||
required?: boolean;
|
||||
sale?: boolean;
|
||||
controlType?: number;
|
||||
feature?: number;
|
||||
valueType?: number;
|
||||
valueUnit?: string;
|
||||
/** SKU 维度属性 */
|
||||
sku?: boolean;
|
||||
important?: boolean;
|
||||
canNote?: boolean;
|
||||
/**
|
||||
* 0 文本;1 数值;2 范围;3/4 乘积;5–8 时间;9 材质表
|
||||
*/
|
||||
propertyValueType?: number;
|
||||
maxValue?: string;
|
||||
minValue?: string;
|
||||
valuePrecision?: number;
|
||||
valueUnits?: string[];
|
||||
inputMaxNum?: number;
|
||||
chooseMaxNum?: number;
|
||||
requiredRuleType?: number;
|
||||
requiredRule?: string;
|
||||
showCondition?: CatPropertyShowCondition[];
|
||||
values?: CatPropertyValue[];
|
||||
}
|
||||
|
||||
export interface CatPropertyShowCondition {
|
||||
parentRefPid?: number;
|
||||
parentVids?: number[];
|
||||
}
|
||||
|
||||
export interface CatPropertyValue {
|
||||
vid?: number;
|
||||
value?: string;
|
||||
specId?: number;
|
||||
extendInfo?: string;
|
||||
parent?: boolean;
|
||||
parentVids?: number[];
|
||||
groupId?: number;
|
||||
groupName?: string;
|
||||
}
|
||||
|
||||
export interface ParentSpec {
|
||||
|
||||
+4
-8
@@ -122,7 +122,7 @@ const specs = usePublishSpecs({
|
||||
const sku = usePublishSku({
|
||||
skuRows,
|
||||
specAxes,
|
||||
catTemplate: category.catTemplate,
|
||||
catRule: category.catRule,
|
||||
revokeUploadFiles: images.revokeUploadFiles,
|
||||
specHelpers: {
|
||||
effectiveSpecSlots: specs.effectiveSpecSlots,
|
||||
@@ -692,15 +692,13 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<Form.Item
|
||||
v-for="p in nonSaleProps"
|
||||
:key="String(p.templatePid ?? p.refPid)"
|
||||
:key="String(p.refPid)"
|
||||
:label="p.name"
|
||||
:required="!!p.required"
|
||||
>
|
||||
<Select
|
||||
v-if="p.values?.length"
|
||||
v-model:value="
|
||||
form.goodsPropValues[String(p.templatePid ?? p.refPid)]
|
||||
"
|
||||
v-model:value="form.goodsPropValues[String(p.refPid)]"
|
||||
class="w-full"
|
||||
allow-clear
|
||||
show-search
|
||||
@@ -714,9 +712,7 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
/>
|
||||
<Input
|
||||
v-else
|
||||
v-model:value="
|
||||
form.goodsPropValues[String(p.templatePid ?? p.refPid)]
|
||||
"
|
||||
v-model:value="form.goodsPropValues[String(p.refPid)]"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
+18
-17
@@ -8,7 +8,7 @@ import { message } from 'ant-design-vue';
|
||||
import type { PddGoodsPublishVO } from '#/api/channel/pdd/goods';
|
||||
import {
|
||||
checkPddPublishCatAuthApi,
|
||||
getPddPublishCatTemplateApi,
|
||||
getPddPublishCatRuleApi,
|
||||
getPddPublishLogisticsTemplateDetailApi,
|
||||
listPddPublishCatsApi,
|
||||
listPddPublishLogisticsApi,
|
||||
@@ -30,7 +30,7 @@ import type {
|
||||
} from '../types';
|
||||
|
||||
/**
|
||||
* 类目树 / Cascader / 发布权 / 模板与运费加载。
|
||||
* 类目树 / Cascader / 发布权 / 类目规则与运费加载。
|
||||
* 规格重建与 SKU 清空由壳层注入,避免与 specs/sku 环依赖。
|
||||
*/
|
||||
export function usePublishCategory(options: {
|
||||
@@ -59,14 +59,15 @@ export function usePublishCategory(options: {
|
||||
null,
|
||||
);
|
||||
const costTemplateDetailLoading = ref(false);
|
||||
const catTemplate = ref<PddGoodsPublishVO.CatTemplate | null>(null);
|
||||
const catRule = ref<PddGoodsPublishVO.CatRule | null>(null);
|
||||
const parentSpecs = ref<PddGoodsPublishVO.ParentSpec[]>([]);
|
||||
|
||||
/** 商品级非销售属性(SKU 维属性另处理) */
|
||||
const nonSaleProps = computed(() =>
|
||||
(catTemplate.value?.properties ?? []).filter((p) => !p.sale),
|
||||
(catRule.value?.properties ?? []).filter((p) => !p.sale && !p.sku),
|
||||
);
|
||||
const saleProps = computed(() =>
|
||||
(catTemplate.value?.properties ?? []).filter((p) => p.sale),
|
||||
(catRule.value?.properties ?? []).filter((p) => p.sale),
|
||||
);
|
||||
|
||||
const rootCatOptions = ref<CatCascaderNode[]>([]);
|
||||
@@ -444,9 +445,9 @@ export function usePublishCategory(options: {
|
||||
form.catPath = path;
|
||||
form.catId = catId;
|
||||
selectedCatPathLabel.value = pathLabel || '';
|
||||
catTemplate.value = null;
|
||||
catRule.value = null;
|
||||
parentSpecs.value = [];
|
||||
// 类目属性随模板变,需清空;规格/SKU 尽量沿用
|
||||
// 类目属性随规则变,需清空;规格/SKU 尽量沿用
|
||||
form.goodsPropValues = {};
|
||||
await refreshCatAuth(path);
|
||||
if (!form.pddShopId || !form.catId) return;
|
||||
@@ -455,7 +456,7 @@ export function usePublishCategory(options: {
|
||||
}
|
||||
try {
|
||||
const [tpl, specs] = await Promise.all([
|
||||
getPddPublishCatTemplateApi({
|
||||
getPddPublishCatRuleApi({
|
||||
pddShopId: form.pddShopId,
|
||||
catId: form.catId,
|
||||
}),
|
||||
@@ -464,11 +465,11 @@ export function usePublishCategory(options: {
|
||||
catId: form.catId,
|
||||
}),
|
||||
]);
|
||||
catTemplate.value = tpl;
|
||||
catRule.value = tpl;
|
||||
parentSpecs.value = specs ?? [];
|
||||
rebuildSpecCatalogPreservingUserData();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '加载类目模板失败');
|
||||
message.error(e?.message || '加载类目发布规则失败');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,7 +544,7 @@ export function usePublishCategory(options: {
|
||||
pinnedSelectedCat.value = null;
|
||||
catAuthAuthorized.value = null;
|
||||
catAuthMessage.value = '';
|
||||
catTemplate.value = null;
|
||||
catRule.value = null;
|
||||
parentSpecs.value = [];
|
||||
form.goodsPropValues = {};
|
||||
clearSkuRows();
|
||||
@@ -625,7 +626,7 @@ export function usePublishCategory(options: {
|
||||
}
|
||||
try {
|
||||
const [tpl, specs] = await Promise.all([
|
||||
getPddPublishCatTemplateApi({
|
||||
getPddPublishCatRuleApi({
|
||||
pddShopId: form.pddShopId,
|
||||
catId,
|
||||
}),
|
||||
@@ -634,11 +635,11 @@ export function usePublishCategory(options: {
|
||||
catId,
|
||||
}),
|
||||
]);
|
||||
catTemplate.value = tpl;
|
||||
catRule.value = tpl;
|
||||
parentSpecs.value = specs ?? [];
|
||||
specCatalog.value = buildSpecCatalog();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '加载类目模板失败');
|
||||
message.error(e?.message || '加载类目发布规则失败');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +661,7 @@ export function usePublishCategory(options: {
|
||||
catAuthMessage.value = '';
|
||||
form.costTemplateId = undefined;
|
||||
costTemplateDetail.value = null;
|
||||
catTemplate.value = null;
|
||||
catRule.value = null;
|
||||
parentSpecs.value = [];
|
||||
clearSkuRows();
|
||||
specAxes.value = [];
|
||||
@@ -687,7 +688,7 @@ export function usePublishCategory(options: {
|
||||
catAuthAuthorized.value = null;
|
||||
catAuthMessage.value = '';
|
||||
costTemplateDetail.value = null;
|
||||
catTemplate.value = null;
|
||||
catRule.value = null;
|
||||
parentSpecs.value = [];
|
||||
rootCatOptions.value = [];
|
||||
catSearchHitOptions.value = [];
|
||||
@@ -703,7 +704,7 @@ export function usePublishCategory(options: {
|
||||
logisticsOptions,
|
||||
costTemplateDetail,
|
||||
costTemplateDetailLoading,
|
||||
catTemplate,
|
||||
catRule,
|
||||
parentSpecs,
|
||||
nonSaleProps,
|
||||
saleProps,
|
||||
|
||||
+4
-6
@@ -194,7 +194,7 @@ export function usePublishDraft(options: {
|
||||
}
|
||||
for (const p of nonSaleProps.value) {
|
||||
if (!p.required) continue;
|
||||
const key = String(p.templatePid ?? p.refPid);
|
||||
const key = String(p.refPid);
|
||||
if (!form.goodsPropValues[key]) {
|
||||
message.warning(`请填写必填属性:${p.name || key}`);
|
||||
return false;
|
||||
@@ -249,7 +249,7 @@ export function usePublishDraft(options: {
|
||||
// 非销售属性 → goods_properties(不传 parent_spec_id / spec_id)
|
||||
const goodsProperties: PddGoodsPublishDTO.GoodsProperty[] = [];
|
||||
for (const p of nonSaleProps.value) {
|
||||
const key = String(p.templatePid ?? p.refPid);
|
||||
const key = String(p.refPid);
|
||||
const raw = form.goodsPropValues[key];
|
||||
if (!raw) continue;
|
||||
const matched = p.values?.find(
|
||||
@@ -257,10 +257,10 @@ export function usePublishDraft(options: {
|
||||
);
|
||||
goodsProperties.push({
|
||||
refPid: p.refPid,
|
||||
templatePid: p.templatePid,
|
||||
valueUnit: p.valueUnit,
|
||||
valueUnit: p.valueUnits?.[0],
|
||||
vid: matched?.vid,
|
||||
value: matched?.value ?? raw,
|
||||
groupId: matched?.groupId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -312,7 +312,6 @@ export function usePublishDraft(options: {
|
||||
saleSpecSeen.add(dedupeKey);
|
||||
goodsProperties.push({
|
||||
refPid: axis.refPid,
|
||||
templatePid: axis.templatePid,
|
||||
valueUnit: axis.valueUnit,
|
||||
vid: matched?.vid,
|
||||
value: valueText,
|
||||
@@ -682,7 +681,6 @@ export function usePublishDraft(options: {
|
||||
name: a.name,
|
||||
parentSpecId: a.parentSpecId,
|
||||
refPid: a.refPid,
|
||||
templatePid: a.templatePid,
|
||||
valueUnit: a.valueUnit,
|
||||
presetOptions: a.presetOptions.map((o) => ({ ...o })),
|
||||
selectedValues: a.selectedValues.map((s) => ({
|
||||
|
||||
+6
-5
@@ -34,11 +34,11 @@ export function usePublishSku(options: {
|
||||
/** 与 images 等共享同一 ref,由壳层创建 */
|
||||
skuRows: Ref<SkuRow[]>;
|
||||
specAxes: Ref<SpecAxis[]>;
|
||||
catTemplate: Ref<PddGoodsPublishVO.CatTemplate | null>;
|
||||
catRule: Ref<PddGoodsPublishVO.CatRule | null>;
|
||||
revokeUploadFiles: (files?: UploadFile[]) => void;
|
||||
specHelpers: SpecHelpers;
|
||||
}) {
|
||||
const { skuRows, specAxes, catTemplate, revokeUploadFiles, specHelpers } =
|
||||
const { skuRows, specAxes, catRule, revokeUploadFiles, specHelpers } =
|
||||
options;
|
||||
const {
|
||||
effectiveSpecSlots,
|
||||
@@ -289,10 +289,11 @@ export function usePublishSku(options: {
|
||||
}
|
||||
|
||||
const combos = cartesianProduct(slotLists);
|
||||
const maxSku = Number(catTemplate.value?.maxSkuNum ?? 0);
|
||||
if (maxSku > 0 && combos.length > maxSku) {
|
||||
const specNumLimit = Number(catRule.value?.specNumLimit ?? 0);
|
||||
const valueSum = slotLists.reduce((sum, list) => sum + list.length, 0);
|
||||
if (specNumLimit > 0 && valueSum > specNumLimit) {
|
||||
message.warning(
|
||||
`规格组合共 ${combos.length} 个,超过类目上限 ${maxSku},请减少规格值`,
|
||||
`规格值合计 ${valueSum} 个,超过类目上限 ${specNumLimit},请减少规格值`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+7
-10
@@ -65,14 +65,15 @@ export function usePublishSpecs(options: {
|
||||
const parents = parentSpecs.value;
|
||||
if (parents.length > 0) {
|
||||
return parents.map((ps) => {
|
||||
const matchedSale = sales.find((s) => s.name === ps.parentSpecName);
|
||||
const matchedSale =
|
||||
sales.find((s) => s.parentSpecId === ps.parentSpecId) ||
|
||||
sales.find((s) => s.name === ps.parentSpecName);
|
||||
return {
|
||||
catalogKey: `ps_${ps.parentSpecId}`,
|
||||
name: ps.parentSpecName || `规格${ps.parentSpecId}`,
|
||||
parentSpecId: ps.parentSpecId,
|
||||
refPid: matchedSale?.refPid,
|
||||
templatePid: matchedSale?.templatePid,
|
||||
valueUnit: matchedSale?.valueUnit,
|
||||
valueUnit: matchedSale?.valueUnits?.[0],
|
||||
presetOptions: (matchedSale?.values || []).map((v) => ({
|
||||
label: v.value || String(v.vid),
|
||||
value: String(v.vid ?? v.value),
|
||||
@@ -84,15 +85,14 @@ export function usePublishSpecs(options: {
|
||||
}
|
||||
const items: SpecCatalogItem[] = [];
|
||||
for (const sp of sales) {
|
||||
const parentSpecId = sp.specId;
|
||||
const parentSpecId = sp.parentSpecId;
|
||||
if (parentSpecId == null) continue;
|
||||
items.push({
|
||||
catalogKey: String(sp.refPid ?? sp.templatePid ?? parentSpecId),
|
||||
catalogKey: String(sp.refPid ?? parentSpecId),
|
||||
name: sp.name || String(parentSpecId),
|
||||
parentSpecId,
|
||||
refPid: sp.refPid,
|
||||
templatePid: sp.templatePid,
|
||||
valueUnit: sp.valueUnit,
|
||||
valueUnit: sp.valueUnits?.[0],
|
||||
presetOptions: (sp.values || []).map((v) => ({
|
||||
label: v.value || String(v.vid),
|
||||
value: String(v.vid ?? v.value),
|
||||
@@ -112,7 +112,6 @@ export function usePublishSpecs(options: {
|
||||
name: item.name,
|
||||
parentSpecId: item.parentSpecId,
|
||||
refPid: item.refPid,
|
||||
templatePid: item.templatePid,
|
||||
valueUnit: item.valueUnit,
|
||||
presetOptions: item.presetOptions.map((o) => ({ ...o })),
|
||||
// 默认一条空输入,随时可编辑
|
||||
@@ -221,7 +220,6 @@ export function usePublishSpecs(options: {
|
||||
name: match.name,
|
||||
parentSpecId: match.parentSpecId,
|
||||
refPid: match.refPid,
|
||||
templatePid: match.templatePid,
|
||||
valueUnit: match.valueUnit,
|
||||
presetOptions: match.presetOptions.map((o) => ({ ...o })),
|
||||
selectedValues:
|
||||
@@ -287,7 +285,6 @@ export function usePublishSpecs(options: {
|
||||
axis.name = item.name;
|
||||
axis.parentSpecId = item.parentSpecId;
|
||||
axis.refPid = item.refPid;
|
||||
axis.templatePid = item.templatePid;
|
||||
axis.valueUnit = item.valueUnit;
|
||||
axis.presetOptions = item.presetOptions.map((o) => ({ ...o }));
|
||||
axis.selectedValues = [createSpecValueSlot('')];
|
||||
|
||||
@@ -36,7 +36,6 @@ export type SpecCatalogItem = {
|
||||
name: string;
|
||||
parentSpecId: number;
|
||||
refPid?: number;
|
||||
templatePid?: number;
|
||||
valueUnit?: string;
|
||||
presetOptions: {
|
||||
label: string;
|
||||
@@ -63,7 +62,6 @@ export type SpecAxis = {
|
||||
name: string;
|
||||
parentSpecId?: number;
|
||||
refPid?: number;
|
||||
templatePid?: number;
|
||||
valueUnit?: string;
|
||||
presetOptions: SpecCatalogItem['presetOptions'];
|
||||
selectedValues: SpecValueSlot[];
|
||||
|
||||
Reference in New Issue
Block a user