diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java index 7371ba4cc..f2636efe6 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java @@ -19,8 +19,7 @@ public class ProductSkuBaseVO { // TODO @franky:类似这种字段,有额外说明的。可以写成; @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") - @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) - @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") + @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") private List properties; @ApiModelProperty(value = "销售价格,单位:分", required = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 58538ebc0..36549eb3f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -91,7 +91,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Override public void validateSkus(List list) { - List skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); + List skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); // 校验规格属性以及规格值是否存在 List propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); List propertyAndValueList = productPropertyService.selectByIds(propertyIds); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 49847f720..c3a05ce9b 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -57,7 +57,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { categoryService.validateProductCategory(createReqVO.getCategoryId()); // 校验SKU List skuCreateReqList = createReqVO.getSkus(); - productSkuService.validateSkus(skuCreateReqList); + if(createReqVO.getSpecType() == 1) { + productSkuService.validateSkus(skuCreateReqList); + } // 插入SPU ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); ProductSpuMapper.insert(spu); @@ -81,7 +83,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { categoryService.validateProductCategory(updateReqVO.getCategoryId()); // 校验SKU List skuCreateReqList = updateReqVO.getSkus(); - productSkuService.validateSkus(skuCreateReqList); + if(updateReqVO.getSpecType() == 1) { + productSkuService.validateSkus(skuCreateReqList); + } // 更新 ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); ProductSpuMapper.updateById(updateObj); diff --git a/yudao-ui-admin/src/views/mall/product/spu/index.vue b/yudao-ui-admin/src/views/mall/product/spu/index.vue index 23e502052..00ee1ed3f 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/index.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/index.vue @@ -178,9 +178,9 @@ /> - - - + + + diff --git a/yudao-ui-admin/src/views/mall/product/spu/save.vue b/yudao-ui-admin/src/views/mall/product/spu/save.vue index e05e651e4..556bd816b 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/save.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/save.vue @@ -309,26 +309,33 @@ export default { if (this.ratesForm.spec == 1) { rates.forEach(r => { let properties = [] - r.spec.forEach((v, i) => { - let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); - let propertie = {}; - propertie.propertyId = this.dynamicSpec[i].specId; - propertie.valueId = specValue.id; - properties.push(propertie); - }) + if(r.spec instanceof Array){ + r.spec.forEach((v, i) => { + let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); + let propertie = {}; + propertie.propertyId = this.dynamicSpec[i].specId; + propertie.valueId = specValue.id; + properties.push(propertie); + }) + }else{ + let specValue = this.dynamicSpec[0].specValue.find(o => o.name == r.spec); + let propertie = {}; + propertie.propertyId = this.dynamicSpec[0].specId; + propertie.valueId = specValue.id; + properties.push(propertie); + } r.properties = properties; }) } this.baseForm.skus = rates; this.baseForm.specType = this.ratesForm.spec; this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1]; - console.log(this.baseForm) createSpu(this.baseForm).then((response) => { + console.log(response) this.$modal.msgSuccess("新增成功"); - this.open = false; - this.getList(); this.$emit("closeDialog"); }); + }, /** 查询规格 */ getPropertyPageList() {