Skip to content

Commit 64f6f67

Browse files
author
puhui999
committed
商品管理: 完成商品属性批量添加
1 parent ab1120b commit 64f6f67

File tree

1 file changed

+25
-3
lines changed
  • src/views/mall/product/management/components/SkuList

1 file changed

+25
-3
lines changed

src/views/mall/product/management/components/SkuList/index.vue

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
</template>
6969
<el-table-column v-if="formData.specType" align="center" fixed="right" label="操作" width="80">
7070
<template #default>
71-
<el-button v-if="isBatch" link size="small" type="primary">批量添加</el-button>
71+
<el-button v-if="isBatch" link size="small" type="primary" @click="batchAdd"
72+
>批量添加
73+
</el-button>
7274
<el-button v-else link size="small" type="primary">删除</el-button>
7375
</template>
7476
</el-table-column>
@@ -81,6 +83,7 @@ import { PropType } from 'vue'
8183
import { SpuType } from '@/api/mall/product/management/type/spuType'
8284
import { propTypes } from '@/utils/propTypes'
8385
import { SkuType } from '@/api/mall/product/management/type/skuType'
86+
import { copyValueToTarget } from '@/utils/object'
8487
8588
const props = defineProps({
8689
propFormData: {
@@ -131,6 +134,12 @@ const SkuData = ref<SkuType[]>([
131134
volume: 0
132135
}
133136
])
137+
/** 批量添加 */
138+
const batchAdd = () => {
139+
formData.value.skus.forEach((item) => {
140+
copyValueToTarget(item, SkuData.value[0])
141+
})
142+
}
134143
const tableHeaderList = ref<{ prop: string; label: string }[]>([])
135144
/**
136145
* 将传进来的值赋值给SkuData
@@ -209,8 +218,21 @@ watch(
209218
(data) => {
210219
// 如果不是多规格则结束
211220
if (!formData.value.specType) return
212-
// 如果当前组件作为批量添加数据使用则结束
213-
if (props.isBatch) return
221+
// 如果当前组件作为批量添加数据使用则重置表数据
222+
if (props.isBatch) {
223+
SkuData.value = [
224+
{
225+
price: 0,
226+
marketPrice: 0,
227+
costPrice: 0,
228+
barCode: '',
229+
picUrl: '',
230+
stock: 0,
231+
weight: 0,
232+
volume: 0
233+
}
234+
]
235+
}
214236
// 判断代理对象是否为空
215237
if (JSON.stringify(data) === '[]') return
216238
// 重置表头

0 commit comments

Comments
 (0)