From 4dbed1ab30acc412ba6fb28fc97e03e526b81c21 Mon Sep 17 00:00:00 2001 From: DongZeLiang <2746733890@qq.com> Date: Fri, 8 Mar 2024 15:55:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E8=A7=84=E6=A0=BCSKU?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/product/info/index.vue | 50 +++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/views/product/info/index.vue b/src/views/product/info/index.vue index 78333ea..dc59520 100644 --- a/src/views/product/info/index.vue +++ b/src/views/product/info/index.vue @@ -411,7 +411,7 @@ export default { templateAttributeList: [], attributeList: [] }, - titleList: [ + templateTitleList: [ { "label":"商品库存", "prop":"stock" @@ -423,13 +423,8 @@ export default { "prop":"image" } ], - skuList: [ - { - "image": "123", - "price": 85.62, - "stock": 236 - } - ] + titleList: [], + skuList: [] }; }, watch: { @@ -467,16 +462,51 @@ export default { }, methods: { changeRule(ruleId){ + this.titleList = [] let ruleInfo = this.ruleList.find(ruleInfo => ruleInfo.id === ruleId); const {ruleAttrList} = ruleInfo; + let skuTotal = 1; for (let ruleAttrListKey in ruleAttrList) { let ruleAttrInfo = ruleAttrList[ruleAttrListKey]; this.titleList.push({ "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(){ addAttribute({"code": this.customAttributeForm.code, "name": this.customAttributeForm.name}).then(response => {