feat: 优化商品复制逻辑
This commit is contained in:
1 parent
a3cacf0fd3
commit
ccd74a3df6
1 file changed
+23
-10
@@ -51,6 +51,15 @@
|
||||
<Icon class="mr-5px" icon="ep:refresh" />
|
||||
重置
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['product:spu:create']"
|
||||
plain
|
||||
type="primary"
|
||||
@click="openForm()"
|
||||
>
|
||||
<Icon class="mr-5px" icon="ep:plus" />
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['product:spu:create']"
|
||||
plain
|
||||
@@ -452,19 +461,23 @@ const handleCopy = async () => {
|
||||
// 获取商品详情
|
||||
const productDetail = await ProductSpuApi.getSpu(row.id!)
|
||||
|
||||
// 准备新商品数据,只清除ID等需要重新生成的字段,其他数据保持原样
|
||||
// 准备新商品数据,复制所有内容,但不传递商品编号(id)和SKU的id,后端会自动生成
|
||||
const { id, createTime, skus, ...spuData } = productDetail
|
||||
const newProduct: ProductSpuApi.Spu = {
|
||||
...productDetail,
|
||||
id: undefined, // 清除ID,让系统自动生成
|
||||
createTime: undefined, // 清除创建时间,使用当前时间
|
||||
// 复制SKU时只清除ID和spuId,其他数据保持原样
|
||||
skus: productDetail.skus?.map(sku => ({
|
||||
...sku,
|
||||
id: undefined, // 清除SKU ID,让系统自动生成
|
||||
spuId: undefined // 清除SPU关联ID,系统会自动关联
|
||||
}))
|
||||
...spuData, // 复制所有SPU字段(除了id和createTime)
|
||||
// 复制SKU时不传递id和spuId,其他所有数据保持原样(包括name字段)
|
||||
skus: skus?.map(sku => {
|
||||
const { id: skuId, spuId, ...skuData } = sku
|
||||
return {
|
||||
...skuData, // 复制SKU的所有业务字段(包括name),排除id、spuId
|
||||
name: sku.name || productDetail.name // 确保name字段被复制,如果没有则使用SPU的name
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 在控制台打印新增的商品数据
|
||||
console.log('复制新增的商品数据:', newProduct)
|
||||
|
||||
// 创建新商品
|
||||
await ProductSpuApi.createSpu(newProduct)
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user