detail.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. wx.navigateTo({
  34. url: `/pages/pay/pay?data=${JSON.stringify({ id, shopdetail })}`,
  35. })
  36. return false;
  37. }
  38. },
  39. // 请求数据
  40. ShopRequest () {
  41. let { id, shopdetail } = this.data, that = this;
  42. axios({
  43. url: `/commodity/wx_commodity_detail/${id}/`,
  44. method: "get",
  45. success (res) {
  46. let { amount, price, days, detail_images: detaillist, introduce: desc, main_image: img, name } = res.data.data;
  47. shopdetail = {
  48. name, price, detaillist, desc, img, amount, days
  49. };
  50. that.setData({
  51. shopdetail
  52. })
  53. wx.stopPullDownRefresh();
  54. }
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. wx.lxd.Ctr({
  62. // nav
  63. title: "商品详情", //标题
  64. back: true,//返回按钮,tabber必须false(除非会改)
  65. })
  66. let { data } = options;
  67. if (!!data) {
  68. data = JSON.parse(data);
  69. this.setData({
  70. ...data
  71. })
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. this.ShopRequest();
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. this.ShopRequest();
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. return {
  111. title: this.data.shopdetail.name,
  112. path: `/pages/detail/detail?data=${JSON.stringify({ id: this.data.id })}`
  113. }
  114. },
  115. onShareTimeline: function (res) {
  116. return {
  117. title: this.data.shopdetail.name,
  118. query: `data=${JSON.stringify({ id: this.data.id })}`
  119. }
  120. }
  121. })