diff --git a/src/views/product/productInfo/index.vue b/src/views/product/productInfo/index.vue index 2bdebef..f11a393 100644 --- a/src/views/product/productInfo/index.vue +++ b/src/views/product/productInfo/index.vue @@ -70,7 +70,7 @@ - + @@ -202,7 +202,7 @@
- + + + + + + + + + + + + + + + + 一键添加 + 一键清空 + + + + + + + + + +
@@ -240,9 +284,9 @@
属性组名称【{{ templateAttributeGroup.groupName }}】
-
- - +
+ + @@ -255,7 +299,7 @@ 商品属性 - + @@ -356,6 +400,26 @@ export default { dicts: ['sys_normal_disable'], data() { return { + oneSettingValue: { + "image": null, + "stock": null, + "price": null + }, + templateTitleList: [ + { + "label": "规格图片", + "prop": "image" + }, + { + "label": "商品库存", + "prop": "stock" + }, { + "label": "商品价格", + "prop": "price" + } + ], + skuList: [], + titleList: [], attributeIdCheckedList: [], attributeCheckedList: [], customAttributeForm: {}, @@ -377,7 +441,7 @@ export default { }, ruleAddFormStatus: false, addRulePropertyValue: null, - active: 1, + active: 2, // 遮罩层 loading: true, // 选中数组 @@ -449,11 +513,11 @@ export default { categoryOptionValue: { handler(value) { if (value != null && value !== undefined && value.length > 0) { - this.form.mainType = value[0]; + this.form.mianType = value[0]; this.form.parentType = value[1]; this.form.type = value[2]; } else { - this.form.mainType = null + this.form.mianType = null this.form.parentType = null this.form.type = null } @@ -481,15 +545,79 @@ export default { this.CategoryTree(); }, methods: { + onSubmit() { + this.skuList.forEach(skuInfo => { + console.log(this.oneSettingValue) + skuInfo.image = this.oneSettingValue.image; + skuInfo.stock = this.oneSettingValue.stock; + skuInfo.price = this.oneSettingValue.price; + }) + }, + onClean(){ + this.skuList=[] + }, + 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": "prop" + ruleAttrListKey + }) + skuTotal = skuTotal * ruleAttrInfo.ruleList.length; + } + this.titleList.push(...this.templateTitleList) + this.skuList = [] + for (let i = 0; i < skuTotal; i++) { + this.skuList.push( + { + "image": null, + "price": 0, + "stock": 0 + } + ) + } + + //currentIndex 当前下表 + for (let currentIndex in ruleAttrList) { + let ruleAttrInfo = ruleAttrList[currentIndex]; + //continuousSize 连续出现次数 forSize 循环出现次数 + let continuousSize = 1, forSize = 1; + for (let continuousIndex = parseInt(currentIndex) + 1; continuousIndex < ruleAttrList.length; continuousIndex++) { + continuousSize = continuousSize * ruleAttrList[continuousIndex].ruleList.length + } + for (let forIndex = parseInt(currentIndex) - 1; forIndex >= 0; forIndex--) { + forSize = forSize * ruleAttrList[forIndex].ruleList.length + } + console.log(`${ruleAttrInfo.name} 规格连续出现的次数 :${continuousSize} 循环出现的次数: ${forSize}`) + + let counter = 0; + for (let forIndex = 0; forIndex < forSize; forIndex++) { + const {ruleList} = ruleAttrInfo; + console.log(ruleList) + + ruleList.forEach(value => { + for (let continuousIndex = 0; continuousIndex < continuousSize; continuousIndex++) { + this.skuList[counter++]["prop" + currentIndex] = value; + } + }) + } + } + + + }, handleCheckedCitiesChange() { let attributeId = this.attributeIdCheckedList .find(attributeId => this.attributeCheckedList.map(attributeChecked => attributeChecked.id).indexOf(attributeId) === -1) if (attributeId != undefined) { - let attributeInfo=this.categoryCommonElement.attributeList.find(attributeInfo=>attributeInfo.id===attributeId); + let attributeInfo = this.categoryCommonElement.attributeList.find(attributeInfo => attributeInfo.id === attributeId); this.attributeCheckedList.push(attributeInfo) - }else{ - let attributeChecked =this.attributeCheckedList.find(attributeChecked=>this.attributeIdCheckedList.indexOf(attributeChecked)); - this.attributeCheckedList.splice(this.attributeCheckedList.indexOf(attributeChecked),1); + } else { + let attributeChecked = this.attributeCheckedList.find(attributeChecked => this.attributeIdCheckedList.indexOf(attributeChecked)); + this.attributeCheckedList.splice(this.attributeCheckedList.indexOf(attributeChecked), 1); } }, @@ -501,17 +629,17 @@ export default { name = this.customAttributeForm.name, value = this.customAttributeForm.value; this.categoryCommonElement.attributeList.push({ - "id":attributeId, - "name":name, - "code":code + "id": attributeId, + "name": name, + "code": code }); this.attributeIdCheckedList.push(attributeId) this.attributeCheckedList.push({ - "id":attributeId, - "name":name, - "value":value + "id": attributeId, + "name": name, + "value": value }); - this.customAttributeForm={} + this.customAttributeForm = {} } }) }, @@ -558,7 +686,7 @@ export default { id: null, name: null, introduction: null, - mainType: null, + mianType: null, parentType: null, type: null, image: null, @@ -645,3 +773,10 @@ export default { } }; + +