diff --git a/pages/detail/detail.vue b/pages/detail/detail.vue index 388b3a2..f9b061a 100644 --- a/pages/detail/detail.vue +++ b/pages/detail/detail.vue @@ -363,35 +363,42 @@ // 获取同类推荐 (使用 itemid 和 son_category) this.getSimilarProducts(d.itemid, d.son_category); - // 加载完商品后请求淘口令 / 领券链接 - this.fetchTaoWord(); } } }); }, - fetchTaoWord() { + fetchTaoWord(callback) { if (!this.product.taobaoId) return; + uni.showLoading({ title: '加载中...', mask: true }); uni.request({ - url: 'https://api.cmspro.haodanku.com/taobao/getTaoWord', + url: 'https://v2.api.haodanku.com/ratesurl', method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, data: { - domain: 'cms.baimajiayuanjiankang.com', itemid: this.product.taobaoId, - activityid: this.product.activityId || '', title: this.product.title || '', - relation_id: '2887601176', - cid: 'YsWZ21tx' + get_taoword: 1, + pid: 'mm_284380119_1881450385_111415850448', + tb_name: 'michuan2018', + relation_id: '2864040832', + apikey: '5417B681C5EA' }, success: (res) => { + uni.hideLoading(); const body = res.data || {}; - if (body.code === 200 && body.data) { - this.product.taoCode = body.data.tao_code || ''; - this.product.spreadUrl = body.data.spread_url || ''; - this.product.couponUrl = body.data.coupon_url || ''; + if (body.code === 1 && body.data) { + this.product.taoCode = body.data.taoword || ''; + this.product.couponUrl = body.data.coupon_click_url || ''; + if (callback) callback(); + } else { + uni.showToast({ title: body.msg || '获取失败', icon: 'none' }); } + }, + fail: () => { + uni.hideLoading(); + uni.showToast({ title: '网络错误', icon: 'none' }); } }); }, @@ -420,37 +427,41 @@ uni.navigateBack(); }, copyTaoWord() { - if (!this.product.taoCode) { - uni.showToast({ title: '口令加载中,请稍候', icon: 'none' }); - return; - } - uni.setClipboardData({ - data: this.product.taoCode, - success: () => { - uni.showToast({ title: '淘口令已复制', icon: 'success' }); - }, - fail: () => { - uni.showToast({ title: '复制失败', icon: 'none' }); + this.fetchTaoWord(() => { + if (!this.product.taoCode) { + uni.showToast({ title: '暂无口令', icon: 'none' }); + return; } + uni.setClipboardData({ + data: this.product.taoCode, + success: () => { + uni.showToast({ title: '淘口令已复制', icon: 'success' }); + }, + fail: () => { + uni.showToast({ title: '复制失败', icon: 'none' }); + } + }); }); }, goBuy() { - const url = this.product.couponUrl; - if (!url) { - uni.showToast({ title: '链接加载中,请稍候', icon: 'none' }); - return; - } - // #ifdef H5 - window.location.href = url; - // #endif - // #ifndef H5 - uni.setClipboardData({ - data: url, - success: () => { - uni.showToast({ title: '链接已复制,请到浏览器打开', icon: 'none' }); + this.fetchTaoWord(() => { + const url = this.product.couponUrl; + if (!url) { + uni.showToast({ title: '暂无领券链接', icon: 'none' }); + return; } + // #ifdef H5 + window.location.href = url; + // #endif + // #ifndef H5 + uni.setClipboardData({ + data: url, + success: () => { + uni.showToast({ title: '链接已复制,请到浏览器打开', icon: 'none' }); + } + }); + // #endif }); - // #endif }, handleScroll(e) { const scrollTop = e.detail.scrollTop;