Browse Source

feature(uniapp商品): 新增商品数据

luowenfeng 2 years ago
parent
commit
8de29d302c

+ 1 - 2
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<Property> properties;
 
     @ApiModelProperty(value = "销售价格,单位:分", required = true)

+ 1 - 1
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<ProductSkuCreateReqVO> list) {
-        List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList());
+        List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList());
         // 校验规格属性以及规格值是否存在
         List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList());
         List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);

+ 6 - 2
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<ProductSkuCreateReqVO> 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<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus();
-        productSkuService.validateSkus(skuCreateReqList);
+        if(updateReqVO.getSpecType() == 1) {
+            productSkuService.validateSkus(skuCreateReqList);
+        }
         // 更新
         ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
         ProductSpuMapper.updateById(updateObj);

+ 3 - 3
yudao-ui-admin/src/views/mall/product/spu/index.vue

@@ -178,9 +178,9 @@
     />
 
 
-<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body >
-  <save @closeDialog="open = false"/>
-</el-dialog>
+    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close>
+      <save @closeDialog="open = false; getList()"/>
+    </el-dialog>
   </div>
 </template>
 

+ 17 - 10
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() {