Commit 4207b2b61d6c8b0573b2ceb2e62db9bd8884a7df
1 parent
4a39f2d9
feature(uniapp商品): 商品加载
Showing
11 changed files
with
187 additions
and
133 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java
| ... | ... | @@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | 7 | import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; |
| 8 | +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; | |
| 9 | +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; | |
| 8 | 10 | import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; |
| 11 | +import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; | |
| 9 | 12 | import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; |
| 13 | +import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; | |
| 10 | 14 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; |
| 11 | 15 | import io.swagger.annotations.Api; |
| 12 | 16 | import io.swagger.annotations.ApiImplicitParam; |
| ... | ... | @@ -19,6 +23,7 @@ import javax.annotation.Resource; |
| 19 | 23 | import javax.servlet.http.HttpServletResponse; |
| 20 | 24 | import javax.validation.Valid; |
| 21 | 25 | import java.io.IOException; |
| 26 | +import java.util.Comparator; | |
| 22 | 27 | import java.util.List; |
| 23 | 28 | |
| 24 | 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -74,4 +79,14 @@ public class ProductBrandController { |
| 74 | 79 | return success(ProductBrandConvert.INSTANCE.convertPage(pageResult)); |
| 75 | 80 | } |
| 76 | 81 | |
| 82 | + @GetMapping("/list") | |
| 83 | + @ApiOperation("获得品牌列表") | |
| 84 | + @PreAuthorize("@ss.hasPermission('product:brand:query')") | |
| 85 | + public CommonResult<List<ProductBrandRespVO>> getProductCategoryList(@Valid ProductBrandListReqVO listVO) { | |
| 86 | + List<ProductBrandDO> list = brandService.getBrandList(listVO); | |
| 87 | + list.sort(Comparator.comparing(ProductBrandDO::getSort)); | |
| 88 | + return success(ProductBrandConvert.INSTANCE.convertList(list)); | |
| 89 | + } | |
| 90 | + | |
| 91 | + | |
| 77 | 92 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandListReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@ApiModel(value = "管理后台 - 商品品牌分页 Request VO") | |
| 8 | +@Data | |
| 9 | +public class ProductBrandListReqVO { | |
| 10 | + | |
| 11 | + @ApiModelProperty(value = "品牌名称", example = "芋道") | |
| 12 | + private String name; | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java
| ... | ... | @@ -40,7 +40,7 @@ public class ProductSkuDO extends BaseDO { |
| 40 | 40 | private String name; |
| 41 | 41 | /** |
| 42 | 42 | * SPU 编号 |
| 43 | - * | |
| 43 | + * <p> | |
| 44 | 44 | * 关联 {@link ProductSpuDO#getId()} |
| 45 | 45 | */ |
| 46 | 46 | private Long spuId; |
| ... | ... | @@ -71,7 +71,7 @@ public class ProductSkuDO extends BaseDO { |
| 71 | 71 | private String picUrl; |
| 72 | 72 | /** |
| 73 | 73 | * SKU 状态 |
| 74 | - * | |
| 74 | + * <p> | |
| 75 | 75 | * 枚举 {@link CommonStatusEnum} |
| 76 | 76 | */ |
| 77 | 77 | private Integer status; |
| ... | ... | @@ -100,13 +100,13 @@ public class ProductSkuDO extends BaseDO { |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * 属性编号 |
| 103 | - * | |
| 103 | + * <p> | |
| 104 | 104 | * 关联 {@link ProductPropertyDO#getId()} |
| 105 | 105 | */ |
| 106 | 106 | private Long propertyId; |
| 107 | 107 | /** |
| 108 | 108 | * 属性值编号 |
| 109 | - * | |
| 109 | + * <p> | |
| 110 | 110 | * 关联 {@link ProductPropertyValueDO#getId()} |
| 111 | 111 | */ |
| 112 | 112 | private Long valueId; | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java
| ... | ... | @@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.product.dal.mysql.brand; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandBaseVO; | |
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO; | |
| 6 | 8 | import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; |
| 8 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 11 | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 10 | 14 | @Mapper |
| 11 | 15 | public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> { |
| 12 | 16 | |
| ... | ... | @@ -18,4 +22,9 @@ public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> { |
| 18 | 22 | .orderByDesc(ProductBrandDO::getId)); |
| 19 | 23 | } |
| 20 | 24 | |
| 25 | + | |
| 26 | + default List<ProductBrandDO> selectList(ProductBrandListReqVO reqVO) { | |
| 27 | + return selectList(new LambdaQueryWrapperX<ProductBrandDO>() | |
| 28 | + .likeIfPresent(ProductBrandDO::getName, reqVO.getName())); | |
| 29 | + } | |
| 21 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java
| 1 | 1 | package cn.iocoder.yudao.module.product.service.brand; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; | |
| 6 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; | |
| 4 | +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; | |
| 7 | 5 | import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; |
| 8 | 6 | |
| 9 | 7 | import javax.validation.Valid; |
| ... | ... | @@ -56,6 +54,20 @@ public interface ProductBrandService { |
| 56 | 54 | List<ProductBrandDO> getBrandList(Collection<Long> ids); |
| 57 | 55 | |
| 58 | 56 | /** |
| 57 | + * 获得品牌列表 | |
| 58 | + * @param listVo 请求参数 | |
| 59 | + * @return 品牌列表 | |
| 60 | + */ | |
| 61 | + List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo); | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 验证选择的商品分类是否合法 | |
| 65 | + * | |
| 66 | + * @param id 分类编号 | |
| 67 | + */ | |
| 68 | + void validateProductBrand(Long id); | |
| 69 | + | |
| 70 | + /** | |
| 59 | 71 | * 获得品牌分页 |
| 60 | 72 | * |
| 61 | 73 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.product.service.brand; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; | |
| 6 | -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; | |
| 4 | +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; | |
| 7 | 5 | import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; |
| 8 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; |
| 9 | 7 | import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper; |
| 8 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 10 | 9 | import org.springframework.stereotype.Service; |
| 11 | 10 | import org.springframework.validation.annotation.Validated; |
| 12 | 11 | |
| ... | ... | @@ -16,6 +15,7 @@ import java.util.List; |
| 16 | 15 | |
| 17 | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | 17 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS; |
| 18 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_CATEGORY_LEVEL; | |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 品牌 Service 实现类 |
| ... | ... | @@ -72,6 +72,18 @@ public class ProductBrandServiceImpl implements ProductBrandService { |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | @Override |
| 75 | + public List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo) { | |
| 76 | + return brandMapper.selectList(listVo); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 80 | + public void validateProductBrand(Long id) { | |
| 81 | + if(getBrand(id) == null){ | |
| 82 | + throw exception(PRODUCT_BRAND_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 75 | 87 | public PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO) { |
| 76 | 88 | return brandMapper.selectPage(pageReqVO); |
| 77 | 89 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| ... | ... | @@ -140,7 +140,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 140 | 140 | |
| 141 | 141 | @Override |
| 142 | 142 | public List<ProductSkuDO> getSkusBySpuId(Long spuId) { |
| 143 | - return productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); | |
| 143 | + List<ProductSkuDO> productSkuDOS = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); | |
| 144 | + return productSkuDOS; | |
| 144 | 145 | } |
| 145 | 146 | |
| 146 | 147 | @Override | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| ... | ... | @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 20 | 20 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 21 | 21 | import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; |
| 22 | 22 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; |
| 23 | +import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; | |
| 23 | 24 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 24 | 25 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; |
| 25 | 26 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| ... | ... | @@ -55,17 +56,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 55 | 56 | @Resource |
| 56 | 57 | private ProductPropertyService productPropertyService; |
| 57 | 58 | |
| 59 | + @Resource | |
| 60 | + private ProductBrandService brandService; | |
| 61 | + | |
| 58 | 62 | @Override |
| 59 | 63 | @Transactional |
| 60 | 64 | public Long createProductSpu(ProductSpuCreateReqVO createReqVO) { |
| 61 | 65 | // 校验分类 |
| 62 | 66 | categoryService.validateProductCategory(createReqVO.getCategoryId()); |
| 63 | - // TODO @:校验品牌 | |
| 64 | - | |
| 67 | + // 校验品牌 | |
| 68 | + brandService.validateProductBrand(createReqVO.getBrandId()); | |
| 65 | 69 | // 校验SKU |
| 66 | 70 | List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus(); |
| 67 | 71 | productSkuService.validateProductSkus(skuCreateReqList, createReqVO.getSpecType()); |
| 68 | - | |
| 69 | 72 | // 插入 SPU |
| 70 | 73 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); |
| 71 | 74 | spu.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice)); |
| ... | ... | @@ -73,7 +76,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 73 | 76 | spu.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice)); |
| 74 | 77 | spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum)); |
| 75 | 78 | ProductSpuMapper.insert(spu); |
| 76 | - | |
| 77 | 79 | // 插入 SKU |
| 78 | 80 | productSkuService.createProductSkus(skuCreateReqList, spu.getId()); |
| 79 | 81 | // 返回 |
| ... | ... | @@ -128,27 +130,29 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 128 | 130 | spuVO.setSkus(skuReqs); |
| 129 | 131 | List<ProductSkuRespVO.Property> properties = new ArrayList<>(); |
| 130 | 132 | // 组合 sku 规格属性 |
| 131 | - for (ProductSkuRespVO productSkuRespVO : skuReqs) { | |
| 132 | - properties.addAll(productSkuRespVO.getProperties()); | |
| 133 | - } | |
| 134 | - Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); | |
| 135 | - List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); | |
| 136 | - // 装载组装过后的属性 | |
| 137 | - List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>(); | |
| 138 | - propertyAndValueList.forEach(p -> { | |
| 139 | - ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); | |
| 140 | - productPropertyViewRespVO.setPropertyId(p.getId()); | |
| 141 | - productPropertyViewRespVO.setName(p.getName()); | |
| 142 | - Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>(); | |
| 143 | - Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); | |
| 144 | - propertyMaps.get(p.getId()).forEach(pv -> { | |
| 145 | - ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); | |
| 146 | - propertyValues.add(tuple2); | |
| 133 | + if(spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { | |
| 134 | + for (ProductSkuRespVO productSkuRespVO : skuReqs) { | |
| 135 | + properties.addAll(productSkuRespVO.getProperties()); | |
| 136 | + } | |
| 137 | + Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); | |
| 138 | + List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); | |
| 139 | + // 装载组装过后的属性 | |
| 140 | + List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>(); | |
| 141 | + propertyAndValueList.forEach(p -> { | |
| 142 | + ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); | |
| 143 | + productPropertyViewRespVO.setPropertyId(p.getId()); | |
| 144 | + productPropertyViewRespVO.setName(p.getName()); | |
| 145 | + Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>(); | |
| 146 | + Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); | |
| 147 | + propertyMaps.get(p.getId()).forEach(pv -> { | |
| 148 | + ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); | |
| 149 | + propertyValues.add(tuple2); | |
| 150 | + }); | |
| 151 | + productPropertyViewRespVO.setPropertyValues(propertyValues); | |
| 152 | + productPropertyViews.add(productPropertyViewRespVO); | |
| 147 | 153 | }); |
| 148 | - productPropertyViewRespVO.setPropertyValues(propertyValues); | |
| 149 | - productPropertyViews.add(productPropertyViewRespVO); | |
| 150 | - }); | |
| 151 | - spuVO.setProductPropertyViews(productPropertyViews); | |
| 154 | + spuVO.setProductPropertyViews(productPropertyViews); | |
| 155 | + } | |
| 152 | 156 | // 组合分类 |
| 153 | 157 | if (null != spuVO.getCategoryId()) { |
| 154 | 158 | LinkedList<Long> categoryArray = new LinkedList<>(); | ... | ... |
yudao-ui-admin/src/api/mall/product/brand.js
| ... | ... | @@ -34,6 +34,15 @@ export function getBrand(id) { |
| 34 | 34 | }) |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | +// 获得品牌list | |
| 38 | +export function getBrandList() { | |
| 39 | + return request({ | |
| 40 | + url: '/product/brand/list', | |
| 41 | + method: 'get' | |
| 42 | + }) | |
| 43 | +} | |
| 44 | + | |
| 45 | + | |
| 37 | 46 | // 获得品牌分页 |
| 38 | 47 | export function getBrandPage(query) { |
| 39 | 48 | return request({ | ... | ... |
yudao-ui-admin/src/views/mall/product/spu/index.vue
| ... | ... | @@ -179,7 +179,7 @@ |
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" > |
| 182 | - <save @closeDialog="open = false; getList()"/> | |
| 182 | + <save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" /> | |
| 183 | 183 | </el-dialog> |
| 184 | 184 | </div> |
| 185 | 185 | </template> |
| ... | ... | @@ -257,6 +257,10 @@ export default { |
| 257 | 257 | title: "", |
| 258 | 258 | // 是否显示弹出层 |
| 259 | 259 | open: false, |
| 260 | + // 弹出层类型 | |
| 261 | + dialogType: "add", | |
| 262 | + // 弹出层参数 | |
| 263 | + dialogObj:{}, | |
| 260 | 264 | dateRangeCreateTime: [], |
| 261 | 265 | // 查询参数 |
| 262 | 266 | queryParams: { |
| ... | ... | @@ -570,75 +574,25 @@ export default { |
| 570 | 574 | }, |
| 571 | 575 | /** 新增按钮操作 */ |
| 572 | 576 | handleAdd() { |
| 573 | - this.reset(); | |
| 577 | + this.dialogType = "add"; | |
| 578 | + this.dialogObj={}; | |
| 574 | 579 | this.open = true; |
| 575 | 580 | this.title = "添加商品spu"; |
| 576 | - this.getPropertyPageList(); | |
| 577 | 581 | }, |
| 578 | 582 | /** 修改按钮操作 */ |
| 579 | 583 | handleUpdate(row) { |
| 580 | - this.reset(); | |
| 581 | - const id = row.id; | |
| 582 | - getSpu(id).then((response) => { | |
| 583 | - let dataSpu = response.data; | |
| 584 | - this.form = { | |
| 585 | - id: dataSpu.id, | |
| 586 | - name: dataSpu.name, | |
| 587 | - sellPoint: dataSpu.sellPoint, | |
| 588 | - description: dataSpu.sellPoint, | |
| 589 | - categoryId: dataSpu.sellPoint, | |
| 590 | - categoryIds: dataSpu.categoryIds, | |
| 591 | - picUrls: dataSpu.picUrls, | |
| 592 | - sort: dataSpu.sort, | |
| 593 | - likeCount: dataSpu.likeCount, | |
| 594 | - price: dataSpu.price, | |
| 595 | - quantity: dataSpu.quantity, | |
| 596 | - status: dataSpu.status, | |
| 597 | - isShowTagInput: undefined, | |
| 598 | - skus: [], | |
| 599 | - skusList: dataSpu.skus, | |
| 600 | - productPropertyViews: dataSpu.productPropertyViews, | |
| 601 | - // skus:dataSpu.productSkuRespVOS, | |
| 602 | - }; | |
| 603 | - this.getDataHandle(); | |
| 604 | - this.open = true; | |
| 605 | - this.title = "修改商品spu"; | |
| 606 | - }); | |
| 584 | + this.dialogType = "upd"; | |
| 585 | + this.dialogObj.id = row.id; | |
| 586 | + this.open = true; | |
| 587 | + console.log("修改") | |
| 588 | + this.title = "修改商品spu"; | |
| 607 | 589 | }, |
| 608 | - getDataHandle() { | |
| 609 | - let that = this; | |
| 610 | - let productPropertyViews = JSON.parse( | |
| 611 | - JSON.stringify(this.form.productPropertyViews) | |
| 612 | - ); | |
| 613 | - productPropertyViews = productPropertyViews.sort( | |
| 614 | - (a, b) => a.propertyId - b.propertyId | |
| 615 | - ); | |
| 616 | - productPropertyViews.forEach((item) => { | |
| 617 | - item.propertyValues = item.propertyValues.sort((a, b) => a.v1 - b.v1); | |
| 618 | - }); | |
| 619 | - let skuIds = []; | |
| 620 | - for (let i = 0; i < productPropertyViews.length; i++) { | |
| 621 | - let han = { | |
| 622 | - name: productPropertyViews[i].name, | |
| 623 | - propertyId: productPropertyViews[i].propertyId, | |
| 624 | - selectValues: [], | |
| 625 | - selectValueIds: [], | |
| 626 | - }; | |
| 627 | - for ( | |
| 628 | - let j = 0; | |
| 629 | - j < productPropertyViews[i].propertyValues.length; | |
| 630 | - j++ | |
| 631 | - ) { | |
| 632 | - han.selectValues.push(productPropertyViews[i].propertyValues[j].v2); | |
| 633 | - han.selectValueIds.push(productPropertyViews[i].propertyValues[j].v1); | |
| 634 | - } | |
| 635 | - skuIds.push(han); | |
| 636 | - } | |
| 637 | - this.skuTags = skuIds; | |
| 638 | - this.unUseTags = this.allhistoryTags.filter((v) => | |
| 639 | - skuIds.every((val) => val.name != v.name) | |
| 640 | - ); | |
| 641 | - this.getHandleTable(); | |
| 590 | + closeDialog(){ | |
| 591 | + console.log("关闭") | |
| 592 | + this.dialogType = "add"; | |
| 593 | + this.dialogObj={}; | |
| 594 | + this.open = false; | |
| 595 | + this.getList() | |
| 642 | 596 | }, |
| 643 | 597 | getHandleTable() { |
| 644 | 598 | this.form.skus = []; |
| ... | ... | @@ -699,33 +653,6 @@ export default { |
| 699 | 653 | } |
| 700 | 654 | }); |
| 701 | 655 | }, |
| 702 | - /** 提交按钮 */ | |
| 703 | - submitForm() { | |
| 704 | - this.$refs["form"].validate((valid) => { | |
| 705 | - if (!valid) { | |
| 706 | - return; | |
| 707 | - } | |
| 708 | - this.form.picUrls = this.form.picUrls.split(","); | |
| 709 | - this.form.categoryId = | |
| 710 | - this.form.categoryIds[this.form.categoryIds.length - 1]; | |
| 711 | - this.form.status = Number(this.form.status); | |
| 712 | - // 修改的提交 | |
| 713 | - if (this.form.id != null) { | |
| 714 | - updateSpu(this.form).then((response) => { | |
| 715 | - this.$modal.msgSuccess("修改成功"); | |
| 716 | - this.open = false; | |
| 717 | - this.getList(); | |
| 718 | - }); | |
| 719 | - return; | |
| 720 | - } | |
| 721 | - // 添加的提交 | |
| 722 | - createSpu(this.form).then((response) => { | |
| 723 | - this.$modal.msgSuccess("新增成功"); | |
| 724 | - this.open = false; | |
| 725 | - this.getList(); | |
| 726 | - }); | |
| 727 | - }); | |
| 728 | - }, | |
| 729 | 656 | /** 删除按钮操作 */ |
| 730 | 657 | handleDelete(row) { |
| 731 | 658 | const id = row.id; | ... | ... |
yudao-ui-admin/src/views/mall/product/spu/save.vue
| ... | ... | @@ -193,6 +193,16 @@ |
| 193 | 193 | <!-- 销售设置 --> |
| 194 | 194 | <el-tab-pane label="销售设置" name="fourth"> |
| 195 | 195 | <el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%"> |
| 196 | + <el-form-item label="所属品牌" prop="brandId"> | |
| 197 | + <el-select v-model="baseForm.brandId" placeholder="请选择"> | |
| 198 | + <el-option | |
| 199 | + v-for="item in brandList" | |
| 200 | + :key="item.id" | |
| 201 | + :label="item.name" | |
| 202 | + :value="item.id"> | |
| 203 | + </el-option> | |
| 204 | + </el-select> | |
| 205 | + </el-form-item> | |
| 196 | 206 | <el-form-item label="虚拟销量" prop="virtualSalesCount"> |
| 197 | 207 | <el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/> |
| 198 | 208 | </el-form-item> |
| ... | ... | @@ -221,8 +231,10 @@ |
| 221 | 231 | </template> |
| 222 | 232 | |
| 223 | 233 | <script> |
| 234 | + | |
| 235 | +import {getBrandList} from "@/api/mall/product/brand"; | |
| 224 | 236 | import {getProductCategoryList} from "@/api/mall/product/category"; |
| 225 | -import {createSpu,} from "@/api/mall/product/spu"; | |
| 237 | +import {createSpu, getSpu} from "@/api/mall/product/spu"; | |
| 226 | 238 | import {getPropertyPage,} from "@/api/mall/product/property"; |
| 227 | 239 | import Editor from "@/components/Editor"; |
| 228 | 240 | import ImageUpload from "@/components/ImageUpload"; |
| ... | ... | @@ -232,6 +244,13 @@ export default { |
| 232 | 244 | Editor, |
| 233 | 245 | ImageUpload |
| 234 | 246 | }, |
| 247 | + props:{//props列表 | |
| 248 | + type:{ | |
| 249 | + type:String, | |
| 250 | + default:"add" //定义参数默认值 | |
| 251 | + }, | |
| 252 | + obj: Object | |
| 253 | + }, | |
| 235 | 254 | data() { |
| 236 | 255 | return { |
| 237 | 256 | activeName: "base", |
| ... | ... | @@ -251,6 +270,7 @@ export default { |
| 251 | 270 | status: 0, |
| 252 | 271 | virtualSalesCount: 0, |
| 253 | 272 | showStock: true, |
| 273 | + brandId: null | |
| 254 | 274 | }, |
| 255 | 275 | categoryList: [], |
| 256 | 276 | // 价格库存 |
| ... | ... | @@ -270,6 +290,7 @@ export default { |
| 270 | 290 | // }, |
| 271 | 291 | ], |
| 272 | 292 | propertyPageList: [], |
| 293 | + brandList: [], | |
| 273 | 294 | specValue: null, |
| 274 | 295 | |
| 275 | 296 | // 表单校验 |
| ... | ... | @@ -283,11 +304,13 @@ export default { |
| 283 | 304 | }, |
| 284 | 305 | }; |
| 285 | 306 | }, |
| 286 | - | |
| 287 | 307 | created() { |
| 288 | - | |
| 308 | + this.getListBrand(); | |
| 289 | 309 | this.getListCategory(); |
| 290 | 310 | this.getPropertyPageList(); |
| 311 | + if(this.type == 'upd'){ | |
| 312 | + this.updateType(this.obj.id) | |
| 313 | + } | |
| 291 | 314 | }, |
| 292 | 315 | methods: { |
| 293 | 316 | removeSpec(index){ |
| ... | ... | @@ -352,6 +375,13 @@ export default { |
| 352 | 375 | this.categoryList = this.handleTree(response.data, "id", "parentId"); |
| 353 | 376 | }); |
| 354 | 377 | }, |
| 378 | + /** 查询品牌列表 */ | |
| 379 | + getListBrand() { | |
| 380 | + // 执行查询 | |
| 381 | + getBrandList().then((response) => { | |
| 382 | + this.brandList = response.data; | |
| 383 | + }); | |
| 384 | + }, | |
| 355 | 385 | cancel() { |
| 356 | 386 | this.$emit("closeDialog"); |
| 357 | 387 | }, |
| ... | ... | @@ -366,7 +396,13 @@ export default { |
| 366 | 396 | rates.forEach(r => { |
| 367 | 397 | let properties = [] |
| 368 | 398 | Array.of(r.spec).forEach(s => { |
| 369 | - Array.of(s).forEach((v, i) => { | |
| 399 | + let obj; | |
| 400 | + if (s instanceof Array) { | |
| 401 | + obj = s; | |
| 402 | + }else{ | |
| 403 | + obj = Array.of(s); | |
| 404 | + } | |
| 405 | + obj.forEach((v, i) => { | |
| 370 | 406 | console.log(this.dynamicSpec, r, s, v, i) |
| 371 | 407 | let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); |
| 372 | 408 | console.log(specValue) |
| ... | ... | @@ -382,9 +418,6 @@ export default { |
| 382 | 418 | rates[0].name = this.baseForm.name; |
| 383 | 419 | rates[0].status = this.baseForm.status; |
| 384 | 420 | } |
| 385 | - | |
| 386 | - console.log(rates) | |
| 387 | - | |
| 388 | 421 | let form = this.baseForm |
| 389 | 422 | if(form.picUrls instanceof Array){ |
| 390 | 423 | form.picUrls = form.picUrls.flatMap(m=>m.split(',')) |
| ... | ... | @@ -422,6 +455,24 @@ export default { |
| 422 | 455 | spec.specValue = obj.propertyValueList; |
| 423 | 456 | this.dynamicSpec = dynamicSpec; |
| 424 | 457 | this.buildRatesFormRates(); |
| 458 | + }, | |
| 459 | + updateType(id){ | |
| 460 | + getSpu(id).then((response) =>{ | |
| 461 | + console.log(response) | |
| 462 | + let data = response.data; | |
| 463 | + this.baseForm.name=data.name; | |
| 464 | + this.baseForm.sellPoint=data.sellPoint; | |
| 465 | + this.baseForm.categoryIds=data.categoryIds; | |
| 466 | + this.baseForm.sort=data.sort; | |
| 467 | + this.baseForm.description=data.description; | |
| 468 | + this.baseForm.picUrls=data.picUrls; | |
| 469 | + this.baseForm.status=data.status; | |
| 470 | + this.baseForm.virtualSalesCount=data.virtualSalesCount; | |
| 471 | + this.baseForm.showStock=data.showStock; | |
| 472 | + this.baseForm.brandId=data.brandId; | |
| 473 | + this.ratesForm.spec=data.specType; | |
| 474 | + this.ratesForm.rates=data.skus | |
| 475 | + }) | |
| 425 | 476 | } |
| 426 | 477 | }, |
| 427 | 478 | }; | ... | ... |