Commit 8de29d302c386758385d0a251e6480e4e239ead6
1 parent
617573a5
feature(uniapp商品): 新增商品数据
Showing
5 changed files
with
28 additions
and
18 deletions
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 { |
| 19 | 19 | |
| 20 | 20 | // TODO @franky:类似这种字段,有额外说明的。可以写成; @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") |
| 21 | 21 | |
| 22 | - @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) | |
| 23 | - @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") | |
| 22 | + @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") | |
| 24 | 23 | private List<Property> properties; |
| 25 | 24 | |
| 26 | 25 | @ApiModelProperty(value = "销售价格,单位:分", required = true) | ... | ... |
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 { |
| 91 | 91 | |
| 92 | 92 | @Override |
| 93 | 93 | public void validateSkus(List<ProductSkuCreateReqVO> list) { |
| 94 | - List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); | |
| 94 | + List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); | |
| 95 | 95 | // 校验规格属性以及规格值是否存在 |
| 96 | 96 | List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); |
| 97 | 97 | List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); | ... | ... |
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 { |
| 57 | 57 | categoryService.validateProductCategory(createReqVO.getCategoryId()); |
| 58 | 58 | // 校验SKU |
| 59 | 59 | List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus(); |
| 60 | - productSkuService.validateSkus(skuCreateReqList); | |
| 60 | + if(createReqVO.getSpecType() == 1) { | |
| 61 | + productSkuService.validateSkus(skuCreateReqList); | |
| 62 | + } | |
| 61 | 63 | // 插入SPU |
| 62 | 64 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); |
| 63 | 65 | ProductSpuMapper.insert(spu); |
| ... | ... | @@ -81,7 +83,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 81 | 83 | categoryService.validateProductCategory(updateReqVO.getCategoryId()); |
| 82 | 84 | // 校验SKU |
| 83 | 85 | List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus(); |
| 84 | - productSkuService.validateSkus(skuCreateReqList); | |
| 86 | + if(updateReqVO.getSpecType() == 1) { | |
| 87 | + productSkuService.validateSkus(skuCreateReqList); | |
| 88 | + } | |
| 85 | 89 | // 更新 |
| 86 | 90 | ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); |
| 87 | 91 | ProductSpuMapper.updateById(updateObj); | ... | ... |
yudao-ui-admin/src/views/mall/product/spu/index.vue
| ... | ... | @@ -178,9 +178,9 @@ |
| 178 | 178 | /> |
| 179 | 179 | |
| 180 | 180 | |
| 181 | -<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body > | |
| 182 | - <save @closeDialog="open = false"/> | |
| 183 | -</el-dialog> | |
| 181 | + <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close> | |
| 182 | + <save @closeDialog="open = false; getList()"/> | |
| 183 | + </el-dialog> | |
| 184 | 184 | </div> |
| 185 | 185 | </template> |
| 186 | 186 | ... | ... |
yudao-ui-admin/src/views/mall/product/spu/save.vue
| ... | ... | @@ -309,26 +309,33 @@ export default { |
| 309 | 309 | if (this.ratesForm.spec == 1) { |
| 310 | 310 | rates.forEach(r => { |
| 311 | 311 | let properties = [] |
| 312 | - r.spec.forEach((v, i) => { | |
| 313 | - let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); | |
| 314 | - let propertie = {}; | |
| 315 | - propertie.propertyId = this.dynamicSpec[i].specId; | |
| 316 | - propertie.valueId = specValue.id; | |
| 317 | - properties.push(propertie); | |
| 318 | - }) | |
| 312 | + if(r.spec instanceof Array){ | |
| 313 | + r.spec.forEach((v, i) => { | |
| 314 | + let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); | |
| 315 | + let propertie = {}; | |
| 316 | + propertie.propertyId = this.dynamicSpec[i].specId; | |
| 317 | + propertie.valueId = specValue.id; | |
| 318 | + properties.push(propertie); | |
| 319 | + }) | |
| 320 | + }else{ | |
| 321 | + let specValue = this.dynamicSpec[0].specValue.find(o => o.name == r.spec); | |
| 322 | + let propertie = {}; | |
| 323 | + propertie.propertyId = this.dynamicSpec[0].specId; | |
| 324 | + propertie.valueId = specValue.id; | |
| 325 | + properties.push(propertie); | |
| 326 | + } | |
| 319 | 327 | r.properties = properties; |
| 320 | 328 | }) |
| 321 | 329 | } |
| 322 | 330 | this.baseForm.skus = rates; |
| 323 | 331 | this.baseForm.specType = this.ratesForm.spec; |
| 324 | 332 | this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1]; |
| 325 | - console.log(this.baseForm) | |
| 326 | 333 | createSpu(this.baseForm).then((response) => { |
| 334 | + console.log(response) | |
| 327 | 335 | this.$modal.msgSuccess("新增成功"); |
| 328 | - this.open = false; | |
| 329 | - this.getList(); | |
| 330 | 336 | this.$emit("closeDialog"); |
| 331 | 337 | }); |
| 338 | + | |
| 332 | 339 | }, |
| 333 | 340 | /** 查询规格 */ |
| 334 | 341 | getPropertyPageList() { | ... | ... |