promotion.js 2.2 KB

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