mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-29 18:51:53 +08:00
feature(uniapp商品): 商品加载
This commit is contained in:
parent
4a39f2d9f8
commit
4207b2b61d
@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;
|
||||||
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
||||||
|
import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||||
|
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
|
||||||
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
|
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@ -19,6 +23,7 @@ import javax.annotation.Resource;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@ -74,4 +79,14 @@ public class ProductBrandController {
|
|||||||
return success(ProductBrandConvert.INSTANCE.convertPage(pageResult));
|
return success(ProductBrandConvert.INSTANCE.convertPage(pageResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("获得品牌列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('product:brand:query')")
|
||||||
|
public CommonResult<List<ProductBrandRespVO>> getProductCategoryList(@Valid ProductBrandListReqVO listVO) {
|
||||||
|
List<ProductBrandDO> list = brandService.getBrandList(listVO);
|
||||||
|
list.sort(Comparator.comparing(ProductBrandDO::getSort));
|
||||||
|
return success(ProductBrandConvert.INSTANCE.convertList(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ApiModel(value = "管理后台 - 商品品牌分页 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ProductBrandListReqVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "品牌名称", example = "芋道")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
@ -40,7 +40,7 @@ public class ProductSkuDO extends BaseDO {
|
|||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* SPU 编号
|
* SPU 编号
|
||||||
*
|
* <p>
|
||||||
* 关联 {@link ProductSpuDO#getId()}
|
* 关联 {@link ProductSpuDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
@ -71,7 +71,7 @@ public class ProductSkuDO extends BaseDO {
|
|||||||
private String picUrl;
|
private String picUrl;
|
||||||
/**
|
/**
|
||||||
* SKU 状态
|
* SKU 状态
|
||||||
*
|
* <p>
|
||||||
* 枚举 {@link CommonStatusEnum}
|
* 枚举 {@link CommonStatusEnum}
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
@ -100,13 +100,13 @@ public class ProductSkuDO extends BaseDO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 属性编号
|
* 属性编号
|
||||||
*
|
* <p>
|
||||||
* 关联 {@link ProductPropertyDO#getId()}
|
* 关联 {@link ProductPropertyDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long propertyId;
|
private Long propertyId;
|
||||||
/**
|
/**
|
||||||
* 属性值编号
|
* 属性值编号
|
||||||
*
|
* <p>
|
||||||
* 关联 {@link ProductPropertyValueDO#getId()}
|
* 关联 {@link ProductPropertyValueDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long valueId;
|
private Long valueId;
|
||||||
|
@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.product.dal.mysql.brand;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandBaseVO;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
|
public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
|
||||||
|
|
||||||
@ -18,4 +22,9 @@ public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
|
|||||||
.orderByDesc(ProductBrandDO::getId));
|
.orderByDesc(ProductBrandDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
default List<ProductBrandDO> selectList(ProductBrandListReqVO reqVO) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<ProductBrandDO>()
|
||||||
|
.likeIfPresent(ProductBrandDO::getName, reqVO.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.product.service.brand;
|
package cn.iocoder.yudao.module.product.service.brand;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -55,6 +53,20 @@ public interface ProductBrandService {
|
|||||||
*/
|
*/
|
||||||
List<ProductBrandDO> getBrandList(Collection<Long> ids);
|
List<ProductBrandDO> getBrandList(Collection<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得品牌列表
|
||||||
|
* @param listVo 请求参数
|
||||||
|
* @return 品牌列表
|
||||||
|
*/
|
||||||
|
List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证选择的商品分类是否合法
|
||||||
|
*
|
||||||
|
* @param id 分类编号
|
||||||
|
*/
|
||||||
|
void validateProductBrand(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得品牌分页
|
* 获得品牌分页
|
||||||
*
|
*
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package cn.iocoder.yudao.module.product.service.brand;
|
package cn.iocoder.yudao.module.product.service.brand;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||||
import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper;
|
import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
@ -16,6 +15,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS;
|
||||||
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_CATEGORY_LEVEL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品牌 Service 实现类
|
* 品牌 Service 实现类
|
||||||
@ -71,6 +71,18 @@ public class ProductBrandServiceImpl implements ProductBrandService {
|
|||||||
return brandMapper.selectBatchIds(ids);
|
return brandMapper.selectBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo) {
|
||||||
|
return brandMapper.selectList(listVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validateProductBrand(Long id) {
|
||||||
|
if(getBrand(id) == null){
|
||||||
|
throw exception(PRODUCT_BRAND_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO) {
|
public PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO) {
|
||||||
return brandMapper.selectPage(pageReqVO);
|
return brandMapper.selectPage(pageReqVO);
|
||||||
|
@ -140,7 +140,8 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductSkuDO> getSkusBySpuId(Long spuId) {
|
public List<ProductSkuDO> getSkusBySpuId(Long spuId) {
|
||||||
return productSkuMapper.selectBySpuIds(Collections.singletonList(spuId));
|
List<ProductSkuDO> productSkuDOS = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId));
|
||||||
|
return productSkuDOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
|||||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||||
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
|
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
|
||||||
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum;
|
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
|
||||||
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
|
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
|
||||||
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
|
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
|
||||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||||
@ -55,17 +56,19 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductPropertyService productPropertyService;
|
private ProductPropertyService productPropertyService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ProductBrandService brandService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Long createProductSpu(ProductSpuCreateReqVO createReqVO) {
|
public Long createProductSpu(ProductSpuCreateReqVO createReqVO) {
|
||||||
// 校验分类
|
// 校验分类
|
||||||
categoryService.validateProductCategory(createReqVO.getCategoryId());
|
categoryService.validateProductCategory(createReqVO.getCategoryId());
|
||||||
// TODO @:校验品牌
|
// 校验品牌
|
||||||
|
brandService.validateProductBrand(createReqVO.getBrandId());
|
||||||
// 校验SKU
|
// 校验SKU
|
||||||
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus();
|
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus();
|
||||||
productSkuService.validateProductSkus(skuCreateReqList, createReqVO.getSpecType());
|
productSkuService.validateProductSkus(skuCreateReqList, createReqVO.getSpecType());
|
||||||
|
|
||||||
// 插入 SPU
|
// 插入 SPU
|
||||||
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
||||||
spu.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice));
|
spu.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice));
|
||||||
@ -73,7 +76,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
spu.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice));
|
spu.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice));
|
||||||
spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
|
spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
|
||||||
ProductSpuMapper.insert(spu);
|
ProductSpuMapper.insert(spu);
|
||||||
|
|
||||||
// 插入 SKU
|
// 插入 SKU
|
||||||
productSkuService.createProductSkus(skuCreateReqList, spu.getId());
|
productSkuService.createProductSkus(skuCreateReqList, spu.getId());
|
||||||
// 返回
|
// 返回
|
||||||
@ -128,27 +130,29 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
spuVO.setSkus(skuReqs);
|
spuVO.setSkus(skuReqs);
|
||||||
List<ProductSkuRespVO.Property> properties = new ArrayList<>();
|
List<ProductSkuRespVO.Property> properties = new ArrayList<>();
|
||||||
// 组合 sku 规格属性
|
// 组合 sku 规格属性
|
||||||
for (ProductSkuRespVO productSkuRespVO : skuReqs) {
|
if(spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) {
|
||||||
properties.addAll(productSkuRespVO.getProperties());
|
for (ProductSkuRespVO productSkuRespVO : skuReqs) {
|
||||||
}
|
properties.addAll(productSkuRespVO.getProperties());
|
||||||
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
|
}
|
||||||
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet()));
|
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
|
||||||
// 装载组装过后的属性
|
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet()));
|
||||||
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
|
// 装载组装过后的属性
|
||||||
propertyAndValueList.forEach(p -> {
|
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
|
||||||
ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO();
|
propertyAndValueList.forEach(p -> {
|
||||||
productPropertyViewRespVO.setPropertyId(p.getId());
|
ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO();
|
||||||
productPropertyViewRespVO.setName(p.getName());
|
productPropertyViewRespVO.setPropertyId(p.getId());
|
||||||
Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>();
|
productPropertyViewRespVO.setName(p.getName());
|
||||||
Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv));
|
Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>();
|
||||||
propertyMaps.get(p.getId()).forEach(pv -> {
|
Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv));
|
||||||
ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
|
propertyMaps.get(p.getId()).forEach(pv -> {
|
||||||
propertyValues.add(tuple2);
|
ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
|
||||||
|
propertyValues.add(tuple2);
|
||||||
|
});
|
||||||
|
productPropertyViewRespVO.setPropertyValues(propertyValues);
|
||||||
|
productPropertyViews.add(productPropertyViewRespVO);
|
||||||
});
|
});
|
||||||
productPropertyViewRespVO.setPropertyValues(propertyValues);
|
spuVO.setProductPropertyViews(productPropertyViews);
|
||||||
productPropertyViews.add(productPropertyViewRespVO);
|
}
|
||||||
});
|
|
||||||
spuVO.setProductPropertyViews(productPropertyViews);
|
|
||||||
// 组合分类
|
// 组合分类
|
||||||
if (null != spuVO.getCategoryId()) {
|
if (null != spuVO.getCategoryId()) {
|
||||||
LinkedList<Long> categoryArray = new LinkedList<>();
|
LinkedList<Long> categoryArray = new LinkedList<>();
|
||||||
|
@ -34,6 +34,15 @@ export function getBrand(id) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获得品牌list
|
||||||
|
export function getBrandList() {
|
||||||
|
return request({
|
||||||
|
url: '/product/brand/list',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获得品牌分页
|
// 获得品牌分页
|
||||||
export function getBrandPage(query) {
|
export function getBrandPage(query) {
|
||||||
return request({
|
return request({
|
||||||
|
@ -179,7 +179,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" >
|
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" >
|
||||||
<save @closeDialog="open = false; getList()"/>
|
<save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" />
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -257,6 +257,10 @@ export default {
|
|||||||
title: "",
|
title: "",
|
||||||
// 是否显示弹出层
|
// 是否显示弹出层
|
||||||
open: false,
|
open: false,
|
||||||
|
// 弹出层类型
|
||||||
|
dialogType: "add",
|
||||||
|
// 弹出层参数
|
||||||
|
dialogObj:{},
|
||||||
dateRangeCreateTime: [],
|
dateRangeCreateTime: [],
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
@ -570,75 +574,25 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
handleAdd() {
|
handleAdd() {
|
||||||
this.reset();
|
this.dialogType = "add";
|
||||||
|
this.dialogObj={};
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "添加商品spu";
|
this.title = "添加商品spu";
|
||||||
this.getPropertyPageList();
|
|
||||||
},
|
},
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.reset();
|
this.dialogType = "upd";
|
||||||
const id = row.id;
|
this.dialogObj.id = row.id;
|
||||||
getSpu(id).then((response) => {
|
this.open = true;
|
||||||
let dataSpu = response.data;
|
console.log("修改")
|
||||||
this.form = {
|
this.title = "修改商品spu";
|
||||||
id: dataSpu.id,
|
|
||||||
name: dataSpu.name,
|
|
||||||
sellPoint: dataSpu.sellPoint,
|
|
||||||
description: dataSpu.sellPoint,
|
|
||||||
categoryId: dataSpu.sellPoint,
|
|
||||||
categoryIds: dataSpu.categoryIds,
|
|
||||||
picUrls: dataSpu.picUrls,
|
|
||||||
sort: dataSpu.sort,
|
|
||||||
likeCount: dataSpu.likeCount,
|
|
||||||
price: dataSpu.price,
|
|
||||||
quantity: dataSpu.quantity,
|
|
||||||
status: dataSpu.status,
|
|
||||||
isShowTagInput: undefined,
|
|
||||||
skus: [],
|
|
||||||
skusList: dataSpu.skus,
|
|
||||||
productPropertyViews: dataSpu.productPropertyViews,
|
|
||||||
// skus:dataSpu.productSkuRespVOS,
|
|
||||||
};
|
|
||||||
this.getDataHandle();
|
|
||||||
this.open = true;
|
|
||||||
this.title = "修改商品spu";
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getDataHandle() {
|
closeDialog(){
|
||||||
let that = this;
|
console.log("关闭")
|
||||||
let productPropertyViews = JSON.parse(
|
this.dialogType = "add";
|
||||||
JSON.stringify(this.form.productPropertyViews)
|
this.dialogObj={};
|
||||||
);
|
this.open = false;
|
||||||
productPropertyViews = productPropertyViews.sort(
|
this.getList()
|
||||||
(a, b) => a.propertyId - b.propertyId
|
|
||||||
);
|
|
||||||
productPropertyViews.forEach((item) => {
|
|
||||||
item.propertyValues = item.propertyValues.sort((a, b) => a.v1 - b.v1);
|
|
||||||
});
|
|
||||||
let skuIds = [];
|
|
||||||
for (let i = 0; i < productPropertyViews.length; i++) {
|
|
||||||
let han = {
|
|
||||||
name: productPropertyViews[i].name,
|
|
||||||
propertyId: productPropertyViews[i].propertyId,
|
|
||||||
selectValues: [],
|
|
||||||
selectValueIds: [],
|
|
||||||
};
|
|
||||||
for (
|
|
||||||
let j = 0;
|
|
||||||
j < productPropertyViews[i].propertyValues.length;
|
|
||||||
j++
|
|
||||||
) {
|
|
||||||
han.selectValues.push(productPropertyViews[i].propertyValues[j].v2);
|
|
||||||
han.selectValueIds.push(productPropertyViews[i].propertyValues[j].v1);
|
|
||||||
}
|
|
||||||
skuIds.push(han);
|
|
||||||
}
|
|
||||||
this.skuTags = skuIds;
|
|
||||||
this.unUseTags = this.allhistoryTags.filter((v) =>
|
|
||||||
skuIds.every((val) => val.name != v.name)
|
|
||||||
);
|
|
||||||
this.getHandleTable();
|
|
||||||
},
|
},
|
||||||
getHandleTable() {
|
getHandleTable() {
|
||||||
this.form.skus = [];
|
this.form.skus = [];
|
||||||
@ -699,33 +653,6 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
|
||||||
submitForm() {
|
|
||||||
this.$refs["form"].validate((valid) => {
|
|
||||||
if (!valid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.form.picUrls = this.form.picUrls.split(",");
|
|
||||||
this.form.categoryId =
|
|
||||||
this.form.categoryIds[this.form.categoryIds.length - 1];
|
|
||||||
this.form.status = Number(this.form.status);
|
|
||||||
// 修改的提交
|
|
||||||
if (this.form.id != null) {
|
|
||||||
updateSpu(this.form).then((response) => {
|
|
||||||
this.$modal.msgSuccess("修改成功");
|
|
||||||
this.open = false;
|
|
||||||
this.getList();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 添加的提交
|
|
||||||
createSpu(this.form).then((response) => {
|
|
||||||
this.$modal.msgSuccess("新增成功");
|
|
||||||
this.open = false;
|
|
||||||
this.getList();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
const id = row.id;
|
const id = row.id;
|
||||||
|
@ -193,6 +193,16 @@
|
|||||||
<!-- 销售设置 -->
|
<!-- 销售设置 -->
|
||||||
<el-tab-pane label="销售设置" name="fourth">
|
<el-tab-pane label="销售设置" name="fourth">
|
||||||
<el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
|
<el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
|
||||||
|
<el-form-item label="所属品牌" prop="brandId">
|
||||||
|
<el-select v-model="baseForm.brandId" placeholder="请选择">
|
||||||
|
<el-option
|
||||||
|
v-for="item in brandList"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="虚拟销量" prop="virtualSalesCount">
|
<el-form-item label="虚拟销量" prop="virtualSalesCount">
|
||||||
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
|
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -221,8 +231,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import {getBrandList} from "@/api/mall/product/brand";
|
||||||
import {getProductCategoryList} from "@/api/mall/product/category";
|
import {getProductCategoryList} from "@/api/mall/product/category";
|
||||||
import {createSpu,} from "@/api/mall/product/spu";
|
import {createSpu, getSpu} from "@/api/mall/product/spu";
|
||||||
import {getPropertyPage,} from "@/api/mall/product/property";
|
import {getPropertyPage,} from "@/api/mall/product/property";
|
||||||
import Editor from "@/components/Editor";
|
import Editor from "@/components/Editor";
|
||||||
import ImageUpload from "@/components/ImageUpload";
|
import ImageUpload from "@/components/ImageUpload";
|
||||||
@ -232,6 +244,13 @@ export default {
|
|||||||
Editor,
|
Editor,
|
||||||
ImageUpload
|
ImageUpload
|
||||||
},
|
},
|
||||||
|
props:{//props列表
|
||||||
|
type:{
|
||||||
|
type:String,
|
||||||
|
default:"add" //定义参数默认值
|
||||||
|
},
|
||||||
|
obj: Object
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeName: "base",
|
activeName: "base",
|
||||||
@ -251,6 +270,7 @@ export default {
|
|||||||
status: 0,
|
status: 0,
|
||||||
virtualSalesCount: 0,
|
virtualSalesCount: 0,
|
||||||
showStock: true,
|
showStock: true,
|
||||||
|
brandId: null
|
||||||
},
|
},
|
||||||
categoryList: [],
|
categoryList: [],
|
||||||
// 价格库存
|
// 价格库存
|
||||||
@ -270,6 +290,7 @@ export default {
|
|||||||
// },
|
// },
|
||||||
],
|
],
|
||||||
propertyPageList: [],
|
propertyPageList: [],
|
||||||
|
brandList: [],
|
||||||
specValue: null,
|
specValue: null,
|
||||||
|
|
||||||
// 表单校验
|
// 表单校验
|
||||||
@ -283,11 +304,13 @@ export default {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
this.getListBrand();
|
||||||
this.getListCategory();
|
this.getListCategory();
|
||||||
this.getPropertyPageList();
|
this.getPropertyPageList();
|
||||||
|
if(this.type == 'upd'){
|
||||||
|
this.updateType(this.obj.id)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
removeSpec(index){
|
removeSpec(index){
|
||||||
@ -351,6 +374,13 @@ export default {
|
|||||||
getProductCategoryList().then((response) => {
|
getProductCategoryList().then((response) => {
|
||||||
this.categoryList = this.handleTree(response.data, "id", "parentId");
|
this.categoryList = this.handleTree(response.data, "id", "parentId");
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
/** 查询品牌列表 */
|
||||||
|
getListBrand() {
|
||||||
|
// 执行查询
|
||||||
|
getBrandList().then((response) => {
|
||||||
|
this.brandList = response.data;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
cancel() {
|
cancel() {
|
||||||
this.$emit("closeDialog");
|
this.$emit("closeDialog");
|
||||||
@ -366,7 +396,13 @@ export default {
|
|||||||
rates.forEach(r => {
|
rates.forEach(r => {
|
||||||
let properties = []
|
let properties = []
|
||||||
Array.of(r.spec).forEach(s => {
|
Array.of(r.spec).forEach(s => {
|
||||||
Array.of(s).forEach((v, i) => {
|
let obj;
|
||||||
|
if (s instanceof Array) {
|
||||||
|
obj = s;
|
||||||
|
}else{
|
||||||
|
obj = Array.of(s);
|
||||||
|
}
|
||||||
|
obj.forEach((v, i) => {
|
||||||
console.log(this.dynamicSpec, r, s, v, i)
|
console.log(this.dynamicSpec, r, s, v, i)
|
||||||
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
|
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
|
||||||
console.log(specValue)
|
console.log(specValue)
|
||||||
@ -382,9 +418,6 @@ export default {
|
|||||||
rates[0].name = this.baseForm.name;
|
rates[0].name = this.baseForm.name;
|
||||||
rates[0].status = this.baseForm.status;
|
rates[0].status = this.baseForm.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(rates)
|
|
||||||
|
|
||||||
let form = this.baseForm
|
let form = this.baseForm
|
||||||
if(form.picUrls instanceof Array){
|
if(form.picUrls instanceof Array){
|
||||||
form.picUrls = form.picUrls.flatMap(m=>m.split(','))
|
form.picUrls = form.picUrls.flatMap(m=>m.split(','))
|
||||||
@ -422,6 +455,24 @@ export default {
|
|||||||
spec.specValue = obj.propertyValueList;
|
spec.specValue = obj.propertyValueList;
|
||||||
this.dynamicSpec = dynamicSpec;
|
this.dynamicSpec = dynamicSpec;
|
||||||
this.buildRatesFormRates();
|
this.buildRatesFormRates();
|
||||||
|
},
|
||||||
|
updateType(id){
|
||||||
|
getSpu(id).then((response) =>{
|
||||||
|
console.log(response)
|
||||||
|
let data = response.data;
|
||||||
|
this.baseForm.name=data.name;
|
||||||
|
this.baseForm.sellPoint=data.sellPoint;
|
||||||
|
this.baseForm.categoryIds=data.categoryIds;
|
||||||
|
this.baseForm.sort=data.sort;
|
||||||
|
this.baseForm.description=data.description;
|
||||||
|
this.baseForm.picUrls=data.picUrls;
|
||||||
|
this.baseForm.status=data.status;
|
||||||
|
this.baseForm.virtualSalesCount=data.virtualSalesCount;
|
||||||
|
this.baseForm.showStock=data.showStock;
|
||||||
|
this.baseForm.brandId=data.brandId;
|
||||||
|
this.ratesForm.spec=data.specType;
|
||||||
|
this.ratesForm.rates=data.skus
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user