From d780880b7a73360c8fc9fead1b429dd8ba3758e3 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期五, 27 九月 2024 14:51:59 +0800 Subject: [PATCH] ts --- pages/home/home.js | 76 +++++++++++++++++++++---------------- 1 files changed, 43 insertions(+), 33 deletions(-) diff --git a/pages/home/home.js b/pages/home/home.js index b94578d..b48cb9a 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -270,6 +270,7 @@ app.MG.store.getProductList(obj).then((res) => { res.datas.forEach((item) => { item.price = item.price ? item.price.toFixed(2) : item.price; + item.isbuy = item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1 }); this.setData({ courseList: res.datas @@ -399,6 +400,7 @@ app.MG.store.getProductList(obj).then((res) => { res.datas.forEach((item) => { item.price = item.price ? item.price.toFixed(2) : item.price; + item.isbuy = item.purchasedSaleMethodIdList.indexOf(item.defaultSaleMethodId) > -1 }); this.setData({ textbookList: res.datas @@ -520,46 +522,54 @@ info } = e.currentTarget.dataset; if (wx.getStorageSync(app.config.tokenKey)) { - let query = { - start: 0, - size: 999, - filterList: [], - searchList: [] - } - try { - if ( - this.data.shoppingCartGetId.includes( - info.defaultSaleMethodId - ) - ) { - wx.showToast({ - title: "璇ュ晢鍝佸凡鍦ㄨ喘鐗╄溅锛岃鍕块噸澶嶆坊鍔�", - icon: 'none', - duration: 1000 - }) - } else { - let query = { - requests: [{ - saleMethodId: info.defaultSaleMethodId, - storeEventId: null, - agentCode: '鐢靛瓙涔�' - }] - } - const addRes = await app.MG.store.addShoppingCart(query) - if (addRes) { + if (info.isbuy) { + wx.showToast({ + title: "璇ュ晢鍝佸凡璐拱", + icon: 'none', + duration: 1000 + }) + } else { + let query = { + start: 0, + size: 999, + filterList: [], + searchList: [] + } + try { + if ( + this.data.shoppingCartGetId.includes( + info.defaultSaleMethodId + ) + ) { wx.showToast({ - title: "娣诲姞鎴愬姛", - icon: 'success', + title: "璇ュ晢鍝佸凡鍦ㄨ喘鐗╄溅锛岃鍕块噸澶嶆坊鍔�", + icon: 'none', duration: 1000 }) + } else { + let query = { + requests: [{ + saleMethodId: info.defaultSaleMethodId, + storeEventId: null, + agentCode: '鐢靛瓙涔�' + }] + } + const addRes = await app.MG.store.addShoppingCart(query) + if (addRes) { + wx.showToast({ + title: "娣诲姞鎴愬姛", + icon: 'success', + duration: 1000 + }) + } + this.getShoppingCartList() } - this.getShoppingCartList() + + } catch (error) { + console.error('鍑洪敊浜嗭細', error) } - } catch (error) { - console.error('鍑洪敊浜嗭細', error) } } - }, onMoreGuide(e) { let type = e.currentTarget.dataset.info -- Gitblit v1.9.1