index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import recordSource from '../../utils/recordSource';
  2. import bonusUp from '../../utils/bonusUp';
  3. const getReq = require('../../config.js').getReq;
  4. const getTypeSn = require('../../utils/util.js').getTypeSn;
  5. let app = getApp();
  6. Page({
  7. data: {
  8. tabs: [],
  9. prop_special: [],
  10. surplus_special: [],
  11. special_datas: {},
  12. summery: [],
  13. isScroll: false,
  14. isSendProp: false,
  15. firstLoad: true,
  16. fromSource: '',
  17. tipsFlag: false,
  18. tipsDatas: null,
  19. daliy_bonus: ''
  20. },
  21. onShow: function ()
  22. {
  23. this.closeTips()
  24. if (!this.data.firstLoad) {
  25. app.setFromSource(this.data.fromSource)
  26. }
  27. // if (app.globalData.userInfo) {
  28. // setTimeout(() => {
  29. // bonusUp((tipsFlag, tipsDatas) => {
  30. // this.setData({
  31. // tipsFlag,
  32. // tipsDatas
  33. // })
  34. // })
  35. // }, 0);
  36. // }
  37. },
  38. onLoad: function (options) {
  39. console.log('onLoad options:',options)
  40. if (options && options.relay_id) {
  41. app.globalData.relay_id = options.relay_id
  42. console.log('options.relay_id:', options.relay_id)
  43. }
  44. if (options && options.channel) {
  45. app.globalData.channel_num = options.channel
  46. console.log('options.channel:', options.channel)
  47. }
  48. this.getDatas()
  49. },
  50. freeBonus() {
  51. if (this.data.daliy_bonus) {
  52. let type_sn = getTypeSn(this.data.daliy_bonus)
  53. if (type_sn) {
  54. app.navigateto(`/pages/shareBonus/shareBonus?type_sn=${type_sn}`)
  55. return
  56. }
  57. }
  58. },
  59. getDatas(special_id) {
  60. let fromSource = recordSource(app, 'act=index&op=index&special_id=0&page=10&curpage=1&client_type=mini')
  61. // wx.showLoading({
  62. // title: '加载中'
  63. // });
  64. let self = this;
  65. console.log('fromSource =' + fromSource)
  66. getReq(app,{
  67. act: 'index',
  68. op: 'mini_index',
  69. page: 10,
  70. curpage: 1,
  71. from: fromSource
  72. }, function (res) {
  73. wx.stopPullDownRefresh()
  74. if (res.code == 200) {
  75. let prop_special = res.datas.special_list;
  76. let sent_down_special = prop_special.splice(0, 8);
  77. self.setData({
  78. surplus_special: prop_special,
  79. prop_special: sent_down_special,
  80. special_datas: res.datas,
  81. summery: res.datas.summary,
  82. firstLoad: false,
  83. fromSource: app.globalData.fromSource
  84. });
  85. }
  86. setTimeout(function () {
  87. wx.hideLoading()
  88. }, 1000)
  89. })
  90. },
  91. req_tabs() {
  92. let self = this
  93. getReq(app,{
  94. act: 'index',
  95. op: 'tabs'
  96. }, function (res) {
  97. if (res.code == 200) {
  98. self.getDatas(res.datas.tabs[0].special_id);
  99. self.setData({
  100. tabs: res.datas.tabs,
  101. daliy_bonus: res.datas.daliy_bonus
  102. });
  103. }
  104. })
  105. },
  106. onMyEvent: function (e) {
  107. this.setData({
  108. prop_special: [],
  109. surplus_special: [],
  110. special_datas: {},
  111. summery: []
  112. });
  113. this.getDatas(e.detail.item.special_id)
  114. },
  115. closeTips() {
  116. this.setData({
  117. tipsFlag: false,
  118. tipsDatas: null
  119. })
  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. onShareAppMessage: function () {
  144. return app.cardShareInfo();
  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. onPullDownRefresh(){
  177. this.getDatas()
  178. }
  179. })