details.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // pages/details/details.js
  2. const app = getApp()
  3. const link = app.globalData.url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. p_id:"",
  10. search_id:"",
  11. goods_sign:"",
  12. goods_details:"",
  13. goods_name:"",
  14. amount:0,
  15. price:0,
  16. rebate:0,
  17. text:"",
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. var that=this
  24. console.log("ppp="+options)
  25. console.log(options)
  26. const goodsSign=options.goodsSign
  27. const searchId=options.searchId
  28. //const pid = "9112489_209622235"
  29. var pid = "9112489_212035116"
  30. var opneId = wx.getStorageSync('openId')
  31. console.log(opneId)
  32. if (options.id == "111"){
  33. console.log(options.id)
  34. wx.login({
  35. success: res => {
  36. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  37. console.log(res)
  38. wx.request( {
  39. url: link + "/v1/user/open.id/set",
  40. header: {
  41. "Content-Type": "application/json"
  42. },
  43. method: "POST",
  44. //
  45. data: { code: res.code,openId: options.openId },
  46. complete: function( res ) {
  47. console.log(res)
  48. console.log('openid='+ options.openId )
  49. if (res.data.code == 200){
  50. wx.setStorageSync('openId', res.data.data.openid)
  51. }
  52. }
  53. })
  54. }
  55. })
  56. }
  57. //获取pid
  58. wx.request({
  59. url: link + '/v1/user/pid/get',
  60. data: { openId: opneId },
  61. header: {
  62. "Content-Type": "application/json"
  63. },
  64. method: "POST",
  65. success (res) {
  66. console.log(res)
  67. console.log(pid)
  68. if (res.data.code == 200){
  69. pid = res.data.data.pid
  70. }
  71. console.log(pid)
  72. that.p_id = pid
  73. that.goods_sign = goodsSign
  74. that.search_id = searchId
  75. wx.request({
  76. url: link + '/v1/pdd/ddk/detail',
  77. data: { goods_sign: goodsSign, search_id: searchId,pid: pid },
  78. header: {
  79. "Content-Type": "application/json"
  80. },
  81. method: "POST",
  82. success (res) {
  83. console.log(res)
  84. that.goods_details = res.data.data.goods_detail_response.goods_details[0].goods_image_url
  85. 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
  86. that.price = (res.data.data.goods_detail_response.goods_details[0].min_group_price)/100
  87. that.rebate = res.data.data.goods_detail_response.goods_details[0].rebate
  88. that.goods_name = res.data.data.goods_detail_response.goods_details[0].goods_name
  89. that.text = that.goods_name + "\n" + "原价:" + that.price + "元\n" + "优惠价:"+that.amount + "元\n" + "返利:"+that.rebate + "元\n" + "点击下方链接即可查看产品详情"
  90. that.setData({
  91. goodsDetails: res.data.data.goods_detail_response.goods_details,
  92. searchId:searchId
  93. })
  94. }
  95. })
  96. }
  97. })
  98. },
  99. copyText: function (e) {
  100. var that = this
  101. console.log(e)
  102. wx.setClipboardData({
  103. data: that.text,
  104. success: function (res) {
  105. wx.getClipboardData({
  106. success: function (res) {
  107. wx.showToast({
  108. title: '复制成功'
  109. })
  110. }
  111. })
  112. }
  113. })
  114. },
  115. counponBtn:function(e){
  116. var that = this
  117. console.log("pdd")
  118. console.log(that.p_id)
  119. wx.request({
  120. url: link + '/v1/pdd/url/generate',
  121. data: { goods_sign_list: [that.goods_sign], search_id: that.search_id,p_id: that.p_id,generate_we_app:"true" },
  122. header: {
  123. "Content-Type": "application/json"
  124. },
  125. method: "POST",
  126. success (res) {
  127. console.log(res)
  128. // that.setData({
  129. // goodsDetails: res.data.data.goods_detail_response.goods_details,
  130. // searchId:searchId
  131. // })
  132. console.log(res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_info.page_path)
  133. let path = res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_info.page_path
  134. //let path = res.data.data.goods_promotion_url_generate_response.goods_promotion_url_list[0].we_app_web_view_short_url
  135. wx.navigateToMiniProgram({
  136. appId: 'wx32540bd863b27570',
  137. path: path,
  138. success(res) {
  139. }
  140. })
  141. }
  142. })
  143. },
  144. bindscroll(e) {
  145. //计算页面 轮播图、详情、评价(砍价)view 高度
  146. this.getTopHeightFunction()
  147. var tabsHeight = this.data.tabsHeight //顶部距离(tabs高度)
  148. if (this.data.tabs[0].topHeight-tabsHeight<=0 && 0 < this.data.tabs[1].topHeight-tabsHeight) { //临界值,根据自己的需求来调整
  149. this.setData({
  150. active: this.data.tabs[0].tabs_name //设置当前标签栏
  151. })
  152. } else if (this.data.tabs.length == 2) {
  153. this.setData({
  154. active: this.data.tabs[1].tabs_name
  155. })
  156. } else if (this.data.tabs[1].topHeight-tabsHeight<=0 && 0 < this.data.tabs[2].topHeight-tabsHeight) {
  157. this.setData({
  158. active: this.data.tabs[1].tabs_name
  159. })
  160. } else if (this.data.tabs[2].topHeight-tabsHeight<=0) {
  161. this.setData({
  162. active: this.data.tabs[2].tabs_name
  163. })
  164. }
  165. },
  166. /**
  167. * 生命周期函数--监听页面初次渲染完成
  168. */
  169. onReady: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow: function () {
  175. },
  176. /**
  177. * 生命周期函数--监听页面隐藏
  178. */
  179. onHide: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面卸载
  183. */
  184. onUnload: function () {
  185. },
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh: function () {
  190. },
  191. /**
  192. * 页面上拉触底事件的处理函数
  193. */
  194. onReachBottom: function () {
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage: function () {
  200. var that = this
  201. var openId = wx.getStorageSync('openId')
  202. var goodsSign = that.goods_sign
  203. var searchId = that.search_id
  204. wx.showShareMenu({
  205. withShareTicket: true,
  206. menus: ['shareAppMessage', 'shareTimeline']
  207. })
  208. return {
  209. title: '自定义转发标题',
  210. path: `pages/boutique/outique?openId=${openId}&goodsSign=${goodsSign}&searchId=${searchId}` // 路径,传递参数到指定页面。,
  211. }
  212. },
  213. onShareTimeline: function(){
  214. var that = this
  215. var openId = wx.getStorageSync('openId')
  216. var goodsSign = that.goods_sign
  217. var searchId = that.search_id
  218. // return {
  219. // title: '自定义转发标题',
  220. // path: '/page/user?id=123',
  221. // promise
  222. // }
  223. return {
  224. title: that.goods_name,
  225. query:'goodsSign='+ goodsSign +'&searchId=' + searchId + '&openId=' + openId + '&id=111',
  226. imageUrl: that.goods_details
  227. }
  228. }
  229. })