index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // pages/index/index.js
  2. import recordSource from '../../utils/recordSource';
  3. const getReq = require('../../config.js').getReq;
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabs: [],
  11. prop_special: [],
  12. surplus_special: [],
  13. special_datas: {},
  14. summery: [],
  15. isScroll: false,
  16. isSendProp: false,
  17. firstLoad: true,
  18. fromSource: '',
  19. tipsFlag: false,
  20. tipsDatas: null,
  21. daliy_bonus: ''
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. console.log('index page onLoad options:', options)
  28. if (options && options.relay_id) {
  29. app.globalData.relay_id = options.relay_id
  30. console.log('options.relay_id:', options.relay_id)
  31. }
  32. if (options && options.channel) {
  33. app.globalData.channel_num = options.channel
  34. console.log('options.channel:', options.channel)
  35. }
  36. this.getDatas(1040)
  37. },
  38. onWxButtonEvent:function (e) {
  39. console.log('index: onWxButtonEvent',e);
  40. if(e.detail.event_type == 'getUserInfo') {
  41. if (e.detail.authen == 'success') {
  42. wx.showModal({
  43. title: '成功领取新人券',
  44. content: '马上去使用优惠券?',
  45. cancelText: '去首页',
  46. confirmText: '加个油',
  47. success: function (res) {
  48. if (res.confirm) {
  49. app.switchtab("/pages/postage/postage");
  50. } else {
  51. app.switchtab("/pages/home/home");
  52. }
  53. }
  54. })
  55. }
  56. else {
  57. app.switchtab("/pages/home/home");
  58. }
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. if (!this.data.firstLoad) {
  71. app.setFromSource(this.data.fromSource)
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload: function () {
  83. },
  84. getDatas(special_id) {
  85. let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
  86. wx.showLoading({
  87. title: '加载中'
  88. });
  89. let self = this;
  90. console.log('fromSource =' + fromSource)
  91. getReq(app, {
  92. act: 'special',
  93. op: 'index',
  94. special_id: special_id
  95. }, function (res) {
  96. wx.stopPullDownRefresh()
  97. if (res.code == 200) {
  98. console.log(res)
  99. let prop_special = res.datas.special_list;
  100. let sent_down_special = prop_special.splice(0, 8);
  101. self.setData({
  102. surplus_special: prop_special,
  103. prop_special: sent_down_special,
  104. special_datas: res.datas,
  105. summery: res.datas.summary,
  106. firstLoad: false,
  107. fromSource: app.globalData.fromSource
  108. });
  109. }
  110. setTimeout(function () {
  111. wx.hideLoading()
  112. }, 1000)
  113. })
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh: function () {
  119. this.getDatas()
  120. },
  121. onPageScroll(e) {
  122. clearTimeout(this.showTop);
  123. this.showTop = setTimeout(() => {
  124. let scrollTop = e.scrollTop;
  125. if (scrollTop >= 300) {
  126. this.setData({
  127. isScroll: true
  128. })
  129. }
  130. else {
  131. this.setData({
  132. isScroll: false
  133. })
  134. }
  135. }, 100);
  136. },
  137. backTop() {
  138. wx.pageScrollTo({
  139. scrollTop: 0,
  140. duration: 300
  141. })
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. if (this.data.isSendProp) {
  148. return;
  149. }
  150. let surplus_special_num = this.data.surplus_special.length;
  151. if (surplus_special_num > 0) {
  152. wx.showLoading({
  153. title: '加载中'
  154. });
  155. this.setData({
  156. isSendProp: true
  157. });
  158. this.data.isSendProp = true;
  159. let prop_special = this.data.surplus_special;
  160. let sent_down_special = prop_special.splice(0, 8);
  161. this.setData({
  162. surplus_special: prop_special,
  163. prop_special: this.data.prop_special.concat(sent_down_special)
  164. })
  165. this.setData({
  166. isSendProp: false
  167. });
  168. setTimeout(function () {
  169. wx.hideLoading()
  170. }, 1500)
  171. }
  172. else {
  173. return;
  174. }
  175. },
  176. /**
  177. * 用户点击右上角分享
  178. */
  179. onShareAppMessage: function () {
  180. return app.cardShareInfo();
  181. }
  182. })