商品管理: 完成商品属性批量添加

This commit is contained in:
puhui999 2023-04-30 17:28:16 +08:00
parent ab1120b0ff
commit 64f6f67ddd

View File

@ -68,7 +68,9 @@
</template>
<el-table-column v-if="formData.specType" align="center" fixed="right" label="操作" width="80">
<template #default>
<el-button v-if="isBatch" link size="small" type="primary">批量添加</el-button>
<el-button v-if="isBatch" link size="small" type="primary" @click="batchAdd"
>批量添加
</el-button>
<el-button v-else link size="small" type="primary">删除</el-button>
</template>
</el-table-column>
@ -81,6 +83,7 @@ import { PropType } from 'vue'
import { SpuType } from '@/api/mall/product/management/type/spuType'
import { propTypes } from '@/utils/propTypes'
import { SkuType } from '@/api/mall/product/management/type/skuType'
import { copyValueToTarget } from '@/utils/object'
const props = defineProps({
propFormData: {
@ -131,6 +134,12 @@ const SkuData = ref<SkuType[]>([
volume: 0
}
])
/** 批量添加 */
const batchAdd = () => {
formData.value.skus.forEach((item) => {
copyValueToTarget(item, SkuData.value[0])
})
}
const tableHeaderList = ref<{ prop: string; label: string }[]>([])
/**
* 将传进来的值赋值给SkuData
@ -209,8 +218,21 @@ watch(
(data) => {
//
if (!formData.value.specType) return
// 使
if (props.isBatch) return
// 使
if (props.isBatch) {
SkuData.value = [
{
price: 0,
marketPrice: 0,
costPrice: 0,
barCode: '',
picUrl: '',
stock: 0,
weight: 0,
volume: 0
}
]
}
//
if (JSON.stringify(data) === '[]') return
//