From ec51286a1e3e33e2dcec1f142097198186cf6aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Sat, 6 Sep 2025 14:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=9B=E5=85=A5=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E7=9A=84=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E8=A7=84=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shop/goods/index.vue | 77 ++++++++++++++++++++--------------- packages/shop/index/index.vue | 7 ++-- 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/packages/shop/goods/index.vue b/packages/shop/goods/index.vue index 3907f099..54e3d780 100644 --- a/packages/shop/goods/index.vue +++ b/packages/shop/goods/index.vue @@ -317,34 +317,35 @@ import { } from "../../../utils"; export default { data() { - return { - picUrl, - top: "", - localHeight: "", - carNum: "", - prevCarNum: "", - currentNum: "0", //当前商品的数量 - type: "error", - boxshadow1: false, - boxshadow2: false, - id: "184", - info: "", - currentIndex: "1", //当前轮播图 + return { + picUrl, + top: "", + localHeight: "", + carNum: "", + prevCarNum: "", + currentNum: "0", //当前商品的数量 + type: "error", + boxshadow1: false, + boxshadow2: false, + id: "184", + info: "", + currentIndex: "1", //当前轮播图 - currentGG: "", //当前选中规格 - currentGGIndex: "", //当前规格index + currentGG: "", //当前选中规格 + currentGGIndex: "", //当前规格index - carOrderList: [], - // 新增评论数据 - showReviewPopup: false, - comments: [], - show: false, - showSize: false, + carOrderList: [], + // 新增评论数据 + showReviewPopup: false, + comments: [], + show: false, + showSize: false, - changeImg: "", - changeName: "", - changePrice: "", - }; + changeImg: "", + changeName: "", + changePrice: "", + selectedGoods: null, // 保存传入的商品规格信息 + }; }, methods: { changeIndex(e) { @@ -454,10 +455,21 @@ export default { } this.info = res; console.log("this.info", this.info.commodity_goods_info_list); - // {{info.commodity_goods_info_list[currentGGIndex].cart_count.count}} - this.currentGG = res.commodity_goods_info_list[0]; + + // 检查是否有传入的选中商品信息,如果有则设置为默认选中 + let selectedIndex = 0; + if (this.selectedGoods) { + for (let i = 0; i < res.commodity_goods_info_list.length; i++) { + if (res.commodity_goods_info_list[i].id === this.selectedGoods.id) { + selectedIndex = i; + break; + } + } + } + + this.currentGG = res.commodity_goods_info_list[selectedIndex]; console.log("this.currentGG", this.currentGG); - this.currentGGIndex = 0; + this.currentGGIndex = selectedIndex; this.changeImg = picUrl + this.currentGG.commodity_pic[0] this.changeName = this.currentGG.goods_alias @@ -480,7 +492,6 @@ export default { // 切换规格 changeGG(item, index) { - console.log("🚀 ~ changeGG ~ item:", item); this.currentGG = item; this.currentGGIndex = index; if (this.currentGG.cart_count) { @@ -622,15 +633,15 @@ export default { })); }); } - }, - onLoad(options) { - console.log(JSON.parse(decodeURIComponent(options.item))); + },onLoad(options) { const itemObj = JSON.parse(decodeURIComponent(options.item)); const meun = menuButtonInfo(); this.top = meun.top; this.localHeight = meun.height; - this.id = itemObj.id; + + this.id = itemObj.commodity_id ? itemObj.commodity_id : itemObj.id; + this.selectedGoods = itemObj; // 保存传入的完整商品信息 }, onReachBottom() { }, onShow() { diff --git a/packages/shop/index/index.vue b/packages/shop/index/index.vue index 9d6af476..3dbeca47 100644 --- a/packages/shop/index/index.vue +++ b/packages/shop/index/index.vue @@ -152,7 +152,7 @@ - + 当日达 @@ -362,9 +362,8 @@ export default { NavgateTo("../search/index"); }, //商品详情页 - goods(e) { - NavgateTo(`../goods/index?item=${JSON.stringify(e)}`); - // NavgateTo("../goods/index"); + goods(ite,items) { + NavgateTo(`../goods/index?item=${JSON.stringify(ite)}`); }, // 购物车