spu 修改页面展示

This commit is contained in:
franky 2022-07-06 17:06:19 +08:00
parent ed56c71ba1
commit f3c83488a3

View File

@ -244,7 +244,8 @@
<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 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>
@ -319,6 +320,7 @@
propertyId: '',
selectValues: [],
selectValueIds: [],
selectObect:[],
},
skuTags: [],
propName: {
@ -388,7 +390,8 @@
created() {
this.getList();
this.getPropertyPageList();
this.getListCategory();
},
methods: {
getTableSpecData() {
@ -434,22 +437,40 @@
let skus = this.unUseTags.map(function (item, index) {
return item.name
});
console.log("skus=="+JSON.stringify(skus))
let index = skus.indexOf(this.addTagInput.name);
console.log("index=="+index)
console.log("skus[index].id=="+this.unUseTags[index].id)
console.log("this.unUseTags[index].propertyValueList=="+JSON.stringify(this.unUseTags[index].propertyValueList))
this.addTagInput.propertyId = this.unUseTags[index].id;
for (let i = 0; i < this.addTagInput.selectValues.length; i++) {
for (let j = 0; j < this.unUseTags[index].propertyValueList.length; j++) {
if (this.addTagInput.selectValues[i] === this.unUseTags[index].propertyValueList[j].name) {
this.addTagInput.selectValueIds.push(this.unUseTags[index].propertyValueList[j].id)
this.addTagInput.selectObect.push({
id:this.unUseTags[index].propertyValueList[j].id,
name:this.unUseTags[index].propertyValueList[j].name,
})
}
}
}
let addTagInput = JSON.parse(JSON.stringify(this.addTagInput))
console.log("addTagInput=="+JSON.stringify(addTagInput))
this.skuTags.push(addTagInput);
// if (this.skuTags.length > 1) {
this.skuTags = this.skuTags.sort((a, b) => a.propertyId - b.propertyId);
this.skuTags.forEach(function (item,index) {
item.selectObect = item.selectObect.sort((a, b) => a.id - b.id)
})
for (let i = 0; i <this.skuTags.length ; i++) {
let selectValueIds=[];
let selectValues=[];
for (let j = 0; j < this.skuTags[i].selectObect.length; j++) {
selectValueIds.push(this.skuTags[i].selectObect[j].id);
selectValues.push(this.skuTags[i].selectObect[j].name);
}
this.skuTags[i].selectValues = selectValues;
this.skuTags[i].selectValueIds = selectValueIds;
}
this.unUseTags.splice(index, 1);
this.isShowTagInput = false;
this.getTable();
@ -467,19 +488,19 @@
propertyIds.push(skuTags[i].propertyId);
propertyNames.push(skuTags[i].name);
}
let skuAll = sku1s.reduce((x, y) => {
let arr = [];
x.forEach(m => y.forEach(y => arr.push(m.concat([y]))))
return arr;
}, [[]])
console.log(skuAll);
let skuIdAll = skuIds.reduce((x, y) => {
let arr = [];
x.forEach(m => y.forEach(y => arr.push(m.concat([y]))))
return arr;
}, [[]])
console.log(skuIdAll);
for (let i = 0; i < skuAll.length; i++) {
let han = {
propertyNames: propertyNames,
@ -508,7 +529,6 @@
}
})
console.log("this.skus=="+JSON.stringify(this.form.skus))
},
hideTagInput() {
this.isShowTagInput = false;
@ -517,6 +537,7 @@
propertyId: '',
selectValues: [],
selectValueIds: [],
selectObect: [],
};
},
shopTagInput() {
@ -529,6 +550,7 @@
propertyId: '',
selectValues: [],
selectValueIds: [],
selectObect: [],
};
},
//
@ -558,7 +580,6 @@
return item
})
this.allhistoryTags = JSON.parse(JSON.stringify(this.unUseTags));
console.log(this.propertyPageList)
});
},
/** 查询分类 */
@ -625,7 +646,6 @@
this.reset();
this.open = true;
this.title = "添加商品spu";
this.getListCategory();
this.getPropertyPageList();
},
/** 修改按钮操作 */
@ -633,7 +653,6 @@
this.reset();
const id = row.id;
getSpu(id).then(response => {
console.log(">>>>>> response.data:" + JSON.stringify(response.data))
let dataSpu = response.data;
this.form = {
id: dataSpu.id,
@ -649,17 +668,99 @@
quantity: dataSpu.quantity,
status: dataSpu.status,
isShowTagInput: undefined,
skus:dataSpu.skus
skus: [],
skusList: dataSpu.skus,
productPropertyViews: dataSpu.productPropertyViews,
// skus:dataSpu.productSkuRespVOS,
};
this.getDataHandle();
this.open = true;
this.title = "修改商品spu";
});
},
getDataHandle() {
let that = this;
let productPropertyViews = JSON.parse(JSON.stringify(this.form.productPropertyViews));
productPropertyViews = productPropertyViews.sort((a, b) => a.propertyId - b.propertyId);
productPropertyViews.forEach(item => {
item.propertyValues = item.propertyValues.sort((a, b) => a.v1 - b.v1);
})
let skuIds = [];
for (let i = 0; i < productPropertyViews.length; i++) {
let han = {
name: productPropertyViews[i].name,
propertyId: productPropertyViews[i].propertyId,
selectValues: [],
selectValueIds: [],
}
for (let j = 0; j < productPropertyViews[i].propertyValues.length; j++) {
han.selectValues.push(productPropertyViews[i].propertyValues[j].v2);
han.selectValueIds.push(productPropertyViews[i].propertyValues[j].v1);
}
skuIds.push(han)
}
this.skuTags = skuIds;
this.unUseTags = this.allhistoryTags.filter((v) =>
skuIds.every((val) => val.name != v.name)
)
this.getHandleTable();
},
getHandleTable() {
this.form.skus = [];
let skuTags = JSON.parse(JSON.stringify(this.skuTags));
let sku1s = [];
let skuIds = [];
let propertyIds = [];
let propertyNames = [];
for (let i = 0; i < skuTags.length; i++) {
sku1s.push(skuTags[i].selectValues);
skuIds.push(skuTags[i].selectValueIds);
propertyIds.push(skuTags[i].propertyId);
propertyNames.push(skuTags[i].name);
}
let skuAll = sku1s.reduce((x, y) => {
let arr = [];
x.forEach(m => y.forEach(y => arr.push(m.concat([y]))))
return arr;
}, [[]])
let skuIdAll = skuIds.reduce((x, y) => {
let arr = [];
x.forEach(m => y.forEach(y => arr.push(m.concat([y]))))
return arr;
}, [[]])
for (let i = 0; i < skuAll.length; i++) {
let han = {
propertyNames: propertyNames,
propertyIds: propertyIds,
propertyChildNames: skuAll[i],
propertyChildIds: skuIdAll[i],
properties: this.form.skusList[i].properties,
picUrl: this.form.skusList[i].picUrl,
costPrice: this.form.skusList[i].costPrice,
originalPrice: this.form.skusList[i].originalPrice,
spuId: this.form.skusList[i].spuId,
prodName: this.form.skusList[i].prodName,
price: this.form.skusList[i].price,
barCode: this.form.skusList[i].barCode,
status: this.form.skusList[i].status,
}
this.form.skus.push(han);
}
this.form.skus.forEach(x => {
x.properties = [];
for (let i = 0; i < x.propertyIds.length; i++) {
x.properties.push({
propertyId: x.propertyIds[i],
valueId: x.propertyChildIds[i]
})
}
})
},
/** 提交按钮 */
submitForm() {
console.log(this.form.picUrls.split(','));
this.$refs["form"].validate(valid => {
if (!valid) {