index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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('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. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. if (!this.data.firstLoad) {
  48. app.setFromSource(this.data.fromSource)
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. getDatas(special_id) {
  62. let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
  63. wx.showLoading({
  64. title: '加载中'
  65. });
  66. let self = this;
  67. console.log('fromSource =' + fromSource)
  68. getReq(app, {
  69. act: 'special',
  70. op: 'index',
  71. special_id: special_id
  72. }, function (res) {
  73. wx.stopPullDownRefresh()
  74. if (res.code == 200) {
  75. console.log(res)
  76. let prop_special = res.datas.special_list;
  77. let sent_down_special = prop_special.splice(0, 8);
  78. self.setData({
  79. surplus_special: prop_special,
  80. prop_special: sent_down_special,
  81. special_datas: res.datas,
  82. summery: res.datas.summary,
  83. firstLoad: false,
  84. fromSource: app.globalData.fromSource
  85. });
  86. }
  87. setTimeout(function () {
  88. wx.hideLoading()
  89. }, 1000)
  90. })
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. this.getDatas()
  97. },
  98. onPageScroll(e) {
  99. clearTimeout(this.showTop);
  100. this.showTop = setTimeout(() => {
  101. let scrollTop = e.scrollTop;
  102. if (scrollTop >= 300) {
  103. this.setData({
  104. isScroll: true
  105. })
  106. }
  107. else {
  108. this.setData({
  109. isScroll: false
  110. })
  111. }
  112. }, 100);
  113. },
  114. backTop() {
  115. wx.pageScrollTo({
  116. scrollTop: 0,
  117. duration: 300
  118. })
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {
  124. if (this.data.isSendProp) {
  125. return;
  126. }
  127. let surplus_special_num = this.data.surplus_special.length;
  128. if (surplus_special_num > 0) {
  129. wx.showLoading({
  130. title: '加载中'
  131. });
  132. this.setData({
  133. isSendProp: true
  134. });
  135. this.data.isSendProp = true;
  136. let prop_special = this.data.surplus_special;
  137. let sent_down_special = prop_special.splice(0, 8);
  138. this.setData({
  139. surplus_special: prop_special,
  140. prop_special: this.data.prop_special.concat(sent_down_special)
  141. })
  142. this.setData({
  143. isSendProp: false
  144. });
  145. setTimeout(function () {
  146. wx.hideLoading()
  147. }, 1500)
  148. }
  149. else {
  150. return;
  151. }
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage: function () {
  157. return app.cardShareInfo();
  158. }
  159. })