promotion.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. loaddisplay: 'none',
  7. arr: [],
  8. indicatorDots: true,
  9. autoplay: true,
  10. interval: 5000,
  11. duration: 2000,
  12. userInfo: {},
  13. hasUserInfo: false,
  14. canIUse: wx.canIUse('button.open-type.getUserInfo')
  15. },
  16. hrefPm: function(e) {
  17. var index = e.currentTarget.dataset.index;
  18. wx.navigateTo({
  19. url: '/pages/promotion/promotionhref?para=' + index
  20. })
  21. console.log(index)
  22. console.log(e.currentTarget)
  23. if (index != null) {
  24. if (e.currentTarget.dataset.type == 1) {
  25. wx.navigateTo({
  26. url: '/pages/promotion/promotionhref?para=' + index
  27. })
  28. }
  29. if (e.currentTarget.dataset.type == 2) {
  30. wx.navigateTo({
  31. url: index
  32. })
  33. }
  34. }
  35. },
  36. //事件处理函数
  37. bindViewTap: function() {
  38. wx.navigateTo({
  39. url: '../logs/logs'
  40. })
  41. },
  42. finish: function() {
  43. this.setData({
  44. loaddisplay: 'none'
  45. })
  46. },
  47. onLoad: function() {
  48. this.setData({
  49. loaddisplay: true
  50. })
  51. var that = this
  52. wx.request({
  53. url: app.globalData.url + '/getPromotions',
  54. method: 'get',
  55. success: function(res) {
  56. console.log(res.data)
  57. that.setData({
  58. arr: res.data
  59. })
  60. },
  61. fail() {
  62. app.timeOut()
  63. }
  64. })
  65. if (app.globalData.userInfo) {
  66. this.setData({
  67. userInfo: app.globalData.userInfo,
  68. hasUserInfo: true
  69. })
  70. } else if (this.data.canIUse) {
  71. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  72. // 所以此处加入 callback 以防止这种情况
  73. app.userInfoReadyCallback = res => {
  74. this.setData({
  75. userInfo: res.userInfo,
  76. hasUserInfo: true
  77. })
  78. }
  79. } else {
  80. // 在没有 open-type=getUserInfo 版本的兼容处理
  81. wx.getUserInfo({
  82. success: res => {
  83. app.globalData.userInfo = res.userInfo
  84. this.setData({
  85. userInfo: res.userInfo,
  86. hasUserInfo: true
  87. })
  88. },
  89. fail() {
  90. app.timeOut()
  91. }
  92. })
  93. }
  94. let _this = this;
  95. _this.setData({
  96. navH: app.globalData.navHeight
  97. })
  98. },
  99. getUserInfo: function(e) {
  100. app.globalData.userInfo = e.detail.userInfo
  101. this.setData({
  102. userInfo: e.detail.userInfo,
  103. hasUserInfo: true
  104. })
  105. },
  106. onShareAppMessage: function() {
  107. return {
  108. title: '米粒-近期活动',
  109. path: '/pages/index/index?skip=1&path=/pages/promotion/promotion'
  110. }
  111. }
  112. })