商品规格SKU生成

dev
DongZeLiang 2024-03-08 15:55:38 +08:00
parent 761682671e
commit 4dbed1ab30
1 changed files with 40 additions and 10 deletions

View File

@ -411,7 +411,7 @@ export default {
templateAttributeList: [], templateAttributeList: [],
attributeList: [] attributeList: []
}, },
titleList: [ templateTitleList: [
{ {
"label":"商品库存", "label":"商品库存",
"prop":"stock" "prop":"stock"
@ -423,13 +423,8 @@ export default {
"prop":"image" "prop":"image"
} }
], ],
skuList: [ titleList: [],
{ skuList: []
"image": "123",
"price": 85.62,
"stock": 236
}
]
}; };
}, },
watch: { watch: {
@ -467,16 +462,51 @@ export default {
}, },
methods: { methods: {
changeRule(ruleId){ changeRule(ruleId){
this.titleList = []
let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === ruleId); let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === ruleId);
const {ruleAttrList} = ruleInfo; const {ruleAttrList} = ruleInfo;
let skuTotal = 1;
for (let ruleAttrListKey in ruleAttrList) { for (let ruleAttrListKey in ruleAttrList) {
let ruleAttrInfo = ruleAttrList[ruleAttrListKey]; let ruleAttrInfo = ruleAttrList[ruleAttrListKey];
this.titleList.push({ this.titleList.push({
"label":ruleAttrInfo.name, "label":ruleAttrInfo.name,
"prop":"stock" "prop":"prop"+ruleAttrListKey
}) })
skuTotal = skuTotal * ruleAttrInfo.valueList.length;
}
this.titleList.push(...this.templateTitleList) ;
console.log(this.titleList);
this.skuList = [];
for (let i = 0; i < skuTotal; i++) {
this.skuList.push(
{
"image": "123",
"price": 85.62,
"stock": 236
}
);
}
// currentIndex
for (let currentIndex in ruleAttrList) {
let ruleAttrInfo = ruleAttrList[currentIndex];
//
let continuousSize = 1, forSize = 1;
for (let continuousIndex = parseInt(currentIndex) + 1 ; continuousIndex < ruleAttrList.length ; continuousIndex++ ){
continuousSize = continuousSize * ruleAttrList[continuousIndex].valueList.length;
}
for (let forIndex = parseInt(currentIndex) - 1; forIndex >= 0; forIndex--){
forSize = forSize * ruleAttrList[forIndex].valueList.length
}
console.log(`${ruleAttrInfo.name} 规格 连续出现次数:${continuousSize} 循环出现次数:${forSize}`)
for (let forIndex = 0; forIndex < forSize; forIndex++) {
const {valueList} = ruleAttrInfo;
valueList.forEach(value => {
for (let continuousIndex = 0; continuousIndex < continuousSize; continuousIndex++) {
this.skuList
}
})
}
} }
console.log(ruleInfo);
}, },
saveCustomAttribute(){ saveCustomAttribute(){
addAttribute({"code": this.customAttributeForm.code, "name": this.customAttributeForm.name}).then(response => { addAttribute({"code": this.customAttributeForm.code, "name": this.customAttributeForm.name}).then(response => {