fix(mall): 修复商品 SKU 名称校验失败的问题
parent
7a7228aed8
commit
c656f87575
|
|
@ -318,6 +318,7 @@ const props = defineProps({
|
||||||
const formData: Ref<Spu | undefined> = ref<Spu>() // 表单数据
|
const formData: Ref<Spu | undefined> = ref<Spu>() // 表单数据
|
||||||
const skuList = ref<Sku[]>([
|
const skuList = ref<Sku[]>([
|
||||||
{
|
{
|
||||||
|
name: '', // SKU 名称
|
||||||
price: 0, // 商品价格
|
price: 0, // 商品价格
|
||||||
marketPrice: 0, // 市场价
|
marketPrice: 0, // 市场价
|
||||||
costPrice: 0, // 成本价
|
costPrice: 0, // 成本价
|
||||||
|
|
@ -449,6 +450,7 @@ const generateTableData = (propertyList: any[]) => {
|
||||||
}
|
}
|
||||||
for (const item of buildSkuList) {
|
for (const item of buildSkuList) {
|
||||||
const row = {
|
const row = {
|
||||||
|
name: '', // SKU 名称,提交时会自动使用 SPU 名称
|
||||||
properties: Array.isArray(item) ? item : [item], // 如果只有一个属性的话返回的是一个 property 对象
|
properties: Array.isArray(item) ? item : [item], // 如果只有一个属性的话返回的是一个 property 对象
|
||||||
price: 0,
|
price: 0,
|
||||||
marketPrice: 0,
|
marketPrice: 0,
|
||||||
|
|
@ -525,6 +527,7 @@ watch(
|
||||||
if (props.isBatch) {
|
if (props.isBatch) {
|
||||||
skuList.value = [
|
skuList.value = [
|
||||||
{
|
{
|
||||||
|
name: '', // SKU 名称
|
||||||
price: 0,
|
price: 0,
|
||||||
marketPrice: 0,
|
marketPrice: 0,
|
||||||
costPrice: 0,
|
costPrice: 0,
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ const onChangeSpec = () => {
|
||||||
// 重置sku列表
|
// 重置sku列表
|
||||||
formData.skus = [
|
formData.skus = [
|
||||||
{
|
{
|
||||||
|
name: '', // SKU 名称,提交时会自动使用 SPU 名称
|
||||||
price: 0,
|
price: 0,
|
||||||
marketPrice: 0,
|
marketPrice: 0,
|
||||||
costPrice: 0,
|
costPrice: 0,
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ import OtherForm from './OtherForm.vue'
|
||||||
import SkuForm from './SkuForm.vue'
|
import SkuForm from './SkuForm.vue'
|
||||||
import DeliveryForm from './DeliveryForm.vue'
|
import DeliveryForm from './DeliveryForm.vue'
|
||||||
import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils'
|
import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils'
|
||||||
|
import { isEmpty } from '@/utils/is'
|
||||||
|
|
||||||
defineOptions({ name: 'ProductSpuAdd' })
|
defineOptions({ name: 'ProductSpuAdd' })
|
||||||
|
|
||||||
|
|
@ -94,6 +95,7 @@ const formData = ref<ProductSpuApi.Spu>({
|
||||||
subCommissionType: false, // 分销类型
|
subCommissionType: false, // 分销类型
|
||||||
skus: [
|
skus: [
|
||||||
{
|
{
|
||||||
|
name: '', // SKU 名称,提交时会自动使用 SPU 名称
|
||||||
price: 0, // 商品价格
|
price: 0, // 商品价格
|
||||||
marketPrice: 0, // 市场价
|
marketPrice: 0, // 市场价
|
||||||
costPrice: 0, // 成本价
|
costPrice: 0, // 成本价
|
||||||
|
|
@ -158,8 +160,13 @@ const submitForm = async () => {
|
||||||
await unref(otherRef)?.validate()
|
await unref(otherRef)?.validate()
|
||||||
// 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据
|
// 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据
|
||||||
const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu
|
const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu
|
||||||
|
// 校验商品名称不能为空(用于 SKU name)
|
||||||
|
if (isEmpty(deepCopyFormData.name)) {
|
||||||
|
message.error('商品名称不能为空')
|
||||||
|
return
|
||||||
|
}
|
||||||
deepCopyFormData.skus!.forEach((item) => {
|
deepCopyFormData.skus!.forEach((item) => {
|
||||||
// 给sku name赋值
|
// 给sku name赋值(使用商品名称作为 SKU 名称)
|
||||||
item.name = deepCopyFormData.name
|
item.name = deepCopyFormData.name
|
||||||
// sku相关价格元转分
|
// sku相关价格元转分
|
||||||
item.price = convertToInteger(item.price)
|
item.price = convertToInteger(item.price)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue