detail.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/detail/detail.js
  2. const app = getApp()
  3. const { axios, token } = app.globalData;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 数据模拟
  10. shopdetail: {}
  11. },
  12. // 点击图标事件
  13. onClickIcon (e) {
  14. let { type } = e.currentTarget.dataset;
  15. if (type == 'share') {
  16. wx.lxd.Share({
  17. show: true,
  18. })
  19. }
  20. },
  21. // 点击按钮事件
  22. onClickButton (e) {
  23. let { type } = e.currentTarget.dataset;
  24. // 点击立即购买
  25. if (type == "buy") {
  26. if (!token()) {
  27. wx.navigateTo({
  28. url: '/pages/sgin/sgin',
  29. })
  30. return false
  31. }
  32. let { id, shopdetail } = this.data;
  33. console.log(id)
  34. wx.navigateTo({
  35. url: `/pages/pay/pay?data=${JSON.stringify({ id, shopdetail })}`,
  36. })
  37. return false;
  38. }
  39. },
  40. // 请求数据
  41. ShopRequest () {
  42. let { id, shopdetail } = this.data, that = this;
  43. axios({
  44. url: `/commodity/wx_commodity_detail/${id}/`,
  45. method: "get",
  46. success (res) {
  47. let { amount, price, days, detail_images: detaillist, introduce: desc, main_image: img, name } = res.data.data;
  48. shopdetail = {
  49. name, price, detaillist, desc, img, amount, days
  50. };
  51. that.setData({
  52. shopdetail
  53. })
  54. wx.stopPullDownRefresh();
  55. }
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. wx.lxd.Ctr({
  63. // nav
  64. title: "商品详情", //标题
  65. back: true,//返回按钮,tabber必须false(除非会改)
  66. })
  67. let { data } = options;
  68. if (!!data) {
  69. data = JSON.parse(data);
  70. this.setData({
  71. ...data
  72. })
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. this.ShopRequest();
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. this.ShopRequest();
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. return {
  112. title: this.data.shopdetail.name,
  113. path: `/pages/detail/detail?data=${JSON.stringify({ id: this.data.id })}`
  114. }
  115. },
  116. onShareTimeline: function (res) {
  117. return {
  118. title: this.data.shopdetail.name,
  119. query: `data=${JSON.stringify({ id: this.data.id })}`
  120. }
  121. }
  122. })