feature(uniapp分类): 商品创建功能以及查询功能正常使用

This commit is contained in:
luowenfeng 2022-08-22 20:43:12 +08:00
parent de27f4c2db
commit 617573a59b
7 changed files with 275 additions and 390 deletions

View File

@ -298,3 +298,27 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `
INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2027, 'Banner创建', 'market:banner:create', 3, 2, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2027, 'Banner创建', 'market:banner:create', 3, 2, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0');
INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2028, 'Banner更新', 'market:banner:update', 3, 3, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2028, 'Banner更新', 'market:banner:update', 3, 3, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0');
INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2029, 'Banner删除', 'market:banner:delete', 3, 4, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2029, 'Banner删除', 'market:banner:delete', 3, 4, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0');
alter table product_spu add `code` varchar(128) COMMENT '商品编码';
alter table product_spu add total_stock int COMMENT '总库存';
alter table product_spu add warn_stock int COMMENT '预警预存';
alter table product_spu add show_stock int COMMENT '是否展示库存';
alter table product_spu add sales_count int COMMENT '商品销量';
alter table product_spu add virtual_sales_count int COMMENT '虚拟销量';
alter table product_spu add click_count int COMMENT '商品点击量';
alter table product_spu add banner_url varchar(128) COMMENT '主图地址';
alter table product_spu add spec_type int COMMENT '规格类型';
alter table product_spu add brand_id int COMMENT '商品品牌编号';
alter table product_spu add video_url varchar(128) COMMENT '商品视频';
alter table product_spu add min_price int COMMENT '最小价格单位使用';
alter table product_spu add max_price int COMMENT '最大价格单位使用';
alter table product_spu add market_price int COMMENT '市场价单位使用';
alter table product_sku add `name` varchar(128) COMMENT '商品 SKU 名字';
alter table product_sku add `stock` int COMMENT '库存';
alter table product_sku add `weight` double COMMENT '商品重量';
alter table product_sku add `volume` double COMMENT '商品体积';
alter table product_sku DROP `original_price`;

View File

@ -27,16 +27,16 @@ public class ProductSkuBaseVO {
@NotNull(message = "销售价格,单位:分不能为空") @NotNull(message = "销售价格,单位:分不能为空")
private Integer price; private Integer price;
@ApiModelProperty(value = "价, 单位: 分", required = true) @ApiModelProperty(value = "市场价, 单位: 分", required = true)
@NotNull(message = "价, 单位: 分不能为空") @NotNull(message = "市场价, 单位: 分不能为空")
private Integer originalPrice; private Integer marketPrice;
@ApiModelProperty(value = "成本价,单位: 分", required = true) @ApiModelProperty(value = "成本价,单位: 分", required = true)
@NotNull(message = "成本价,单位: 分不能为空") @NotNull(message = "成本价,单位: 分不能为空")
private Integer costPrice; private Integer costPrice;
@ApiModelProperty(value = "条形码", required = true) @ApiModelProperty(value = "条形码")
@NotNull(message = "条形码不能为空") // @NotNull(message = "条形码不能为空")
private String barCode; private String barCode;
@ApiModelProperty(value = "图片地址", required = true) @ApiModelProperty(value = "图片地址", required = true)
@ -46,7 +46,15 @@ public class ProductSkuBaseVO {
@ApiModelProperty(value = "状态: 0-正常 1-禁用") @ApiModelProperty(value = "状态: 0-正常 1-禁用")
private Integer status; private Integer status;
// TODO @franky 要有 swagger 注解 @ApiModelProperty(value = "库存")
private Integer stock;
@ApiModelProperty(value = "商品重量单位kg 千克")
private Double weight;
@ApiModelProperty(value = "商品体积单位m^3 平米")
private Double volume;
@Data @Data
public static class Property { public static class Property {
@NotNull(message = "规格属性名id不能为空") @NotNull(message = "规格属性名id不能为空")

View File

@ -1,5 +1,8 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo; package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -16,6 +19,11 @@ public class ProductSpuBaseVO {
@ApiModelProperty(value = "商品名称") @ApiModelProperty(value = "商品名称")
private String name; private String name;
/**
* 商品编码
*/
private String code;
@ApiModelProperty(value = "卖点", required = true) @ApiModelProperty(value = "卖点", required = true)
@NotNull(message = "卖点不能为空") @NotNull(message = "卖点不能为空")
private String sellPoint; private String sellPoint;
@ -24,28 +32,87 @@ public class ProductSpuBaseVO {
@NotNull(message = "描述不能为空") @NotNull(message = "描述不能为空")
private String description; private String description;
/**
* 商品品牌编号
*
* 关联 {@link ProductBrandDO#getId()}
*/
private Long brandId;
@ApiModelProperty(value = "分类id", required = true) @ApiModelProperty(value = "分类id", required = true)
@NotNull(message = "分类id不能为空") @NotNull(message = "分类id不能为空")
private Long categoryId; private Long categoryId;
/**
* 商品主图
*/
private String bannerUrl;
@ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true) @ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true)
@NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空") @NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空")
private List<String> picUrls; private List<String> picUrls;
/**
* 商品视频
*/
private String videoUrl;
/**
* 规格类型
*
* 枚举 {@link ProductSpuSpecTypeEnum}
*/
private Integer specType;
@ApiModelProperty(value = "排序字段", required = true) @ApiModelProperty(value = "排序字段", required = true)
@NotNull(message = "排序字段不能为空") @NotNull(message = "排序字段不能为空")
private Integer sort; private Integer sort;
/**
@ApiModelProperty(value = "点赞初始人数") * 最小价格单位使用
private Integer likeCount; *
* 基于其对应的 {@link ProductSkuDO#getPrice()} 最小值
@ApiModelProperty(value = "价格 单位使用:分") */
private Integer price; private Integer minPrice;
/**
@ApiModelProperty(value = "库存数量") * 最大价格单位使用
private Integer quantity; *
* 基于其对应的 {@link ProductSkuDO#getPrice()} 最大值
*/
private Integer maxPrice;
/**
* 市场价单位使用
*
* 基于其对应的 {@link ProductSkuDO#getMarketPrice()} 最大值
*/
private Integer marketPrice;
/**
* 总库存
*
* 基于其对应的 {@link ProductSkuDO#getStock()} 求和
*/
private Integer totalStock;
/**
* 预警预存
*/
private Integer warnStock;
/**
* 是否展示库存
*/
private Boolean showStock;
@ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)") @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
private Integer status; private Integer status;
/**
* 商品销量
*/
private Integer salesCount;
/**
* 虚拟销量
*/
private Integer virtualSalesCount;
/**
* 商品点击量
*/
private Integer clickCount;
} }

View File

@ -49,7 +49,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
//插入属性值 //插入属性值
List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList(); List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList();
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId())); productPropertyValueDOList.forEach(x-> x.setPropertyId(property.getId()));
productPropertyValueMapper.insertBatch(productPropertyValueDOList); productPropertyValueMapper.insertBatch(productPropertyValueDOList);
// 返回 // 返回
return property.getId(); return property.getId();
@ -67,7 +67,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
productPropertyValueMapper.deletePropertyValueByPropertyId(updateReqVO.getId()); productPropertyValueMapper.deletePropertyValueByPropertyId(updateReqVO.getId());
List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList(); List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList();
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId())); productPropertyValueDOList.forEach(x-> x.setPropertyId(updateReqVO.getId()));
productPropertyValueMapper.insertBatch(productPropertyValueDOList); productPropertyValueMapper.insertBatch(productPropertyValueDOList);
} }

View File

@ -2,9 +2,14 @@ package cn.iocoder.yudao.module.product.service.sku;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
@ -84,8 +89,6 @@ public class ProductSkuServiceImpl implements ProductSkuService {
return productSkuMapper.selectPage(pageReqVO); return productSkuMapper.selectPage(pageReqVO);
} }
// TODO @franky这个方法貌似实现的还是有点问题哈例如说throw 异常后面还执行逻辑~
// TODO @艿艿 咳咳throw 那里我是偷懒省略了{}哈哈我加上然后我调试下在优化下
@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 -> p.getProperties().stream()).collect(Collectors.toList());
@ -99,8 +102,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
skuPropertyList.forEach(p -> { skuPropertyList.forEach(p -> {
ProductPropertyRespVO productPropertyRespVO = propertyMap.get(p.getPropertyId()); ProductPropertyRespVO productPropertyRespVO = propertyMap.get(p.getPropertyId());
// 如果对应的属性名不存在或属性名下的属性值集合为空给出提示 // 如果对应的属性名不存在或属性名下的属性值集合为空给出提示
if (null == productPropertyRespVO || productPropertyRespVO.getPropertyValueList().isEmpty()) if (null == productPropertyRespVO || productPropertyRespVO.getPropertyValueList().isEmpty()) {
throw ServiceExceptionUtil.exception(PROPERTY_NOT_EXISTS); throw ServiceExceptionUtil.exception(PROPERTY_NOT_EXISTS);
}
// 判断改属性名对应的属性值是否存在,不存在给出提示 // 判断改属性名对应的属性值是否存在,不存在给出提示
if (!productPropertyRespVO.getPropertyValueList().stream().map(ProductPropertyValueRespVO::getId).collect(Collectors.toSet()).contains(p.getValueId())) { if (!productPropertyRespVO.getPropertyValueList().stream().map(ProductPropertyValueRespVO::getId).collect(Collectors.toSet()).contains(p.getValueId())) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS); throw ServiceExceptionUtil.exception(ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS);

View File

@ -181,246 +181,6 @@
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body > <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body >
<save @closeDialog="open = false"/> <save @closeDialog="open = false"/>
</el-dialog> </el-dialog>
<!-- 对话框(添加 / 修改) -->
<!-- <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="商品名称" prop="name">
<el-input v-model="form.name" placeholder="请输入商品名称" />
</el-form-item>
<el-form-item label="卖点" prop="sellPoint">
<el-input v-model="form.sellPoint" placeholder="请输入卖点" />
</el-form-item>
<el-form-item label="描述">
<editor v-model="form.description" :min-height="192" />
</el-form-item>
<el-form-item label="分类id" prop="categoryIds">
<el-cascader
v-model="form.categoryIds"
placeholder="请输入分类id"
style="width: 100%"
:options="categoryList"
:props="propName"
clearable
></el-cascader>
</el-form-item>
<el-form-item label="商品主图地址" prop="picUrls">
<ImageUpload v-model="form.picUrls" :limit="10" />
</el-form-item>
<el-form-item label="商品规格">
<el-button size="mini" @click="shopTagInput()">添加规格</el-button>
<div v-for="(tag, tagIndex) in skuTags" :key="tagIndex">
<span>{{ tag.name }}</span>
<el-button
style="margin-left: 10px"
class="button-new-tag"
type="text"
icon="el-icon-delete"
@click="removeTag(tagIndex)"
>删除
</el-button>
<br />
<el-tag
v-for="(tagItem, tagItemIndex) in tag.selectValues"
:key="tagItemIndex"
style="margin-right: 10px"
:disable-transitions="false"
>
{{ tagItem }}
</el-tag> -->
<!-- <el-input-->
<!-- class="input-new-tag"-->
<!-- v-if="tagItemInputs[tagIndex] && tagItemInputs[tagIndex].visible"-->
<!-- v-model="tagItemInputs[tagIndex].value"-->
<!-- :ref="`saveTagInput${tagIndex}`"-->
<!-- size="small"-->
<!-- @keyup.enter.native="handleInputConfirm(tagIndex)"-->
<!-- @blur="handleInputConfirm(tagIndex)">-->
<!-- </el-input>-->
<!-- </div>
</el-form-item>
<el-form-item label="规格名" v-show="isShowTagInput">
<el-col :span="8">
<el-select
v-model="addTagInput.name"
filterable
allow-create
default-first-option
placeholder="请选择"
@change="handleTagClick"
>
<el-option
v-for="item in unUseTags"
:key="item.id"
:label="item.name"
:value="item.name"
>
</el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item label="规格值" v-show="isShowTagInput">
<el-col :span="8">
<el-select
v-model="addTagInput.selectValues"
multiple
filterable
allow-create
default-first-option
placeholder="请选择"
>
<el-option
v-for="item in dbTagValues"
:key="item.id"
:label="item.name"
:value="item.name"
>
</el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item>
<el-button
size="mini"
type="primary"
@click="addTag()"
v-show="isShowTagInput"
>确定</el-button
>
<el-button size="mini" @click="hideTagInput()" v-show="isShowTagInput"
>取消</el-button
>
</el-form-item>
<el-form-item v-if="form.skus.length > 0">
<el-table
:data="form.skus"
border
style="width: 100%; margin-top: 20px"
:span-method="tableSpanMethod"
>
<el-table-column
v-for="(leftTitle, index) in skuTags"
:key="index"
:label="leftTitle.name"
>
<template slot-scope="scope">
{{ scope.row.propertyChildNames[index] }}
</template>
</el-table-column>
<el-table-column
v-if="skuTags.length"
prop="picUrl"
label="sku图片"
width="180"
>
<template slot-scope="scope">
<ImageUpload v-model="scope.row.picUrl" :limit="1">
</ImageUpload>
</template>
</el-table-column>
<el-table-column
prop="prodName"
label="条形码"
width="250"
v-if="skuTags.length"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.barCode"
type="textarea"
:disabled="scope.row.status == 1"
></el-input>
</template>
</el-table-column>
<el-table-column prop="price" label="销售价">
<template slot-scope="scope">
<el-input-number
size="small"
v-model="scope.row.price"
controls-position="right"
:precision="2"
:max="1000000000"
:min="0.01"
:disabled="scope.row.status == 1"
>
</el-input-number>
</template>
</el-table-column>
<el-table-column prop="oriPrice" label="成本价">
<template slot-scope="scope">
<el-input-number
size="small"
v-model="scope.row.costPrice"
controls-position="right"
:precision="2"
:max="1000000000"
:min="0.01"
:disabled="scope.row.status == 1"
>
</el-input-number>
</template>
</el-table-column>
<el-table-column prop="oriPrice" label="原价">
<template slot-scope="scope">
<el-input-number
size="small"
v-model="scope.row.originalPrice"
controls-position="right"
:precision="2"
:max="1000000000"
:min="0.01"
:disabled="scope.row.status == 1"
>
</el-input-number>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
type="text"
size="small"
@click="changeSkuStatus(`${scope.$index}`)"
v-if="scope.row.status === 0"
>
正常
</el-button>
<el-button
type="text"
size="small"
@click="changeSkuStatus(`${scope.$index}`)"
v-else
>已禁用</el-button
>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item label="排序字段" prop="sort">
<el-input v-model="form.sort" placeholder="请输入排序字段" />
</el-form-item>
<el-form-item label="点赞初始人数" prop="likeCount">
<el-input v-model="form.likeCount" placeholder="请输入点赞初始人数" />
</el-form-item>
<el-form-item label="价格 单位使用:分" prop="price">
<el-input
v-model="form.price"
placeholder="请输入价格 单位使用:分"
/>
</el-form-item>
<el-form-item label="库存数量" prop="quantity">
<el-input v-model="form.quantity" placeholder="请输入库存数量" />
</el-form-item>
<el-form-item label="上下架状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio label="0">上架</el-radio>
<el-radio label="1">下架</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog> -->
</div> </div>
</template> </template>

View File

@ -1,25 +1,5 @@
<template> <template>
<div class="container"> <div class="container">
<el-dialog
title="请输入规格值,多个请换行"
:visible.sync="dialogForSpec"
append-to-body
width="400px"
@close="dialogForSpec = false; specValue = null"
>
<el-input
v-model="specValue"
type="textarea"
:autosize="{ minRows: 6, maxRows: 6}"
placeholder="请输入内容"
/>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogForSpec = false; specValue = null"> </el-button>
<el-button type="primary" @click="addSpecValue"> </el-button>
</div>
</el-dialog>
<el-tabs v-model="activeName" class="tabs"> <el-tabs v-model="activeName" class="tabs">
<!-- 基础设置 --> <!-- 基础设置 -->
<el-tab-pane label="基础设置" name="base"> <el-tab-pane label="基础设置" name="base">
@ -40,11 +20,11 @@
clearable clearable
></el-cascader> ></el-cascader>
</el-form-item> </el-form-item>
<el-form-item label="商品主图" prop="picUrls"> <el-form-item label="商品主图" prop="bannerUrl">
<ImageUpload v-model="baseForm.picUrl" :limit="1" /> <ImageUpload v-model="baseForm.bannerUrl" :limit="1"/>
</el-form-item> </el-form-item>
<el-form-item label="商品轮播图" prop="picUrl"> <el-form-item label="商品轮播图" prop="picUrls">
<ImageUpload v-model="baseForm.picUrls" :limit="10" /> <ImageUpload v-model="baseForm.picUrls" :limit="10"/>
</el-form-item> </el-form-item>
<el-form-item label="排序字段" prop="sort"> <el-form-item label="排序字段" prop="sort">
<el-input v-model="baseForm.sort" placeholder="请输入排序字段"/> <el-input v-model="baseForm.sort" placeholder="请输入排序字段"/>
@ -80,29 +60,28 @@
<div class="spec-header"> <div class="spec-header">
规格项 规格项
<el-input <el-select v-model="specs.specId" filterable placeholder="请选择" @change="changeSpec">
v-model="specs.spec_name" <el-option
placeholder="请填写规格项" v-for="item in propertyPageList"
class="spec-name" :key="item.id"
></el-input> :label="item.name"
:value="item.id">
</el-option>
</el-select>
</div> </div>
<div class="spec-values"> <div class="spec-values">
<template v-for="(specsValue, i) in specs.spec_values"> <template v-for="(v, i) in specs.specValue">
<el-input <el-input v-model="v.name" class="spec-value" :key="i"/>
v-model="specs.spec_values[i]"
class="spec-value"
:key="specsValue"
></el-input>
</template> </template>
<el-button <!-- <el-button
type="primary" type="primary"
icon="el-icon-plus" icon="el-icon-plus"
circle circle
@click="dialogForSpec = true; currentSpec = index" @click="dialogForSpec = true; currentSpec = index"
></el-button> ></el-button> -->
</div> </div>
</div> </div>
<el-button type="primary" @click="dynamicSpec.push({spec_values: []}); ratesForm.rates = []" <el-button type="primary" @click="dynamicSpec.push({specValue: []}); ratesForm.rates = []"
>添加规格项目 >添加规格项目
</el-button </el-button
> >
@ -112,8 +91,9 @@
<el-form-item label="规格明细"> <el-form-item label="规格明细">
<el-table :data="ratesForm.rates" border style="width: 100%" ref="rates"> <el-table :data="ratesForm.rates" border style="width: 100%" ref="rates">
<template v-if="ratesForm.spec == 1" > <template v-if="ratesForm.spec == 1">
<el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v=>v.spec_name != undefined)" :label="item.spec_name" > <el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v=>v.specName != undefined)"
:label="item.specName">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input <el-input
v-if="scope.row.spec" v-if="scope.row.spec"
@ -126,7 +106,8 @@
<el-table-column label="规格图片" width="120px"> <el-table-column label="规格图片" width="120px">
<template slot-scope="scope"> <template slot-scope="scope">
<ImageUpload v-model="scope.row.picUrl" :limit="1" :isShowTip="false" style="width: 100px; height: 50px" /> <ImageUpload v-model="scope.row.picUrl" :limit="1" :isShowTip="false"
style="width: 100px; height: 50px"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="市场价(元)"> <el-table-column label="市场价(元)">
@ -177,19 +158,19 @@
<!-- 商品详情 --> <!-- 商品详情 -->
<el-tab-pane label="商品描述" name="third"> <el-tab-pane label="商品描述" name="third">
<editor v-model="baseForm.description" :min-height="400" /> <editor v-model="baseForm.description" :min-height="400"/>
</el-tab-pane> </el-tab-pane>
<!-- 销售设置 --> <!-- 销售设置 -->
<el-tab-pane label="销售设置" name="fourth"> <el-tab-pane label="销售设置" name="fourth">
<el-form ref="baseForm" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%"> <el-form ref="baseForm" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
<el-form-item label="库存数量" prop="quantity"> <el-form-item label="库存数量" prop="totalStock">
<el-input v-model="baseForm.quantity" placeholder="请输入库存数量" /> <el-input v-model="baseForm.totalStock" placeholder="请输入库存数量"/>
</el-form-item> </el-form-item>
<el-form-item label="上下架状态" prop="status"> <el-form-item label="上下架状态" prop="status">
<el-radio-group v-model="baseForm.status"> <el-radio-group v-model="baseForm.status">
<el-radio label="0">上架</el-radio> <el-radio :label="0">上架</el-radio>
<el-radio label="1">下架</el-radio> <el-radio :label="1">下架</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -205,12 +186,12 @@
</template> </template>
<script> <script>
import { import {getProductCategoryList} from "@/api/mall/product/category";
getProductCategoryList import {createSpu,} from "@/api/mall/product/spu";
} from "@/api/mall/product/category"; 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";
export default { export default {
components: { components: {
Editor, Editor,
@ -231,12 +212,12 @@ export default {
categoryIds: null, categoryIds: null,
sort: null, sort: null,
description: null, description: null,
picUrl:null, bannerUrl: null,
picUrls: [], picUrls: [],
quantity: null totalStock: null,
status: 0
}, },
categoryList: [], categoryList: [],
// //
ratesForm: { ratesForm: {
spec: 0, spec: 0,
@ -245,15 +226,16 @@ export default {
}, },
dynamicSpec: [ dynamicSpec: [
// { // {
// spec_id: 86, // specId: 86,
// spec_name: "", // specName: "",
// spec_values: [], // specValue:[{
// spec_value_ids: [225], // name: "",
// id: 225,
// }]
// }, // },
], ],
dialogForSpec: false, propertyPageList: [],
specValue: null, specValue: null,
currentSpec: null,
// //
rules: { rules: {
@ -263,7 +245,7 @@ export default {
categoryIds: [ categoryIds: [
{required: true, message: "分类id不能为空", trigger: "blur"}, {required: true, message: "分类id不能为空", trigger: "blur"},
], ],
picUrls: [{required: true, message: "商品主图地址", trigger: "blur"}], bannerUrl: [{required: true, message: "商品主图地址", trigger: "blur"}],
sort: [ sort: [
{required: true, message: "排序字段不能为空", trigger: "blur"}, {required: true, message: "排序字段不能为空", trigger: "blur"},
], ],
@ -272,32 +254,33 @@ export default {
}, },
created() { created() {
this.getListCategory(); this.getListCategory();
this.getPropertyPageList();
}, },
methods: { methods: {
changeRadio() { changeRadio() {
this.$refs.rates.doLayout() this.$refs.rates.doLayout()
if(this.ratesForm.spec == 0){ if (this.ratesForm.spec == 0) {
this.ratesForm.rates = [{}] this.ratesForm.rates = [{}]
}else{ } else {
this.ratesForm.rates = [] this.ratesForm.rates = []
if(this.dynamicSpec.length > 0){ if (this.dynamicSpec.length > 0) {
this.buildRatesFormRates() this.buildRatesFormRates()
} }
} }
}, },
// //
buildRatesFormRates(){ buildRatesFormRates() {
let rates = []; let rates = [];
this.dynamicSpec.map(v=>v.spec_values) this.dynamicSpec.map(v => v.specValue.map(m => m.name))
.reduce((last, current) => { .reduce((last, current) => {
const array = []; const array = [];
last.forEach(par1 => { last.forEach(par1 => {
current.forEach(par2 => { current.forEach(par2 => {
let v let v
if(par1 instanceof Array){ if (par1 instanceof Array) {
v = par1.concat(par2) v = par1.concat(par2)
}else{ } else {
v = [par1, par2]; v = [par1, par2];
} }
array.push(v) array.push(v)
@ -305,21 +288,10 @@ export default {
}); });
return array; return array;
}) })
.forEach(v=>{ .forEach(v => {
rates.push({spec: v}) rates.push({spec: v})
}); });
console.log(rates)
this.ratesForm.rates = rates this.ratesForm.rates = rates
},
addSpecValue() {
this.dialogForSpec = false;
let specValue = this.dynamicSpec[this.currentSpec].spec_values
.concat(this.specValue.split(/[(\r\n)\r\n]+/))
.filter(v => v != "");
console.log(specValue)
this.dynamicSpec[this.currentSpec].spec_values = [...new Set(specValue)];
this.currentSpec = null;
this.buildRatesFormRates()
}, },
/** 查询分类 */ /** 查询分类 */
getListCategory() { getListCategory() {
@ -328,9 +300,53 @@ export default {
this.categoryList = this.handleTree(response.data, "id", "parentId"); this.categoryList = this.handleTree(response.data, "id", "parentId");
}); });
}, },
cancel(){ cancel() {
this.$emit("closeDialog"); this.$emit("closeDialog");
}, },
submit() {
let rates = this.ratesForm.rates;
//
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);
})
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) => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
this.$emit("closeDialog");
});
},
/** 查询规格 */
getPropertyPageList() {
//
getPropertyPage().then((response) => {
this.propertyPageList = response.data.list;
});
},
changeSpec(val) {
let obj = this.propertyPageList.find(o => o.id == val);
let dynamicSpec = this.dynamicSpec;
let spec = dynamicSpec.find(o => o.specId == val)
spec.specId = obj.id;
spec.specName = obj.name;
spec.specValue = obj.propertyValueList;
this.dynamicSpec = dynamicSpec;
this.buildRatesFormRates();
}
}, },
}; };
</script> </script>
@ -349,7 +365,7 @@ export default {
.spec-header { .spec-header {
padding: 30px; padding: 30px;
padding-bottom: 0; padding-bottom: 20px;
.spec-name { .spec-name {
display: inline; display: inline;
@ -364,6 +380,7 @@ export default {
width: 84%; width: 84%;
padding: 25px; padding: 25px;
margin: auto; margin: auto;
padding-top: 5px;
.spec-value { .spec-value {
display: inline-block; display: inline-block;
@ -381,35 +398,40 @@ export default {
} }
} }
.tabs{ .tabs {
height: 500px; height: 500px;
border-bottom: 2px solid #f2f2f2; border-bottom: 2px solid #f2f2f2;
.el-tab-pane{
.el-tab-pane {
height: 445px; height: 445px;
overflow-y: auto; overflow-y: auto;
} }
} }
// //
.rates{ .rates {
.component-upload-image{ .component-upload-image {
margin: auto; margin: auto;
} }
.el-upload--picture-card{
.el-upload--picture-card {
width: 100px; width: 100px;
height: 50px; height: 50px;
line-height: 60px; line-height: 60px;
margin: auto; margin: auto;
} }
.el-upload-list__item{
.el-upload-list__item {
width: 100px !important; width: 100px !important;
height: 50px !important; height: 50px !important;
}
} }
}
.buttons{ .buttons {
margin-top: 20px; margin-top: 20px;
height: 36px; height: 36px;
button{
button {
float: right; float: right;
margin-left: 15px; margin-left: 15px;
} }