mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 发布弹窗支持规格拖拽、SKU规格内联编辑与商家编码校验关联
This commit is contained in:
+581
-98
@@ -9,7 +9,11 @@ import type { CascaderProps, UploadFile, UploadProps } from 'ant-design-vue';
|
||||
|
||||
import { computed, nextTick, onBeforeUnmount, reactive, ref, watch } from 'vue';
|
||||
|
||||
import type { Sortable } from '@vben/hooks';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { useSortable } from '@vben/hooks';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
import {
|
||||
@@ -52,12 +56,18 @@ import {
|
||||
} from '#/api/channel/pdd/cat';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
import { getProductPageApi } from '#/api/ec/product';
|
||||
import { getProductSkuPageApi } from '#/api/ec/product/sku';
|
||||
import {
|
||||
getProductSkuBySkuCodeApi,
|
||||
getProductSkuPageApi,
|
||||
} from '#/api/ec/product/sku';
|
||||
import { FileCategory } from '#/constants/file-category';
|
||||
import { uploadFile } from '#/utils/upload-file';
|
||||
|
||||
defineOptions({ name: 'PddGoodsPublishModal' });
|
||||
|
||||
/** 规格轴 / 规格值拖拽手柄 */
|
||||
const GripVerticalIcon = createIconifyIcon('lucide:grip-vertical');
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
presetPddShopId?: number | null;
|
||||
@@ -157,6 +167,13 @@ type SkuRow = {
|
||||
comboKey: string;
|
||||
internalSkuId?: number;
|
||||
productName?: string;
|
||||
/** 关联的内部 SKU 名称(展示用) */
|
||||
internalSkuName?: string;
|
||||
/**
|
||||
* 商家编码是否命中内部 SKU:
|
||||
* idle=未校验/空;checking=请求中;matched=是;unmatched=非内部SKU
|
||||
*/
|
||||
codeMatchStatus?: 'idle' | 'checking' | 'matched' | 'unmatched';
|
||||
skuName: string;
|
||||
outSkuSn: string;
|
||||
priceYuan?: number;
|
||||
@@ -230,6 +247,19 @@ const specCatalog = ref<SpecCatalogItem[]>([]);
|
||||
/** 用户已添加的规格轴(默认一条「款式」) */
|
||||
const specAxes = ref<SpecAxis[]>([]);
|
||||
let specAxisRowSeq = 1;
|
||||
/** 规格轴列表容器(拖拽排序) */
|
||||
const specAxesListRef = ref<HTMLElement | null>(null);
|
||||
let axesSortable: null | Sortable = null;
|
||||
/** 各轴规格值容器的 Sortable 实例 */
|
||||
const valueSortables = new Map<number, Sortable>();
|
||||
/** SKU 规格列内联编辑草稿:`${rowKey}_${axisKey}` → 输入中文案 */
|
||||
const skuSpecDraft = ref<Record<string, string>>({});
|
||||
/** 上方「内部 SKU 拉入」多选 */
|
||||
const bindPickSkuIds = ref<number[]>([]);
|
||||
/** 商家编码校验防抖定时器(按行) */
|
||||
const outSkuSnTimers = new Map<number, ReturnType<typeof setTimeout>>();
|
||||
/** 商家编码校验序号,防止乱序回写 */
|
||||
const outSkuSnValidateSeq = new Map<number, number>();
|
||||
/** 规格表容器:新增后滚到表体底部 */
|
||||
const skuTableWrapRef = ref<HTMLElement | null>(null);
|
||||
|
||||
@@ -279,12 +309,13 @@ const skuTableColumns = computed(() => [
|
||||
...specAxes.value.map((axis) => ({
|
||||
title: axis.name,
|
||||
key: `spec_${axis.key}`,
|
||||
width: 120,
|
||||
width: 140,
|
||||
customCell: (_record: SkuRow, rowIndex?: number) => ({
|
||||
rowSpan: skuSpecRowSpans.value.get(axis.key)?.[rowIndex ?? 0] ?? 1,
|
||||
}),
|
||||
})),
|
||||
{ title: '商家编码', key: 'code', width: 300 },
|
||||
{ title: '编码', key: 'code', width: 140 },
|
||||
{ title: '内部SKU', key: 'internalSku', width: 160 },
|
||||
{ title: '单买价', key: 'price', width: 120 },
|
||||
{ title: '拼单价', key: 'multi', width: 120 },
|
||||
{ title: '库存', key: 'qty', width: 100 },
|
||||
@@ -293,7 +324,7 @@ const skuTableColumns = computed(() => [
|
||||
]);
|
||||
|
||||
const skuTableScrollX = computed(
|
||||
() => 740 + specAxes.value.length * 120,
|
||||
() => 740 + specAxes.value.length * 140,
|
||||
);
|
||||
|
||||
const logisticsOptions = ref<{ label: string; value: number }[]>([]);
|
||||
@@ -1019,6 +1050,111 @@ function removeSpecValue(rowId: number, index: number) {
|
||||
});
|
||||
}
|
||||
|
||||
/** 销毁规格轴/规格值 Sortable,避免泄漏 */
|
||||
function destroySpecSortables() {
|
||||
axesSortable?.destroy();
|
||||
axesSortable = null;
|
||||
for (const s of valueSortables.values()) {
|
||||
s.destroy();
|
||||
}
|
||||
valueSortables.clear();
|
||||
}
|
||||
|
||||
/** 规格轴卡片拖拽:交换维度顺序后重建 SKU 行序 */
|
||||
async function initAxesSortable() {
|
||||
axesSortable?.destroy();
|
||||
axesSortable = null;
|
||||
await nextTick();
|
||||
const el = specAxesListRef.value;
|
||||
if (!el || specAxes.value.length < 2) return;
|
||||
const { initializeSortable } = useSortable(el, {
|
||||
animation: 200,
|
||||
delay: 0,
|
||||
handle: '.spec-axis-drag-handle',
|
||||
draggable: '.spec-axis-card',
|
||||
onEnd(evt) {
|
||||
const { oldIndex, newIndex } = evt;
|
||||
if (
|
||||
oldIndex == null ||
|
||||
newIndex == null ||
|
||||
oldIndex === newIndex ||
|
||||
Number.isNaN(oldIndex) ||
|
||||
Number.isNaN(newIndex)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const list = [...specAxes.value];
|
||||
const [moved] = list.splice(oldIndex, 1);
|
||||
if (!moved) return;
|
||||
list.splice(newIndex, 0, moved);
|
||||
specAxes.value = list;
|
||||
syncSkuRowsFromSpecs();
|
||||
void refreshSpecSortables();
|
||||
},
|
||||
});
|
||||
axesSortable = await initializeSortable();
|
||||
}
|
||||
|
||||
/** 轴内规格值 Chip 拖拽:只调同轴取值顺序 */
|
||||
async function initValueSortables() {
|
||||
for (const s of valueSortables.values()) {
|
||||
s.destroy();
|
||||
}
|
||||
valueSortables.clear();
|
||||
await nextTick();
|
||||
for (const axis of specAxes.value) {
|
||||
const el = document.querySelector(
|
||||
`[data-spec-values="${axis.rowId}"]`,
|
||||
) as HTMLElement | null;
|
||||
if (!el || axis.selectedValues.length < 2) continue;
|
||||
const rowId = axis.rowId;
|
||||
const { initializeSortable } = useSortable(el, {
|
||||
animation: 150,
|
||||
delay: 0,
|
||||
handle: '.spec-value-drag-handle',
|
||||
draggable: '.spec-value-chip',
|
||||
onEnd(evt) {
|
||||
const { oldIndex, newIndex } = evt;
|
||||
if (
|
||||
oldIndex == null ||
|
||||
newIndex == null ||
|
||||
oldIndex === newIndex ||
|
||||
Number.isNaN(oldIndex) ||
|
||||
Number.isNaN(newIndex)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const target = specAxes.value.find((a) => a.rowId === rowId);
|
||||
if (!target) return;
|
||||
const vals = [...target.selectedValues];
|
||||
const [moved] = vals.splice(oldIndex, 1);
|
||||
if (moved === undefined) return;
|
||||
vals.splice(newIndex, 0, moved);
|
||||
target.selectedValues = vals;
|
||||
syncSkuRowsFromSpecs();
|
||||
void refreshSpecSortables();
|
||||
},
|
||||
});
|
||||
valueSortables.set(rowId, await initializeSortable());
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSpecSortables() {
|
||||
await initAxesSortable();
|
||||
await initValueSortables();
|
||||
}
|
||||
|
||||
/** 规格轴数量或取值槽位数变化时重建拖拽 */
|
||||
watch(
|
||||
() =>
|
||||
specAxes.value
|
||||
.map((a) => `${a.rowId}:${a.selectedValues.length}`)
|
||||
.join('|'),
|
||||
() => {
|
||||
void refreshSpecSortables();
|
||||
},
|
||||
);
|
||||
|
||||
function cartesianProduct(lists: string[][]): string[][] {
|
||||
if (lists.length === 0) return [];
|
||||
return lists.reduce<string[][]>(
|
||||
@@ -1047,6 +1183,72 @@ function skuSpecColumnLabel(
|
||||
return labelOfAxisValue(axis, raw);
|
||||
}
|
||||
|
||||
function skuSpecDraftKey(rowKey: number, axisKey: string) {
|
||||
return `${rowKey}_${axisKey}`;
|
||||
}
|
||||
|
||||
/** 规格列展示:优先草稿(输入中),否则轴上取值的 label */
|
||||
function skuSpecCellDisplay(record: Record<string, any>, axisKey: string) {
|
||||
const rowKey = Number(record.key);
|
||||
const dk = skuSpecDraftKey(rowKey, axisKey);
|
||||
if (Object.prototype.hasOwnProperty.call(skuSpecDraft.value, dk)) {
|
||||
return skuSpecDraft.value[dk] ?? '';
|
||||
}
|
||||
return skuSpecColumnLabel(record, `spec_${axisKey}`);
|
||||
}
|
||||
|
||||
function skuSpecCellAutoOptions(record: Record<string, any>, axisKey: string) {
|
||||
const axis = specAxes.value.find((a) => a.key === axisKey);
|
||||
if (!axis) return [];
|
||||
const current = (record.saleValues?.[axisKey] as string | undefined) ?? '';
|
||||
const index = axis.selectedValues.findIndex((v) => v === current);
|
||||
if (index < 0) {
|
||||
return axis.presetOptions.map((o) => ({
|
||||
label: o.label,
|
||||
value: o.label,
|
||||
}));
|
||||
}
|
||||
return specValueAutoOptions(axis, index);
|
||||
}
|
||||
|
||||
function onSkuSpecCellInput(rowKey: number, axisKey: string, text: string) {
|
||||
skuSpecDraft.value = {
|
||||
...skuSpecDraft.value,
|
||||
[skuSpecDraftKey(rowKey, axisKey)]: text,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并单元格内改规格值 = 重命名该轴上对应取值(整组同值),再同步笛卡尔积。
|
||||
*/
|
||||
function onSkuSpecCellCommit(rowKey: number, axisKey: string) {
|
||||
const dk = skuSpecDraftKey(rowKey, axisKey);
|
||||
if (!Object.prototype.hasOwnProperty.call(skuSpecDraft.value, dk)) return;
|
||||
const draft = skuSpecDraft.value[dk] ?? '';
|
||||
const nextDraft = { ...skuSpecDraft.value };
|
||||
delete nextDraft[dk];
|
||||
skuSpecDraft.value = nextDraft;
|
||||
|
||||
const row = skuRows.value.find((r) => r.key === rowKey);
|
||||
const axis = specAxes.value.find((a) => a.key === axisKey);
|
||||
if (!row || !axis) return;
|
||||
|
||||
const oldToken = row.saleValues[axisKey] ?? '';
|
||||
const newToken = resolveSpecValueToken(axis, draft);
|
||||
if (!newToken || newToken === oldToken) return;
|
||||
|
||||
const vi = axis.selectedValues.findIndex((v) => v === oldToken);
|
||||
if (vi < 0) return;
|
||||
if (
|
||||
axis.selectedValues.some((v, i) => i !== vi && v.trim() === newToken)
|
||||
) {
|
||||
message.warning('该规格值已存在');
|
||||
return;
|
||||
}
|
||||
axis.selectedValues[vi] = newToken;
|
||||
syncSkuRowsFromSpecs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 规格取值变化后按笛卡尔积生成 SKU;同组合键保留已填价格/编码/图。
|
||||
*/
|
||||
@@ -1119,6 +1321,8 @@ function bindInternalSku(rowKey: number, skuId?: number) {
|
||||
if (skuId == null) {
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = undefined;
|
||||
row.internalSkuName = undefined;
|
||||
row.codeMatchStatus = 'idle';
|
||||
return;
|
||||
}
|
||||
if (
|
||||
@@ -1136,11 +1340,182 @@ function bindInternalSku(rowKey: number, skuId?: number) {
|
||||
}
|
||||
row.internalSkuId = sku.id;
|
||||
row.productName = sku.productName;
|
||||
row.internalSkuName = sku.name;
|
||||
row.codeMatchStatus = 'matched';
|
||||
if (sku.skuCode) {
|
||||
row.outSkuSn = sku.skuCode;
|
||||
}
|
||||
}
|
||||
|
||||
/** 商家编码写入后清除该行待校验定时器 */
|
||||
function clearOutSkuSnTimer(rowKey: number) {
|
||||
const t = outSkuSnTimers.get(rowKey);
|
||||
if (t) {
|
||||
clearTimeout(t);
|
||||
outSkuSnTimers.delete(rowKey);
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllOutSkuSnTimers() {
|
||||
for (const t of outSkuSnTimers.values()) {
|
||||
clearTimeout(t);
|
||||
}
|
||||
outSkuSnTimers.clear();
|
||||
outSkuSnValidateSeq.clear();
|
||||
}
|
||||
|
||||
/** 商家编码变更:400ms 防抖后校验是否内部 SKU */
|
||||
function onOutSkuSnChange(rowKey: number, value: string) {
|
||||
const row = skuRows.value.find((r) => r.key === rowKey);
|
||||
if (!row) return;
|
||||
row.outSkuSn = value;
|
||||
// 编码改动后暂视为未校验,避免仍显示旧关联
|
||||
if (row.codeMatchStatus === 'matched' || row.codeMatchStatus === 'unmatched') {
|
||||
row.codeMatchStatus = 'idle';
|
||||
}
|
||||
clearOutSkuSnTimer(rowKey);
|
||||
outSkuSnTimers.set(
|
||||
rowKey,
|
||||
setTimeout(() => {
|
||||
outSkuSnTimers.delete(rowKey);
|
||||
void validateOutSkuSnByCode(rowKey);
|
||||
}, 400),
|
||||
);
|
||||
}
|
||||
|
||||
/** 失焦立即校验(取消防抖) */
|
||||
function onOutSkuSnBlur(rowKey: number) {
|
||||
clearOutSkuSnTimer(rowKey);
|
||||
void validateOutSkuSnByCode(rowKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按商家编码反查内部 SKU;命中则关联,否则标「非内部SKU」。
|
||||
*/
|
||||
async function validateOutSkuSnByCode(rowKey: number) {
|
||||
const row = skuRows.value.find((r) => r.key === rowKey);
|
||||
if (!row) return;
|
||||
|
||||
const code = row.outSkuSn.trim();
|
||||
if (!code) {
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = undefined;
|
||||
row.internalSkuName = undefined;
|
||||
row.codeMatchStatus = 'idle';
|
||||
return;
|
||||
}
|
||||
|
||||
// 已关联且编码未变:跳过请求
|
||||
if (
|
||||
row.codeMatchStatus === 'matched' &&
|
||||
row.internalSkuId != null &&
|
||||
row.outSkuSn.trim() === code
|
||||
) {
|
||||
const bound = skuOptions.value.find((s) => s.id === row.internalSkuId);
|
||||
if (bound?.skuCode && bound.skuCode === code) return;
|
||||
}
|
||||
|
||||
const seq = (outSkuSnValidateSeq.get(rowKey) ?? 0) + 1;
|
||||
outSkuSnValidateSeq.set(rowKey, seq);
|
||||
row.codeMatchStatus = 'checking';
|
||||
|
||||
try {
|
||||
const sku = await getProductSkuBySkuCodeApi(code);
|
||||
if (outSkuSnValidateSeq.get(rowKey) !== seq) return;
|
||||
if (!sku?.id) {
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = undefined;
|
||||
row.internalSkuName = undefined;
|
||||
row.codeMatchStatus = 'unmatched';
|
||||
return;
|
||||
}
|
||||
if (
|
||||
skuRows.value.some(
|
||||
(r) => r.key !== row.key && r.internalSkuId === sku.id,
|
||||
)
|
||||
) {
|
||||
message.warning('该内部 SKU 已绑定到其他规格组合');
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = sku.productName;
|
||||
row.internalSkuName = sku.name;
|
||||
row.codeMatchStatus = 'matched';
|
||||
return;
|
||||
}
|
||||
row.internalSkuId = sku.id;
|
||||
row.productName = sku.productName;
|
||||
row.internalSkuName = sku.name;
|
||||
row.codeMatchStatus = 'matched';
|
||||
// 缓存到下拉候选,便于同弹窗内复用
|
||||
if (!skuOptions.value.some((s) => s.id === sku.id)) {
|
||||
skuOptions.value = [sku, ...skuOptions.value];
|
||||
}
|
||||
} catch {
|
||||
if (outSkuSnValidateSeq.get(rowKey) !== seq) return;
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = undefined;
|
||||
row.internalSkuName = undefined;
|
||||
row.codeMatchStatus = 'unmatched';
|
||||
}
|
||||
}
|
||||
|
||||
/** 按当前 SKU 表行序依次关联上方多选的内部 SKU */
|
||||
function applyInternalSkusInOrder() {
|
||||
const ids = bindPickSkuIds.value;
|
||||
if (ids.length === 0) {
|
||||
message.warning('请先选择内部 SKU');
|
||||
return;
|
||||
}
|
||||
const rows = skuRows.value;
|
||||
if (rows.length === 0) {
|
||||
message.warning('请先生成 SKU 组合');
|
||||
return;
|
||||
}
|
||||
const n = Math.min(ids.length, rows.length);
|
||||
const idSet = new Set(ids.slice(0, n));
|
||||
for (const r of rows) {
|
||||
if (r.internalSkuId != null && idSet.has(r.internalSkuId)) {
|
||||
r.internalSkuId = undefined;
|
||||
r.productName = undefined;
|
||||
r.internalSkuName = undefined;
|
||||
r.codeMatchStatus = 'idle';
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < n; i++) {
|
||||
const row = rows[i]!;
|
||||
const skuId = ids[i]!;
|
||||
const sku = skuOptions.value.find((s) => s.id === skuId);
|
||||
if (!sku) continue;
|
||||
clearOutSkuSnTimer(row.key);
|
||||
row.internalSkuId = sku.id;
|
||||
row.productName = sku.productName;
|
||||
row.internalSkuName = sku.name;
|
||||
row.codeMatchStatus = 'matched';
|
||||
if (sku.skuCode) {
|
||||
row.outSkuSn = sku.skuCode;
|
||||
}
|
||||
}
|
||||
if (ids.length > rows.length) {
|
||||
message.info(`已按顺序填入 ${rows.length} 行,多余选择已忽略`);
|
||||
} else if (ids.length < rows.length) {
|
||||
message.info(`已填入前 ${ids.length} 行,其余行未改动`);
|
||||
} else {
|
||||
message.success('已按顺序关联内部 SKU');
|
||||
}
|
||||
}
|
||||
|
||||
/** 清空全部行的内部 SKU 关联(不改商家编码) */
|
||||
function clearInternalSkuBindings() {
|
||||
if (skuRows.value.length === 0) return;
|
||||
for (const row of skuRows.value) {
|
||||
clearOutSkuSnTimer(row.key);
|
||||
row.internalSkuId = undefined;
|
||||
row.productName = undefined;
|
||||
row.internalSkuName = undefined;
|
||||
row.codeMatchStatus = 'idle';
|
||||
}
|
||||
message.success('已清空内部 SKU 关联');
|
||||
}
|
||||
|
||||
/** 新增规格后滚到表体底部,方便继续编辑新行 */
|
||||
async function scrollSkuTableToBottom() {
|
||||
await nextTick();
|
||||
@@ -1678,6 +2053,10 @@ function resetAll() {
|
||||
clearSkuRows();
|
||||
specAxes.value = [];
|
||||
specCatalog.value = [];
|
||||
skuSpecDraft.value = {};
|
||||
bindPickSkuIds.value = [];
|
||||
clearAllOutSkuSnTimers();
|
||||
destroySpecSortables();
|
||||
catTemplate.value = null;
|
||||
parentSpecs.value = [];
|
||||
rootCatOptions.value = [];
|
||||
@@ -1693,6 +2072,8 @@ function resetAll() {
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('pointerdown', onOverlayPointerDown, true);
|
||||
clearLocalImages();
|
||||
clearAllOutSkuSnTimers();
|
||||
destroySpecSortables();
|
||||
if (catSearchTimer) clearTimeout(catSearchTimer);
|
||||
});
|
||||
</script>
|
||||
@@ -2056,7 +2437,7 @@ onBeforeUnmount(() => {
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-3"
|
||||
message="默认一条「款式」;最多两种规格。规格值始终可编辑,失焦后更新下方 SKU 组合。"
|
||||
message="默认一条「款式」;最多两种规格。拖拽手柄可调规格轴与规格值顺序;失焦后更新下方 SKU 组合。"
|
||||
/>
|
||||
<Empty
|
||||
v-if="specCatalog.length === 0"
|
||||
@@ -2064,74 +2445,94 @@ onBeforeUnmount(() => {
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
/>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="axis in specAxes"
|
||||
:key="axis.rowId"
|
||||
class="flex flex-wrap items-start gap-2 rounded-md border border-border/60 bg-muted/20 p-3"
|
||||
>
|
||||
<Select
|
||||
:value="axis.catalogKey"
|
||||
class="w-28 shrink-0"
|
||||
:options="catalogOptionsForAxis(axis.rowId)"
|
||||
@change="
|
||||
(v: any) => onAxisCatalogChange(axis.rowId, String(v))
|
||||
"
|
||||
/>
|
||||
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
||||
<div
|
||||
v-for="(_val, vi) in axis.selectedValues"
|
||||
:key="`${axis.rowId}_val_${vi}`"
|
||||
class="flex items-center gap-1"
|
||||
:data-spec-value-input="`${axis.rowId}_${vi}`"
|
||||
<div ref="specAxesListRef" class="space-y-3">
|
||||
<div
|
||||
v-for="axis in specAxes"
|
||||
:key="axis.rowId"
|
||||
class="spec-axis-card flex flex-wrap items-start gap-2 rounded-md border border-border/60 bg-muted/20 p-3"
|
||||
>
|
||||
<span
|
||||
v-if="specAxes.length > 1"
|
||||
class="spec-axis-drag-handle mt-1.5 shrink-0 cursor-grab text-muted-foreground active:cursor-grabbing"
|
||||
title="拖动调整规格顺序"
|
||||
>
|
||||
<AutoComplete
|
||||
:value="specValueDisplay(axis, vi)"
|
||||
class="w-36"
|
||||
:options="specValueAutoOptions(axis, vi)"
|
||||
placeholder="输入或选预设,回车新增"
|
||||
allow-clear
|
||||
@update:value="
|
||||
(v) =>
|
||||
onSpecValueInput(
|
||||
axis.rowId,
|
||||
vi,
|
||||
v == null ? '' : String(v),
|
||||
)
|
||||
"
|
||||
@blur="onSpecValueCommit(axis.rowId, vi)"
|
||||
@select="() => onSpecValueCommit(axis.rowId, vi)"
|
||||
@keydown.enter.prevent="
|
||||
onSpecValueEnter(axis.rowId, vi)
|
||||
"
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
size="small"
|
||||
title="删除规格值"
|
||||
@click="removeSpecValue(axis.rowId, vi)"
|
||||
<GripVerticalIcon class="size-4" />
|
||||
</span>
|
||||
<Select
|
||||
:value="axis.catalogKey"
|
||||
class="w-28 shrink-0"
|
||||
:options="catalogOptionsForAxis(axis.rowId)"
|
||||
@change="
|
||||
(v: any) => onAxisCatalogChange(axis.rowId, String(v))
|
||||
"
|
||||
/>
|
||||
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
||||
<div
|
||||
:data-spec-values="axis.rowId"
|
||||
class="flex flex-wrap items-center gap-2"
|
||||
>
|
||||
<div
|
||||
v-for="(_val, vi) in axis.selectedValues"
|
||||
:key="`${axis.rowId}_val_${vi}`"
|
||||
class="spec-value-chip flex items-center gap-1"
|
||||
:data-spec-value-input="`${axis.rowId}_${vi}`"
|
||||
>
|
||||
<span
|
||||
class="spec-value-drag-handle shrink-0 cursor-grab text-muted-foreground active:cursor-grabbing"
|
||||
title="拖动调整取值顺序"
|
||||
>
|
||||
<GripVerticalIcon class="size-3.5" />
|
||||
</span>
|
||||
<AutoComplete
|
||||
:value="specValueDisplay(axis, vi)"
|
||||
class="w-36"
|
||||
:options="specValueAutoOptions(axis, vi)"
|
||||
placeholder="输入或选预设,回车新增"
|
||||
allow-clear
|
||||
@update:value="
|
||||
(v) =>
|
||||
onSpecValueInput(
|
||||
axis.rowId,
|
||||
vi,
|
||||
v == null ? '' : String(v),
|
||||
)
|
||||
"
|
||||
@blur="onSpecValueCommit(axis.rowId, vi)"
|
||||
@select="() => onSpecValueCommit(axis.rowId, vi)"
|
||||
@keydown.enter.prevent="
|
||||
onSpecValueEnter(axis.rowId, vi)
|
||||
"
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
size="small"
|
||||
title="删除规格值"
|
||||
@click="removeSpecValue(axis.rowId, vi)"
|
||||
>
|
||||
<template #icon>
|
||||
<MinusOutlined />
|
||||
</template>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button type="dashed" @click="addSpecValueSlot(axis.rowId)">
|
||||
<template #icon>
|
||||
<MinusOutlined />
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
规格值
|
||||
</Button>
|
||||
</div>
|
||||
<Button type="dashed" @click="addSpecValueSlot(axis.rowId)">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
规格值
|
||||
<Button
|
||||
v-if="specAxes.length > 1"
|
||||
type="link"
|
||||
danger
|
||||
class="shrink-0"
|
||||
@click="removeSpecAxis(axis.rowId)"
|
||||
>
|
||||
删除规格
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
v-if="specAxes.length > 1"
|
||||
type="link"
|
||||
danger
|
||||
class="shrink-0"
|
||||
@click="removeSpecAxis(axis.rowId)"
|
||||
>
|
||||
删除规格
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
v-if="canAddSpecAxis"
|
||||
@@ -2145,6 +2546,30 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="内部 SKU 拉入">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Select
|
||||
v-model:value="bindPickSkuIds"
|
||||
mode="multiple"
|
||||
show-search
|
||||
allow-clear
|
||||
class="min-w-[240px] flex-1"
|
||||
placeholder="搜索并多选内部 SKU"
|
||||
:filter-option="false"
|
||||
:options="skuSelectOptions"
|
||||
@search="(kw: string) => loadSkuCandidates(kw)"
|
||||
@focus="() => loadSkuCandidates()"
|
||||
/>
|
||||
<Button type="primary" @click="applyInternalSkusInOrder">
|
||||
按行序填入
|
||||
</Button>
|
||||
<Button @click="clearInternalSkuBindings">清空关联</Button>
|
||||
</div>
|
||||
<p class="mt-2 mb-0 text-xs text-muted-foreground">
|
||||
按下方 SKU 表从上到下依次关联;一行一个。有内部编码时会写入商家编码。
|
||||
</p>
|
||||
</Card>
|
||||
|
||||
<Card size="small">
|
||||
<template #title>
|
||||
SKU 列表
|
||||
@@ -2173,42 +2598,100 @@ onBeforeUnmount(() => {
|
||||
<template
|
||||
v-if="String(column.key || '').startsWith('spec_')"
|
||||
>
|
||||
{{ skuSpecColumnLabel(record, String(column.key)) }}
|
||||
<AutoComplete
|
||||
:value="
|
||||
skuSpecCellDisplay(
|
||||
record,
|
||||
String(column.key).replace(/^spec_/, ''),
|
||||
)
|
||||
"
|
||||
class="w-full min-w-[100px]"
|
||||
:options="
|
||||
skuSpecCellAutoOptions(
|
||||
record,
|
||||
String(column.key).replace(/^spec_/, ''),
|
||||
)
|
||||
"
|
||||
placeholder="规格值"
|
||||
allow-clear
|
||||
@update:value="
|
||||
(v) =>
|
||||
onSkuSpecCellInput(
|
||||
record.key,
|
||||
String(column.key).replace(/^spec_/, ''),
|
||||
v == null ? '' : String(v),
|
||||
)
|
||||
"
|
||||
@blur="
|
||||
onSkuSpecCellCommit(
|
||||
record.key,
|
||||
String(column.key).replace(/^spec_/, ''),
|
||||
)
|
||||
"
|
||||
@select="
|
||||
() =>
|
||||
onSkuSpecCellCommit(
|
||||
record.key,
|
||||
String(column.key).replace(/^spec_/, ''),
|
||||
)
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'code'">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Select
|
||||
:value="record.internalSkuId"
|
||||
show-search
|
||||
allow-clear
|
||||
class="w-full"
|
||||
placeholder="关联内部 SKU(可选)"
|
||||
:filter-option="false"
|
||||
:options="skuSelectOptions"
|
||||
@search="(kw: string) => loadSkuCandidates(kw)"
|
||||
@change="
|
||||
(v: any) =>
|
||||
bindInternalSku(
|
||||
record.key,
|
||||
v == null || v === '' ? undefined : Number(v),
|
||||
)
|
||||
"
|
||||
/>
|
||||
<Input
|
||||
v-model:value="record.outSkuSn"
|
||||
:placeholder="
|
||||
record.internalSkuId
|
||||
? '已关联,可改编码'
|
||||
: '或手填商家编码'
|
||||
"
|
||||
/>
|
||||
<div
|
||||
v-if="record.productName"
|
||||
class="text-xs text-muted-foreground"
|
||||
:title="record.productName"
|
||||
<Input
|
||||
:value="record.outSkuSn"
|
||||
placeholder="商家编码"
|
||||
@update:value="
|
||||
(v) =>
|
||||
onOutSkuSnChange(
|
||||
record.key,
|
||||
v == null ? '' : String(v),
|
||||
)
|
||||
"
|
||||
@blur="() => onOutSkuSnBlur(record.key)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'internalSku'">
|
||||
<div class="flex flex-col gap-0.5">
|
||||
<template v-if="record.codeMatchStatus === 'checking'">
|
||||
<span class="text-xs text-muted-foreground">校验中…</span>
|
||||
</template>
|
||||
<template
|
||||
v-else-if="record.codeMatchStatus === 'unmatched'"
|
||||
>
|
||||
{{ record.productName }}
|
||||
</div>
|
||||
<span class="text-xs text-orange-500">非内部SKU</span>
|
||||
</template>
|
||||
<template v-else-if="record.internalSkuId">
|
||||
<div
|
||||
class="truncate text-xs"
|
||||
:title="
|
||||
[record.productName, record.internalSkuName]
|
||||
.filter(Boolean)
|
||||
.join(' / ') || undefined
|
||||
"
|
||||
>
|
||||
{{ record.productName || '—' }}
|
||||
</div>
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<span
|
||||
class="min-w-0 truncate text-muted-foreground"
|
||||
:title="record.internalSkuName || undefined"
|
||||
>
|
||||
{{ record.internalSkuName || '已关联' }}
|
||||
</span>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
class="h-auto shrink-0 px-0"
|
||||
@click="bindInternalSku(record.key, undefined)"
|
||||
>
|
||||
清除
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="text-xs text-muted-foreground">未关联</span>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'price'">
|
||||
|
||||
Reference in New Issue
Block a user