From cdbbdbca885d75eac8f94da9f095b975dd1660e8 Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Thu, 30 Apr 2026 10:30:52 +0800 Subject: [PATCH] 1 --- package1/group/groupBuyList.vue | 2 +- package1/group/groupBuySingle.vue | 66 ++++++++++++------ package1/myCenter/addGoods.vue | 109 ++++++++++++++++++++---------- 3 files changed, 118 insertions(+), 59 deletions(-) diff --git a/package1/group/groupBuyList.vue b/package1/group/groupBuyList.vue index e45b9f4..2736e47 100644 --- a/package1/group/groupBuyList.vue +++ b/package1/group/groupBuyList.vue @@ -109,7 +109,7 @@ + v-for="(item1,index1) in item.products" :key="index1" @tap="goDetail('shop',item)"> diff --git a/package1/group/groupBuySingle.vue b/package1/group/groupBuySingle.vue index ccb725f..110f7fe 100644 --- a/package1/group/groupBuySingle.vue +++ b/package1/group/groupBuySingle.vue @@ -279,10 +279,10 @@ - 选{{spec.name}} + 选{{spec.name}}(可选{{spec.canbuy}}个) - {{option}} @@ -604,10 +604,6 @@ categoryName: '推荐', id: 'tuijian', checked: true - },{ - categoryName: '必点', - id: 'bidian', - checked: false }], shopRecommend:[], availableCoupons: [], @@ -802,7 +798,8 @@ that.productItem = [...that.productItem, ...res.result.records]; } let hasTuijian = false - let bidian = false + let tuijianList = [] + let putongList = [] for(let i = 0;i 0) { + let canbuy = attrs[key].canbuy || 1; // 历史数据没有canbuy字段默认为1 this.parsedSpecs.push({ name: key, options: attrs[key].title, - selected: attrs[key].title[0] // Default select first + canbuy: canbuy, + selected: [attrs[key].title[0]] // 默认选中第一个 }); } } @@ -1040,10 +1036,12 @@ .attributeList; for (let key in attrs) { if (attrs[key] && attrs[key].title && attrs[key].title.length > 0) { + let canbuy = attrs[key].canbuy || 1; // 历史数据没有canbuy字段默认为1 this.parsedSpecs.push({ name: key, options: attrs[key].title, - selected: attrs[key].title[0] // Default select first + canbuy: canbuy, + selected: [attrs[key].title[0]] // 默认选中第一个 }); } } @@ -1132,7 +1130,29 @@ } }, selectSpec(sIndex, option) { - this.parsedSpecs[sIndex].selected = option; + let spec = this.parsedSpecs[sIndex]; + let idx = spec.selected.indexOf(option); + if (idx !== -1) { + // 已选中,取消选中(但至少保留一个选中) + if (spec.selected.length > 1) { + spec.selected.splice(idx, 1); + } + } else { + // 未选中 + if (spec.selected.length < spec.canbuy) { + // 还没达到上限,直接添加 + spec.selected.push(option); + } else if (spec.canbuy === 1) { + // 只能选1个,替换 + spec.selected = [option]; + } else { + // 已达到上限,提示 + uni.showToast({ + title: spec.name + '最多选' + spec.canbuy + '个', + icon: 'none' + }); + } + } this.$forceUpdate(); }, selectGroupRule(rule) { @@ -1148,7 +1168,7 @@ submitAddToCart() { let specChoices = {}; for (let spec of this.parsedSpecs) { - specChoices[spec.name] = spec.selected; + specChoices[spec.name] = spec.canbuy === 1 ? spec.selected[0] : spec.selected; } this.addToCart(this.currentItem, specChoices); uni.showToast({ @@ -1160,7 +1180,7 @@ submitPintuan(isFaceToFace) { let specChoices = {}; for (let spec of this.parsedSpecs) { - specChoices[spec.name] = spec.selected; + specChoices[spec.name] = spec.canbuy === 1 ? spec.selected[0] : spec.selected; } let packageFee = parseFloat(this.currentItem.lunchBox || 0); @@ -1311,7 +1331,11 @@ if (!specs) return ''; let arr = []; for (let k in specs) { - arr.push(specs[k]); + if (Array.isArray(specs[k])) { + arr.push(specs[k].join('+')); + } else { + arr.push(specs[k]); + } } return arr.join(','); }, diff --git a/package1/myCenter/addGoods.vue b/package1/myCenter/addGoods.vue index f5bd601..111644c 100644 --- a/package1/myCenter/addGoods.vue +++ b/package1/myCenter/addGoods.vue @@ -65,8 +65,8 @@ - - {{value[0]}}: + + {{value[0]}}(可选{{value[1].canbuy || 1}}个): {{item}}、 @@ -135,11 +135,13 @@ {{item.title}} + + + + + - - - @@ -155,6 +157,8 @@ dataList: {}, modalType:0, maxSelect:1, + currentCanbuy:1, + canbuyMap:{}, categoryData:[], categoryIndex: 0, modalclassType:'', @@ -430,23 +434,32 @@ }, guigeSubmit(){ if(this.modalclassType == 'shuxing'){ + // 保存当前分类的canbuy值 + if(this.typeToAttrName){ + this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1 + } for(let i=0;i { + value.canbuy = value.canbuy || 1 + this.canbuyMap[key] = value.canbuy for(let i = 0;i {}); @@ -636,40 +680,31 @@ }, false, true).then((res) => { if(res.code == 200){ this.categorySonData = res.result.content + // 先给所有子项初始化checked为false,确保Vue响应性 + console.log("111111",this.specValueArr) + console.log("22222",this.attrValueArr) + for (var i = 0; i < this.categorySonData.length; i++) { + this.$set(this.categorySonData[i], 'checked', false) + } if(this.modalclassType == 'shuxing'){ for (var i = 0; i < this.categorySonData.length; i++) { - if(this.attrValueArr.length>0){ - let index1 = false - for (var m = 0; m < this.attrValueArr.length; m++) { - if(this.attrValueArr[m].title == this.categorySonData[i].title && this.attrValueArr[m].parentName == this.typeToAttrName){ - index1 = true - this.categorySonData[i].checked = true - } + for (var m = 0; m < this.attrValueArr.length; m++) { + if(this.attrValueArr[m].title == this.categorySonData[i].title && this.attrValueArr[m].parentName == this.typeToAttrName){ + this.$set(this.categorySonData[i], 'checked', true) } - if(index1){ - this.categorySonData[i].checked = true - } - }else{ - this.categorySonData[i].checked = false } } }else{ //guige - - for (var i = 0; i < this.categorySonData.length; i++) { - if(this.specValueArr.length>0){ - for (var m = 0; m < this.specValueArr.length; m++) { - if(this.specValueArr[m].id == this.categorySonData[i].id){ - this.categorySonData[i].checked = true - } + for (var m = 0; m < this.specValueArr.length; m++) { + if(this.specValueArr[m].id == this.categorySonData[i].id){ + this.$set(this.categorySonData[i], 'checked', true) } - }else{ - this.categorySonData[i].checked = false } } } - + this.$forceUpdate() } }).catch(() => {}); },