From e2cf0a471105c2b40de4c0958068da5b3dfcfe6e Mon Sep 17 00:00:00 2001 From: linlihong <747682928@qq.com> Date: Thu, 5 Sep 2024 15:43:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=A2=AB=E5=AD=90=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- page/component/details/details.js | 88 +++++++++++++++-------------- page/component/details/details.wxml | 4 +- page/component/index.js | 2 +- page/component/user/user.js | 4 +- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/page/component/details/details.js b/page/component/details/details.js index b20a7a0..cf497f4 100644 --- a/page/component/details/details.js +++ b/page/component/details/details.js @@ -15,8 +15,8 @@ Page({ goodName: options.goodName, goodPrice: options.goodPrice, goodDetail: options.goodDetail, - goodImage: decodeURIComponent(options.goodImage).split(','), - }; + goodImage: decodeURIComponent(options.goodImage).split(","), + } const specList = [ { specId: 2, @@ -31,87 +31,91 @@ Page({ ] } ]; - this.setData({ goods, specList, viewGood: goods.goodImage[0] }); + this.setData({ goods, specList, viewGood: goods.goodImage[0] }) }, openPopup() { - this.setData({ showPopup: true }); + this.setData({ showPopup: true }) }, handlePopupHide() { - this.setData({ showPopup: false }); + this.setData({ showPopup: false }) }, selectSpec(e) { - const { specid, id, val } = e.currentTarget.dataset; + const { specid, id, val } = e.currentTarget.dataset // 动态更改价格 - let updatedPrice = this.data.goods.goodPrice; + let updatedPrice = this.data.goods.goodPrice if (val === "普通蓬松枕") { - updatedPrice = 220; // 设置为220 + updatedPrice = 220 // 设置为220 } if (val === "压缩高级枕") { - updatedPrice = 240; // 设置为240 + updatedPrice = 240 // 设置为240 } - let specList = this.data.specList.map(spec => { + let specList = this.data.specList.map((spec) => { if (spec.specId === specid) { - spec.specValueList = spec.specValueList.map(item => { - item.isSelected = item.specValueId == id; - return item; - }); + spec.specValueList = spec.specValueList.map((item) => { + item.isSelected = item.specValueId == id + return item + }) } - return spec; - }); + return spec + }) this.setData({ specList, viewGood: e.currentTarget.dataset.goodimage, - 'goods.goodPrice': updatedPrice // 更新价格 - }); - this.updateSelectedSpecs(); + "goods.goodPrice": updatedPrice, // 更新价格 + }) + this.updateSelectedSpecs() }, goToHome() { wx.switchTab({ - url: '/page/component/index' // 使用switchTab跳转到首页(tabbar页面) - }); + url: "/page/component/index", // 使用switchTab跳转到首页(tabbar页面) + }) }, updateSelectedSpecs() { - const selectedSpecs = this.data.specList.map(spec => { - const selectedItem = spec.specValueList.find(item => item.isSelected); - return selectedItem ? selectedItem.specValue : null; - }).filter(item => item); - this.setData({ selectedSpecs }); + const selectedSpecs = this.data.specList + .map((spec) => { + const selectedItem = spec.specValueList.find((item) => item.isSelected) + return selectedItem ? selectedItem.specValue : null + }) + .filter((item) => item) + this.setData({ selectedSpecs }) }, handleBuyNumChange(e) { this.setData({ - buyNum: e.detail.value - }); + buyNum: e.detail.value, + }) }, confirmSpecs() { console.log(this.data.selectedSpecs) - if (this.data.selectedSpecs.length < this.data.specList.length) { - wx.showToast({ - title: '请选择所有规格', - icon: 'none' - }); - return; - } + // if (this.data.selectedSpecs.length < this.data.specList.length) { + // wx.showToast({ + // title: "请选择所有规格", + // icon: "none", + // }) + // return + // } - this.setData({ showPopup: false }); + this.setData({ showPopup: false }) // wx.getUserProfile({ // desc: '用于完善会员资料', // success: (res) => { // this.setData({ userInfo: res.userInfo }); - const { id, goodName, goodImage, goodPrice } = this.data.goods; - const num = this.data.buyNum; - const url = `../orders/orders?goodsId=${id}&title=${goodName}&image=${goodImage[0]}&price=${goodPrice}&num=${num}&specs=${this.data.selectedSpecs.join(',')}`; + const { id, goodName, goodImage, goodPrice } = this.data.goods + const num = this.data.buyNum + const url = `../orders/orders?goodsId=${id}&title=${goodName}&image=${ + goodImage[0] + }&price=${goodPrice}&num=${num}&specs=${this.data.selectedSpecs.join(",")}` - wx.navigateTo({ url }); + wx.navigateTo({ url }) // }, // fail: (err) => { // wx.showToast({ @@ -120,5 +124,5 @@ Page({ // }); // } // }); - } -}); + }, +}) diff --git a/page/component/details/details.wxml b/page/component/details/details.wxml index b5b81a6..c7c5b1f 100644 --- a/page/component/details/details.wxml +++ b/page/component/details/details.wxml @@ -55,7 +55,7 @@ 默认统一被褥1.5m*2.0m - + 购买数量 diff --git a/page/component/index.js b/page/component/index.js index f314f91..785688b 100644 --- a/page/component/index.js +++ b/page/component/index.js @@ -79,7 +79,7 @@ Page({ success: (res) => { const wxConfig = { appid: "wx865aefa5a7115ae0", - secret: "df0817d59696a6160de2770222d8ec53", + secret: "4f883606afdbca0599b732753856b5b5", code: res.code } console.log("code: " + res.code) diff --git a/page/component/user/user.js b/page/component/user/user.js index c2f88a1..500055d 100644 --- a/page/component/user/user.js +++ b/page/component/user/user.js @@ -53,14 +53,14 @@ Page({ console.log("code:" + res.code) const wxConfig = { appid: "wx865aefa5a7115ae0", - secret: "3f9849429894435abc935eea88178dfd", + secret: "4f883606afdbca0599b732753856b5b5", code: res.code } wx.request({ url: "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxConfig.appid + "&secret=" + wxConfig.secret + "&code=" + wxConfig.code + "&js_code=" + wxConfig.code + '&grant_type=authorization_code', success: (res) => { wx.setStorageSync('openid', res.data.openid); - console.log(res); + console.log("res",res); }, fail: (err) => { console.error('wx.login 失败', err);