提交 e50520a3 authored 作者: zgy's avatar zgy

完成商品参数

上级 56c9274d
package com.platform.controller;
import com.platform.entity.TbCfItemParamEntity;
import com.platform.service.TbCfItemParamService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import com.platform.utils.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 商品参数Controller
*
* @author lipengjun
* @date 2020-05-20 10:50:25
*/
@Controller
@RequestMapping("tbcfitemparam")
public class TbCfItemParamController {
@Autowired
private TbCfItemParamService tbCfItemParamService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("tbcfitemparam:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<TbCfItemParamEntity> tbCfItemParamList = tbCfItemParamService.queryList(query);
int total = tbCfItemParamService.queryTotal(query);
PageUtils pageUtil = new PageUtils(tbCfItemParamList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("tbcfitemparam:info")
@ResponseBody
public R info(@PathVariable("id") String id) {
TbCfItemParamEntity tbCfItemParam = tbCfItemParamService.queryObject(id);
return R.ok().put("tbCfItemParam", tbCfItemParam);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("tbcfitemparam:save")
@ResponseBody
public R save(@RequestBody TbCfItemParamEntity tbCfItemParam) {
tbCfItemParamService.save(tbCfItemParam);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("tbcfitemparam:update")
@ResponseBody
public R update(@RequestBody TbCfItemParamEntity tbCfItemParam) {
tbCfItemParamService.update(tbCfItemParam);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("tbcfitemparam:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
tbCfItemParamService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<TbCfItemParamEntity> list = tbCfItemParamService.queryList(params);
return R.ok().put("list", list);
}
/**
* 查看所有列表
*/
@RequestMapping("/queryParamByItemId")
@ResponseBody
public R queryParamByItemId(@RequestParam("itemId") String itemId) {
List<TbCfItemParamEntity> list;
if (!StringUtils.isBlank(itemId)) {
list = tbCfItemParamService.queryParamByItemId(itemId);
} else {
return R.error("参数不能为空");
}
return R.ok().put("list", list);
}
}
......@@ -2,6 +2,9 @@ package com.platform.dao;
import com.platform.entity.TbCfItemParamEntity;
import java.util.List;
/**
* 商品参数Dao
*
......@@ -10,4 +13,7 @@ import com.platform.entity.TbCfItemParamEntity;
*/
public interface TbCfItemParamDao extends BaseDao<TbCfItemParamEntity> {
List<TbCfItemParamEntity> queryParamByItemId(String itemId);
int deleteByItemId(String itemId);
}
......@@ -24,6 +24,18 @@ public class ItemDescSkus extends TbCfStationItemEntity {
* 商品规格信息
*/
private List<TbCfCategoryEntity> tree;
/**
* 商品参数
*/
private List<TbCfItemParamEntity> paramster;
public List<TbCfItemParamEntity> getParamster() {
return paramster;
}
public void setParamster(List<TbCfItemParamEntity> paramster) {
this.paramster = paramster;
}
public String getItemDesc() {
return itemDesc;
......
......@@ -12,6 +12,15 @@ public class ItemInfo {
private TbCfItemDescEntity itemDesc;
private List<TbCfItemSkusEntity> itemSkusList;
private List<TbCfCategoryEntity> categoryList;
private List<TbCfItemParamEntity> paramList;
public List<TbCfItemParamEntity> getParamList() {
return paramList;
}
public void setParamList(List<TbCfItemParamEntity> paramList) {
this.paramList = paramList;
}
public TbCfStationItemEntity getItem() {
return item;
......
......@@ -68,4 +68,6 @@ public interface TbCfItemParamService {
* @return 删除条数
*/
int deleteBatch(String[] ids);
List<TbCfItemParamEntity> queryParamByItemId(String itemId);
}
......@@ -56,4 +56,9 @@ public class TbCfItemParamServiceImpl implements TbCfItemParamService {
public int deleteBatch(String[] ids) {
return tbCfItemParamDao.deleteBatch(ids);
}
public List<TbCfItemParamEntity> queryParamByItemId(String itemId){
return tbCfItemParamDao.queryParamByItemId(itemId);
}
}
......@@ -48,6 +48,10 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
@Autowired
private SysUserDao sysUserDao;
@Autowired
private TbCfItemParamDao tbCfItemParamDao;
@Override
public ItemInfo queryItemInfoById(String itemId) {
//查询商品主体信息
......@@ -57,11 +61,12 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
//查询商品描述
TbCfItemDescEntity itemDesc = tbCfItemDescDao.queryObject(itemId);
List<TbCfCategoryEntity> categoryList = tbCfCategoryDao.queryByItemId(itemId);
List<TbCfItemParamEntity> paramList = tbCfItemParamDao.queryParamByItemId(itemId);
ItemInfo itemInfo = new ItemInfo();
itemInfo.setItem(item);
itemInfo.setCategoryList(categoryList);
itemInfo.setItemSkusList(itemSkusList);
itemInfo.setParamList(paramList);
itemInfo.setItemDesc(itemDesc);
return itemInfo;
......@@ -102,7 +107,15 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
count += entity.getSkuCount();
orederNum++;
}
//商品参数
List<TbCfItemParamEntity> paramsterList = itemSkus.getParamster();
for (TbCfItemParamEntity param : paramsterList) {
param.setId(IdUtil.createIdbyUUID());
param.setCreateTime(new Date());
param.setUpdateTime(new Date());
param.setItemId(itemId);
tbCfItemParamDao.save(param);
}
//商品主体信息
TbCfStationItemEntity tbCfStationItem = new TbCfStationItemEntity();
tbCfStationItem.setItemId(itemId);
......@@ -206,7 +219,17 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
count += entity.getSkuCount();
orederNum++;
}
//先删除之前的商品参数
tbCfItemParamDao.deleteByItemId(itemId);
//商品参数
List<TbCfItemParamEntity> paramsterList = itemSkus.getParamster();
for (TbCfItemParamEntity param : paramsterList) {
param.setId(IdUtil.createIdbyUUID());
param.setCreateTime(new Date());
param.setUpdateTime(new Date());
param.setItemId(itemId);
tbCfItemParamDao.save(param);
}
/*for (int i = 0; i < itemList.size(); i++) {
TbCfItemSkusEntity skusEntity = tbCfItemSkusDao.queryByOrderNum(i + 1, itemId);
if (skusEntity != null) {
......
......@@ -23,7 +23,17 @@
from tb_cf_item_param
where id = #{id}
</select>
<select id="queryParamByItemId" resultType="com.platform.entity.TbCfItemParamEntity">
select
`id`,
`param_name`,
`param_value`,
`item_id`,
`create_time`,
`update_time`
from tb_cf_item_param
where item_id = #{itemId}
</select>
<select id="queryList" resultType="com.platform.entity.TbCfItemParamEntity">
select
`id`,
......@@ -78,10 +88,10 @@
<update id="update" parameterType="com.platform.entity.TbCfItemParamEntity">
update tb_cf_item_param
<set>
<if test="paramName != null">`param_name` = #{paramName}, </if>
<if test="paramValue != null">`param_value` = #{paramValue}, </if>
<if test="itemId != null">`item_id` = #{itemId}, </if>
<if test="createTime != null">`create_time` = #{createTime}, </if>
<if test="paramName != null">`param_name` = #{paramName},</if>
<if test="paramValue != null">`param_value` = #{paramValue},</if>
<if test="itemId != null">`item_id` = #{itemId},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
......@@ -91,6 +101,10 @@
delete from tb_cf_item_param where id = #{value}
</delete>
<delete id="deleteByItemId">
delete from tb_cf_item_param where item_id = #{itemId}
</delete>
<delete id="deleteBatch">
delete from tb_cf_item_param where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
......
......@@ -78,99 +78,94 @@ let vm = new Vue({
isSelectedArr: [], //选中标签的数组
//2020年4月9日
showAttributeImg:false, //显示属性图片模态框
AttributeImgArr:[],
skuListsIndex:null,//sku选中索引
disabledChangeAttribute:false,//禁止改变商品属性
showAttributeImg: false, //显示属性图片模态框
AttributeImgArr: [],
skuListsIndex: null,//sku选中索引
disabledChangeAttribute: false,//禁止改变商品属性
showBatch:false,//显示批量操作模态框
selectBtnArr:[
{isSelected:false,title:'全选'},
{isSelected:false,title:'反选'},
{isSelected:false,title:'取消选择'}
showBatch: false,//显示批量操作模态框
selectBtnArr: [
{isSelected: false, title: '全选'},
{isSelected: false, title: '反选'},
{isSelected: false, title: '取消选择'}
],
allAttributes:[],//所有具体属性
batchAmount:0,
batchCount:0,
allAttributes: [],//所有具体属性
batchAmount: 0,
batchCount: 0,
//2020年5月20日 商品参数
paramster:[
{
paramName:'shell fabric', //面料
paramValue:'dacron' //涤纶
}
]
paramster: []
},
methods: {
//预览
preview(e){
window.open(`https://www.afrieshop.com/product_detail?pid=${e}&from=backstage management system&from_fullPath=${window.location.herf}`,'_blank');
preview(e) {
window.open(`https://www.afrieshop.com/product_detail?pid=${e}&from=backstage management system&from_fullPath=${window.location.herf}`, '_blank');
},
cancelSelectImg(){
this.prevItem[this.skuListsIndex].skuImg=null;
cancelSelectImg() {
this.prevItem[this.skuListsIndex].skuImg = null;
this.showAttributeImg = false;
},
changeBatch(e,flag){
if(flag==='amount'){
this.batchAmount=e.target.value;
}else{
this.batchCount=e.target.value;
changeBatch(e, flag) {
if (flag === 'amount') {
this.batchAmount = e.target.value;
} else {
this.batchCount = e.target.value;
}
},
//批量操作
saveBatchData(){
saveBatchData() {
let activeImgPath = '';
this.AttributeImgArr.map( item => {
item.isSelected?activeImgPath=item.img_path:null;
this.AttributeImgArr.map(item => {
item.isSelected ? activeImgPath = item.img_path : null;
});
this.allAttributes.forEach( item => {
if(item.isSelected){
this.allAttributes.forEach(item => {
if (item.isSelected) {
item.amount = this.batchAmount;
item.count = this.batchCount;
item.skuImg = activeImgPath;
return false;
}
})
this.prevItem.map( item => item.isSelected =false);
this.prevItem.map( item => {
this.allAttributes.map( _item => {
if(_item.isSelected&&item.skuDesc.includes(_item.text)){
this.prevItem.map(item => item.isSelected = false);
this.prevItem.map(item => {
this.allAttributes.map(_item => {
if (_item.isSelected && item.skuDesc.includes(_item.text)) {
item.isSelected = true;
}
})
})
this.prevItem.map( (item,index) => {
if(item.isSelected){
this.prevItem.map((item, index) => {
if (item.isSelected) {
item.skuImg = activeImgPath;
item.skuPrice = this.batchAmount;
item.skuCount = this.batchCount;
}
})
this.prevItem.map( item => delete item.isSelected);
this.prevItem.map(item => delete item.isSelected);
this.showBatch = false;
},
//批处理图片选择
BatchSelectImg(item,index){
this.AttributeImgArr.map( (_item,_index) => index!==_index?_item.isSelected = false:null);
BatchSelectImg(item, index) {
this.AttributeImgArr.map((_item, _index) => index !== _index ? _item.isSelected = false : null);
this.AttributeImgArr[index].isSelected = !this.AttributeImgArr[index].isSelected;
},
//批量处理单选属性
selectAttr(e,index){
selectAttr(e, index) {
this.allAttributes[index].isSelected = !this.allAttributes[index].isSelected;
},
//显示批量处理模态框
showBatchModel(){
showBatchModel() {
this.$refs.amount.$el.children[1].value = this.batchAmount = null;
this.$refs.count.$el.children[1].value = this.batchCount = null;
this.showBatch = true;
//获取所有具体属性
this.allAttributes = [];
this.attrItem[0].categoryDesc.split(',').map( _item => this.allAttributes.push({
text:_item,
isSelected:false,
amount:null,
count:null,
skuImg:null
this.attrItem[0].categoryDesc.split(',').map(_item => this.allAttributes.push({
text: _item,
isSelected: false,
amount: null,
count: null,
skuImg: null
}));
// this.attrItem.map( item => item.categoryDesc.split(',').map( _item => this.allAttributes.push({
// text:_item,
......@@ -181,40 +176,40 @@ let vm = new Vue({
// })) );
},
//切换批量选择按钮
changeSelectBtnArr(item,index){
this.selectBtnArr.map( (_item,_index) => _index!==index?_item.isSelected = false:null);
changeSelectBtnArr(item, index) {
this.selectBtnArr.map((_item, _index) => _index !== index ? _item.isSelected = false : null);
this.selectBtnArr[index].isSelected = !this.selectBtnArr[index].isSelected;
if(index===0){
this.allAttributes.map( item => item.isSelected = true);
}else if(index===1){
this.allAttributes.map( item => item.isSelected = !item.isSelected);
}else{
this.allAttributes.map( item => item.isSelected = false);
if (index === 0) {
this.allAttributes.map(item => item.isSelected = true);
} else if (index === 1) {
this.allAttributes.map(item => item.isSelected = !item.isSelected);
} else {
this.allAttributes.map(item => item.isSelected = false);
}
},
selectImg(url){
selectImg(url) {
// console.log(this.prevItem[this.skuListsIndex]);
this.prevItem[this.skuListsIndex].skuImg = url;
this.$forceUpdate();
this.showAttributeImg = false;
},
//单条sku选择图片
HandleSelectAttributeImg(e,i){
if(!this.disabledChangeAttribute){
HandleSelectAttributeImg(e, i) {
if (!this.disabledChangeAttribute) {
window.alert('请先确认商品规格后再操作。(确认商品规格后将不可再次编辑规格数据)');
}else{
} else {
this.showAttributeImg = true;
this.skuListsIndex = i;
}
},
//删除属性图片
removeAttributeImg(e,i,notShowMessage){
this.$delete(this.AttributeImgArr,i);
this.delAttributeImg(e,notShowMessage);
removeAttributeImg(e, i, notShowMessage) {
this.$delete(this.AttributeImgArr, i);
this.delAttributeImg(e, notShowMessage);
},
//删除图片
delAttributeImg(url,notShowMessage){
delAttributeImg(url, notShowMessage) {
Ajax.request({
url: "../api/upload/delFile?url=" + url,
async: false,
......@@ -222,21 +217,21 @@ let vm = new Vue({
contentType: "application/json",
successCallback: function (resultData) {
// console.log(resultData);
!notShowMessage?iview.Message.success(resultData.success):null;
!notShowMessage ? iview.Message.success(resultData.success) : null;
}
});
},
//处理属性图片上传成功回调
handleAttributeImgSuccess(e){
handleAttributeImgSuccess(e) {
this.AttributeImgArr.push({
img_path:e,
isSelected:false
img_path: e,
isSelected: false
});
console.log(e);
// this.delAttributeImg(e);
},
//控制属性图片模块框
isShowAttributeContainer(Bool){
isShowAttributeContainer(Bool) {
this.showAttributeImg = Bool;
},
//获取二级分类
......@@ -279,7 +274,14 @@ let vm = new Vue({
vm.reload();
},
add: function () {
this.AttributeImgArr.length=0;
this.AttributeImgArr.length = 0;
this.paramster.length=0;
this.paramster.push({
paramName: '',
paramValue: ''
});
vm.showList = false;
vm.title = "新增";
vm.tbCfStationItem = {};
......@@ -301,14 +303,19 @@ let vm = new Vue({
vm.getInfo(itemId);
},
saveOrUpdate: function (event) {
if(vm.prevItem.length===0){
if (vm.prevItem.length === 0) {
console.log(123);
alert('请编辑完属性后再保存');
}else{
} else {
let resArr = [];
this.prevItem.forEach(item => {
resArr.push(item)
})
let paramArr = [];
this.paramster.forEach(item => {
paramArr.push(item)
})
vm.tbCfStationItem.paramster = this.paramster;
let label = null;
vm.tbCfStationItem.itemLabel = this.isSelectedArr.map(item => item.id).join(',');
vm.tbCfStationItem.prevItem = resArr
......@@ -318,7 +325,7 @@ let vm = new Vue({
vm.tbCfStationItem.itemImg = vm.uploadList.map(res => res).join(';');
vm.tbCfStationItem.itemDesc = encodeURI(UE.getEditor('itemDesc').getContent()); // 富文本取值
vm.tbCfStationItem.itemDesc = vm.tbCfStationItem.itemDesc.replace(/&nbsp;/g, " ");
vm.tbCfStationItem.skuImgs = vm.AttributeImgArr.map( item => item.img_path).join(';');
vm.tbCfStationItem.skuImgs = vm.AttributeImgArr.map(item => item.img_path).join(';');
let url = vm.tbCfStationItem.itemId == null ? "../tbcfstationitem/save" : "../tbcfstationitem/update";
Ajax.request({
url: url,
......@@ -384,6 +391,14 @@ let vm = new Vue({
async: true,
successCallback: function (r) {
r.code === 0 && (() => {
_this.paramster = []
//回显参数
r.tbCfStationItem.paramList.map(item => {
_this.paramster.push({
paramName: item.paramName,
paramValue: item.paramValue
})
})
_this.attrItem = []
// let _option = JSON.parse(localStorage.getItem('option'))
//回显属性
......@@ -398,20 +413,20 @@ let vm = new Vue({
_this.tmdSkudata = r.tbCfStationItem.itemSkusList
r.tbCfStationItem.itemSkusList.map(item => {
_this.prevItem.push({
skuImg:null,
skuImg: null,
skuName: item.skuName,
skuDesc: item.skuDesc,
skuPrice: item.skuPrice,
skuCount: item.skuCount,
skuImg:item.skuImg,
skuCode:item.skuCode
skuImg: item.skuImg,
skuCode: item.skuCode
})
})
if(r.tbCfStationItem.item.skuImgs){
r.tbCfStationItem.item.skuImgs.split(';').map( item => {
if (r.tbCfStationItem.item.skuImgs) {
r.tbCfStationItem.item.skuImgs.split(';').map(item => {
vm.AttributeImgArr.push({
img_path: item,
isSelected:false
isSelected: false
})
})
}
......@@ -462,15 +477,15 @@ let vm = new Vue({
});
},
back(){
back() {
//清除未保存商品的图片
if(!vm.tbCfStationItem.itemId){
this.AttributeImgArr.map( (item,index) => {
this.delAttributeImg(item.img_path,true);
if (!vm.tbCfStationItem.itemId) {
this.AttributeImgArr.map((item, index) => {
this.delAttributeImg(item.img_path, true);
})
setTimeout(()=>{
setTimeout(() => {
this.AttributeImgArr = [];
},0)
}, 0)
}
this.reload();
},
......@@ -543,7 +558,7 @@ let vm = new Vue({
/** ******************************************************************************************** */
vhandleSuccess(response, file, fileList) {
// "http://diaosaas-prod.oss-cn-shenzhen.aliyuncs.com/education/155728894307110106.jpg"
console.log('shangchuan',response)
console.log('shangchuan', response)
vm.uploadList.push(response);
$("#itemImg").show();
},
......@@ -699,7 +714,7 @@ let vm = new Vue({
product(skuArr).forEach((item, index) => {
this.prevItem.push({
skuImg:null,
skuImg: null,
skuName: skuName,
skuDesc: item,
skuPrice: this.default_price,
......@@ -805,13 +820,13 @@ let vm = new Vue({
* 2020年5月20日
* 新增产品参数
*/
addProductParams(){
addProductParams() {
this.paramster.push({
paramName:null,
paramValue:null
paramName: null,
paramValue: null
})
},
delParamster(i){
delParamster(i) {
let arr = new Array();
this.paramster.map((item, index) => {
if (i !== index) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论