feature(uniapp商品): 新增商品数据
parent
617573a59b
commit
8de29d302c
|
@ -19,8 +19,7 @@ public class ProductSkuBaseVO {
|
||||||
|
|
||||||
// TODO @franky:类似这种字段,有额外说明的。可以写成; @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]")
|
// TODO @franky:类似这种字段,有额外说明的。可以写成; @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]")
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true)
|
@ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]")
|
||||||
@NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空")
|
|
||||||
private List<Property> properties;
|
private List<Property> properties;
|
||||||
|
|
||||||
@ApiModelProperty(value = "销售价格,单位:分", required = true)
|
@ApiModelProperty(value = "销售价格,单位:分", required = true)
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateSkus(List<ProductSkuCreateReqVO> list) {
|
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<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList());
|
||||||
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);
|
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);
|
||||||
|
|
|
@ -57,7 +57,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||||
categoryService.validateProductCategory(createReqVO.getCategoryId());
|
categoryService.validateProductCategory(createReqVO.getCategoryId());
|
||||||
// 校验SKU
|
// 校验SKU
|
||||||
List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus();
|
List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus();
|
||||||
|
if(createReqVO.getSpecType() == 1) {
|
||||||
productSkuService.validateSkus(skuCreateReqList);
|
productSkuService.validateSkus(skuCreateReqList);
|
||||||
|
}
|
||||||
// 插入SPU
|
// 插入SPU
|
||||||
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
||||||
ProductSpuMapper.insert(spu);
|
ProductSpuMapper.insert(spu);
|
||||||
|
@ -81,7 +83,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||||
categoryService.validateProductCategory(updateReqVO.getCategoryId());
|
categoryService.validateProductCategory(updateReqVO.getCategoryId());
|
||||||
// 校验SKU
|
// 校验SKU
|
||||||
List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus();
|
List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus();
|
||||||
|
if(updateReqVO.getSpecType() == 1) {
|
||||||
productSkuService.validateSkus(skuCreateReqList);
|
productSkuService.validateSkus(skuCreateReqList);
|
||||||
|
}
|
||||||
// 更新
|
// 更新
|
||||||
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
|
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
|
||||||
ProductSpuMapper.updateById(updateObj);
|
ProductSpuMapper.updateById(updateObj);
|
||||||
|
|
|
@ -178,8 +178,8 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body >
|
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close>
|
||||||
<save @closeDialog="open = false"/>
|
<save @closeDialog="open = false; getList()"/>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -309,6 +309,7 @@ export default {
|
||||||
if (this.ratesForm.spec == 1) {
|
if (this.ratesForm.spec == 1) {
|
||||||
rates.forEach(r => {
|
rates.forEach(r => {
|
||||||
let properties = []
|
let properties = []
|
||||||
|
if(r.spec instanceof Array){
|
||||||
r.spec.forEach((v, i) => {
|
r.spec.forEach((v, i) => {
|
||||||
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
|
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
|
||||||
let propertie = {};
|
let propertie = {};
|
||||||
|
@ -316,19 +317,25 @@ export default {
|
||||||
propertie.valueId = specValue.id;
|
propertie.valueId = specValue.id;
|
||||||
properties.push(propertie);
|
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;
|
r.properties = properties;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.baseForm.skus = rates;
|
this.baseForm.skus = rates;
|
||||||
this.baseForm.specType = this.ratesForm.spec;
|
this.baseForm.specType = this.ratesForm.spec;
|
||||||
this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1];
|
this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1];
|
||||||
console.log(this.baseForm)
|
|
||||||
createSpu(this.baseForm).then((response) => {
|
createSpu(this.baseForm).then((response) => {
|
||||||
|
console.log(response)
|
||||||
this.$modal.msgSuccess("新增成功");
|
this.$modal.msgSuccess("新增成功");
|
||||||
this.open = false;
|
|
||||||
this.getList();
|
|
||||||
this.$emit("closeDialog");
|
this.$emit("closeDialog");
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
/** 查询规格 */
|
/** 查询规格 */
|
||||||
getPropertyPageList() {
|
getPropertyPageList() {
|
||||||
|
|
Loading…
Reference in New Issue