1、spu界面规格功能实现
This commit is contained in:
parent
9b921c3753
commit
4af0056fca
|
|
@ -53,3 +53,21 @@ export function deleteRelation(ids) {
|
|||
})
|
||||
}
|
||||
|
||||
// 查询商品规格属性
|
||||
export function baseAtteListForSpu(spuId) {
|
||||
return request({
|
||||
url: `/mall-product/product/attr/base/listforspu/${spuId}`,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
// 修改商品规格属性
|
||||
export function updateSpuAttr(spuId,data) {
|
||||
return request({
|
||||
url: `/mall-product/product/attr/update/${spuId}`,
|
||||
method: 'put',
|
||||
data:data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="16">
|
||||
<el-card class="box-card">
|
||||
<el-tabs tab-position="left" style="width:98%">
|
||||
<el-tab-pane
|
||||
:label="group.attrGroupName"
|
||||
v-for="(group,gidx) in dataResp.attrGroups"
|
||||
:key="group.attrGroupId"
|
||||
>
|
||||
<!-- 遍历属性,每个tab-pane对应一个表单,每个属性是一个表单项 spu.baseAttrs[0] = [{attrId:xx,val:}]-->
|
||||
<el-form ref="form" :model="dataResp" label-position="right">
|
||||
<el-form-item
|
||||
label-width="80px"
|
||||
:label="attr.attrName"
|
||||
v-for="(attr,aidx) in group.attrs"
|
||||
:key="attr.attrId"
|
||||
>
|
||||
<el-input
|
||||
v-model="dataResp.baseAttrs[gidx][aidx].attrId"
|
||||
type="hidden"
|
||||
v-show="false"
|
||||
></el-input>
|
||||
<el-select
|
||||
v-model="dataResp.baseAttrs[gidx][aidx].attrValues"
|
||||
:multiple="attr.valueType === 1"
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
placeholder="请选择或输入值"
|
||||
>
|
||||
<el-option
|
||||
v-for="(val,vidx) in attr.valueSelect.split(';')"
|
||||
:key="vidx"
|
||||
:label="val"
|
||||
:value="val"
|
||||
></el-option>
|
||||
</el-select>
|
||||
<el-checkbox
|
||||
style="margin-left: 25px"
|
||||
v-model="dataResp.baseAttrs[gidx][aidx].showDesc"
|
||||
:true-label="1"
|
||||
:false-label="0"
|
||||
>快速展示
|
||||
</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<div style="margin:auto;margin-bottom: 35px">
|
||||
<el-button type="success" style="float:right" @click="submitSpuAttrs">确认修改</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {baseAtteListForSpu, updateSpuAttr} from "@/api/mall/product/attr";
|
||||
import {getAttrGroupWithAttrs} from "@/api/mall/product/attr-group";
|
||||
|
||||
export default {
|
||||
name: "AttrUpdate",
|
||||
components: {},
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
spuId: "",
|
||||
catalogId: "",
|
||||
dataResp: {
|
||||
//后台返回的所有数据
|
||||
attrGroups: [],
|
||||
baseAttrs: []
|
||||
},
|
||||
spuAttrsMap: {}
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
methods: {
|
||||
clearData() {
|
||||
this.dataResp.attrGroups = [];
|
||||
this.dataResp.baseAttrs = [];
|
||||
this.spuAttrsMap = {};
|
||||
},
|
||||
|
||||
getSpuBaseAttrs() {
|
||||
baseAtteListForSpu(this.spuId).then(res => {
|
||||
res.data.forEach(item => {
|
||||
this.spuAttrsMap["" + item.attrId] = item;
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
getQueryParams() {
|
||||
this.spuId = this.$route.query.spuId;
|
||||
this.catalogId = this.$route.query.catalogId;
|
||||
},
|
||||
|
||||
showBaseAttrs() {
|
||||
let _this = this;
|
||||
getAttrGroupWithAttrs(this.catalogId).then(res => {
|
||||
//先对表单的baseAttrs进行初始化
|
||||
res.data.forEach(item => {
|
||||
let attrArray = [];
|
||||
item.attrs.forEach(attr => {
|
||||
let v = "";
|
||||
if (_this.spuAttrsMap["" + attr.attrId]) {
|
||||
v = _this.spuAttrsMap["" + attr.attrId].attrValue.split(";");
|
||||
if (v.length === 1) {
|
||||
v = v[0] + "";
|
||||
}
|
||||
}
|
||||
attrArray.push({
|
||||
attrId: attr.attrId,
|
||||
attrName: attr.attrName,
|
||||
attrValues: v,
|
||||
showDesc: _this.spuAttrsMap["" + attr.attrId]
|
||||
? _this.spuAttrsMap["" + attr.attrId].quickShow
|
||||
: attr.showDesc
|
||||
});
|
||||
});
|
||||
this.dataResp.baseAttrs.push(attrArray);
|
||||
});
|
||||
this.dataResp.attrGroups = res.data;
|
||||
})
|
||||
},
|
||||
|
||||
submitSpuAttrs() {
|
||||
let submitData = [];
|
||||
this.dataResp.baseAttrs.forEach(item => {
|
||||
item.forEach(attr => {
|
||||
let val = "";
|
||||
if (attr.attrValues instanceof Array) {
|
||||
val = attr.attrValues.join(";");
|
||||
} else {
|
||||
val = attr.attrValues;
|
||||
}
|
||||
|
||||
if (val !== "") {
|
||||
submitData.push({
|
||||
attrId: attr.attrId,
|
||||
attrName: attr.attrName,
|
||||
attrValue: val,
|
||||
quickShow: attr.showDesc
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.$confirm("修改商品规格信息, 是否继续?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(() => {
|
||||
updateSpuAttr(this.spuId, submitData).then(res => {
|
||||
this.$modal.notifySuccess("属性修改成功")
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.clearData();
|
||||
this.getQueryParams();
|
||||
if (this.spuId && this.catalogId) {
|
||||
this.showBaseAttrs();
|
||||
this.getSpuBaseAttrs();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
</style>
|
||||
|
|
@ -94,10 +94,10 @@ export default {
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
attrUpdateShow(row) {
|
||||
console.log(row);
|
||||
this.$router.push({
|
||||
path: "/product-attrupdate",
|
||||
path: "/mall/product/mall-attribute/spu-attribute",
|
||||
query: { spuId: row.id, catalogId: row.catalogId }
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,134 @@
|
|||
package com.xjs.validation;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 封装list
|
||||
* <br>
|
||||
* 实现嵌套校验
|
||||
* @author xiejs
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Data
|
||||
public class ValidList<E> implements List<E> {
|
||||
@Valid
|
||||
private List<E> list = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return list.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return list.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
return list.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return list.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return list.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
return list.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
return list.addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return list.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
return list.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
return list.set(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
list.add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
return list.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
return list.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
return list.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
return list.listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
return list.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
return list.subList(fromIndex, toIndex);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,16 @@ package com.xjs.mall.product.controller;
|
|||
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.xjs.mall.other.R;
|
||||
import com.xjs.mall.product.entity.AttrEntity;
|
||||
import com.xjs.mall.product.entity.ProductAttrValueEntity;
|
||||
import com.xjs.mall.product.service.AttrService;
|
||||
import com.xjs.mall.product.service.ProductAttrValueService;
|
||||
import com.xjs.mall.product.vo.AttrGroupRelationVo;
|
||||
import com.xjs.mall.product.vo.AttrResponseVo;
|
||||
import com.xjs.mall.product.vo.AttrVo;
|
||||
import com.xjs.utils.PageUtils;
|
||||
import com.xjs.mall.other.R;
|
||||
import com.xjs.validation.ValidList;
|
||||
import com.xjs.validation.group.AddGroup;
|
||||
import com.xjs.validation.group.UpdateGroup;
|
||||
import com.xjs.web.MyBaseController;
|
||||
|
|
@ -36,6 +39,24 @@ import java.util.Map;
|
|||
public class AttrController extends MyBaseController<AttrEntity> {
|
||||
@Autowired
|
||||
private AttrService attrService;
|
||||
@Autowired
|
||||
private ProductAttrValueService productAttrValueService;
|
||||
|
||||
@PutMapping("/update/{spuId}")
|
||||
@ApiOperation("修改商品规格属性")
|
||||
public R updateSpuAttr(@PathVariable Long spuId,
|
||||
@Validated(UpdateGroup.class) @RequestBody ValidList<ProductAttrValueEntity> entities) {
|
||||
productAttrValueService.updateSpuAttr(spuId, entities);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("base/listforspu/{spuId}")
|
||||
@ApiOperation("查询商品规格属性")
|
||||
public R baseAtteListForSpu(@PathVariable Long spuId) {
|
||||
List<ProductAttrValueEntity> list = productAttrValueService.baseAtteListForSpu(spuId);
|
||||
|
||||
return R.ok().put("data", list);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("relation/delete")
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ package com.xjs.mall.product.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.xjs.validation.group.UpdateGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* spu属性值
|
||||
*
|
||||
*
|
||||
* @author xiejs
|
||||
* @email 1294405880@qq.com
|
||||
* @date 2022-03-15 10:16:53
|
||||
|
|
@ -39,6 +40,7 @@ public class ProductAttrValueEntity implements Serializable {
|
|||
/**
|
||||
* 属性值
|
||||
*/
|
||||
@Size(message = "属性值应小于 20 字符",groups = UpdateGroup.class,max = 20)
|
||||
private String attrValue;
|
||||
/**
|
||||
* 顺序
|
||||
|
|
|
|||
|
|
@ -22,5 +22,19 @@ public interface ProductAttrValueService extends IService<ProductAttrValueEntity
|
|||
* @param spuId spuId
|
||||
*/
|
||||
void saveProductAttr(List<BaseAttrs> baseAttrs,Long spuId);
|
||||
|
||||
/**
|
||||
* 查询商品规格属性
|
||||
* @param spuId spu id
|
||||
* @return list
|
||||
*/
|
||||
List<ProductAttrValueEntity> baseAtteListForSpu(Long spuId);
|
||||
|
||||
/**
|
||||
* 修改商品规格属性
|
||||
* @param spuId spu id
|
||||
* @param entities 要修改的集合
|
||||
*/
|
||||
void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.xjs.mall.product.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xjs.mall.product.dao.ProductAttrValueDao;
|
||||
import com.xjs.mall.product.entity.AttrEntity;
|
||||
|
|
@ -9,12 +10,14 @@ import com.xjs.mall.product.service.ProductAttrValueService;
|
|||
import com.xjs.mall.product.vo.spu.BaseAttrs;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service("productAttrValueService")
|
||||
@Transactional
|
||||
public class ProductAttrValueServiceImpl extends ServiceImpl<ProductAttrValueDao, ProductAttrValueEntity> implements ProductAttrValueService {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -40,6 +43,23 @@ public class ProductAttrValueServiceImpl extends ServiceImpl<ProductAttrValueDao
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductAttrValueEntity> baseAtteListForSpu(Long spuId) {
|
||||
LambdaQueryWrapper<ProductAttrValueEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ProductAttrValueEntity::getSpuId, spuId);
|
||||
return super.baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities) {
|
||||
//删除这个spuId之前对应的所有属性
|
||||
super.baseMapper.delete(new LambdaQueryWrapper<ProductAttrValueEntity>().eq(ProductAttrValueEntity::getSpuId, spuId));
|
||||
|
||||
//更新
|
||||
List<ProductAttrValueEntity> collect = entities.stream().peek(item -> item.setSpuId(spuId)).collect(Collectors.toList());
|
||||
|
||||
super.saveBatch(collect);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.bean.BeanUtils;
|
||||
import com.xjs.mall.RemoteProductFeign;
|
||||
|
|
@ -17,6 +16,7 @@ import com.xjs.mall.ware.service.WareSkuService;
|
|||
import com.xjs.mall.ware.vo.WareSkuVo;
|
||||
import com.xjs.utils.PageUtils;
|
||||
import com.xjs.utils.Query;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -29,6 +29,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service("wareSkuService")
|
||||
@Transactional
|
||||
@Log4j2
|
||||
public class WareSkuServiceImpl extends ServiceImpl<WareSkuDao, WareSkuEntity> implements WareSkuService {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -78,14 +79,18 @@ public class WareSkuServiceImpl extends ServiceImpl<WareSkuDao, WareSkuEntity> i
|
|||
wareSkuEntity.setWareId(wareId);
|
||||
wareSkuEntity.setStockLocked(0);
|
||||
|
||||
//远程查询sku的名字
|
||||
R r = remoteProductFeign.getSkuNameById(skuId);
|
||||
if (r.getCode() == HttpStatus.SUCCESS) {
|
||||
wareSkuEntity.setSkuName((String) r.get("msg"));
|
||||
//远程查询sku的名字 没写降级,所以需要try catch
|
||||
try {
|
||||
R r = remoteProductFeign.getSkuNameById(skuId);
|
||||
if (r.getCode() == 0) {
|
||||
wareSkuEntity.setSkuName((String) r.get("msg"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
super.baseMapper.insert(wareSkuEntity);
|
||||
}else {
|
||||
} else {
|
||||
super.baseMapper.addStock(skuId, wareId, skuNum);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue