// pages/details/details.js const app = getApp() const link = app.globalData.url Page({ /** * 页面的初始数据 */ data: { p_id:"", search_id:"", goods_sign:"", goods_details:"", goods_name:"", amount:0, price:0, rebate:0, text:"", }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that=this console.log("ppp="+options) console.log(options) const goodsSign=options.goodsSign const searchId=options.searchId //const pid = "9112489_209622235" var pid = "9112489_212035116" var opneId = wx.getStorageSync('openId') console.log(opneId) if (options.id == "111"){ console.log(options.id) wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId console.log(res) wx.request( { url: link + "/v1/user/open.id/set", header: { "Content-Type": "application/json" }, method: "POST", // data: { code: res.code,openId: options.openId }, complete: function( res ) { console.log(res) console.log('openid='+ options.openId ) if (res.data.code == 200){ wx.setStorageSync('openId', res.data.data.openid) } } }) } }) } //获取pid wx.request({ url: link + '/v1/user/pid/get', data: { openId: opneId }, header: { "Content-Type": "application/json" }, method: "POST", success (res) { console.log(res) console.log(pid) if (res.data.code == 200){ pid = res.data.data.pid } console.log(pid) that.p_id = pid that.goods_sign = goodsSign that.search_id = searchId wx.request({ url: link + '/v1/pdd/ddk/detail', data: { goods_sign: goodsSign, search_id: searchId,pid: pid }, header: { "Content-Type": "application/json" }, method: "POST", success (res) { console.log(res) that.goods_details = res.data.data.goods_detail_response.goods_details[0].goods_image_url that.amount =(res.data.data.goods_detail_response.goods_details[0].min_group_price - res.data.data.goods_detail_response.goods_details[0].coupon_discount)/100 that.price = (res.data.data.goods_detail_response.goods_details[0].min_group_price)/100 that.rebate = res.data.data.goods_detail_response.goods_details[0].rebate that.goods_name = res.data.data.goods_detail_response.goods_details[0].goods_name that.text = that.goods_name + "\n" + "原价:" + that.price + "元\n" + "优惠价:"+that.amount + "元\n" + "返利:"+that.rebate + "元\n" + "点击下方链接即可查看产品详情" that.setData({ goodsDetails: res.data.data.goods_detail_response.goods_details, searchId:searchId }) } }) } }) }, copyText: function (e) { var that = this console.log(e) wx.setClipboardData({ data: that.text, success: function (res) { wx.getClipboardData({ success: function (res) { wx.showToast({ title: '复制成功' }) } }) } }) }, counponBtn:function(e){ var that = this console.log("pdd") console.log(that.p_id) wx.request({ url: link + '/v1/pdd/url/generate', data: { goods_sign_list: [that.goods_sign], search_id: that.search_id,p_id: that.p_id,generate_we_app:"true" }, header: { "Content-Type": "application/json" }, method: "POST", success (res) { console.log(res) // that.setData({ // goodsDetails: res.data.data.goods_detail_response.goods_details, // searchId:searchId // }) console.log(res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_info.page_path) let path = res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_info.page_path //let path = res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_web_view_short_url wx.navigateToMiniProgram({ appId: 'wx32540bd863b27570', path: path, success(res) { } }) } }) }, bindscroll(e) { //计算页面 轮播图、详情、评价(砍价)view 高度 this.getTopHeightFunction() var tabsHeight = this.data.tabsHeight //顶部距离(tabs高度) if (this.data.tabs[0].topHeight-tabsHeight<=0 && 0 < this.data.tabs[1].topHeight-tabsHeight) { //临界值,根据自己的需求来调整 this.setData({ active: this.data.tabs[0].tabs_name //设置当前标签栏 }) } else if (this.data.tabs.length == 2) { this.setData({ active: this.data.tabs[1].tabs_name }) } else if (this.data.tabs[1].topHeight-tabsHeight<=0 && 0 < this.data.tabs[2].topHeight-tabsHeight) { this.setData({ active: this.data.tabs[1].tabs_name }) } else if (this.data.tabs[2].topHeight-tabsHeight<=0) { this.setData({ active: this.data.tabs[2].tabs_name }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { var that = this var openId = wx.getStorageSync('openId') var goodsSign = that.goods_sign var searchId = that.search_id wx.showShareMenu({ withShareTicket: true, menus: ['shareAppMessage', 'shareTimeline'] }) return { title: '自定义转发标题', path: `pages/boutique/outique?openId=${openId}&goodsSign=${goodsSign}&searchId=${searchId}` // 路径,传递参数到指定页面。, } }, onShareTimeline: function(){ var that = this var openId = wx.getStorageSync('openId') var goodsSign = that.goods_sign var searchId = that.search_id // return { // title: '自定义转发标题', // path: '/page/user?id=123', // promise // } return { title: that.goods_name, query:'goodsSign='+ goodsSign +'&searchId=' + searchId + '&openId=' + openId + '&id=111', imageUrl: that.goods_details } } })