index.js 4.2 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('index onLoad:',options)
  40. if (!options.relay_id) {
  41. app.globalData.relay_id = options.relay_id
  42. }
  43. // this.req_tabs();
  44. this.getDatas(0)
  45. },
  46. freeBonus() {
  47. if (this.data.daliy_bonus) {
  48. let type_sn = getTypeSn(this.data.daliy_bonus)
  49. if (type_sn) {
  50. app.navigateto(`/pages/shareBonus/shareBonus?type_sn=${type_sn}`)
  51. return
  52. }
  53. }
  54. },
  55. getDatas(special_id) {
  56. let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
  57. wx.showLoading({
  58. title: '加载中'
  59. });
  60. let self = this;
  61. console.log('fromSource =' + fromSource)
  62. getReq(app,{
  63. act: 'special',
  64. op: 'index',
  65. special_id: special_id,
  66. page: 10,
  67. curpage: 1,
  68. from: fromSource
  69. }, function (res) {
  70. if (res.code == 200) {
  71. console.log(res)
  72. let prop_special = res.datas.special_list;
  73. let sent_down_special = prop_special.splice(0, 8);
  74. self.setData({
  75. surplus_special: prop_special,
  76. prop_special: sent_down_special,
  77. special_datas: res.datas,
  78. summery: res.datas.summary,
  79. firstLoad: false,
  80. fromSource: app.globalData.fromSource
  81. });
  82. }
  83. setTimeout(function () {
  84. wx.hideLoading()
  85. }, 1000)
  86. })
  87. },
  88. req_tabs() {
  89. let self = this
  90. getReq(app,{
  91. act: 'index',
  92. op: 'tabs'
  93. }, function (res) {
  94. if (res.code == 200) {
  95. self.getDatas(res.datas.tabs[0].special_id);
  96. self.setData({
  97. tabs: res.datas.tabs,
  98. daliy_bonus: res.datas.daliy_bonus
  99. });
  100. }
  101. })
  102. },
  103. onMyEvent: function (e) {
  104. this.setData({
  105. prop_special: [],
  106. surplus_special: [],
  107. special_datas: {},
  108. summery: []
  109. });
  110. this.getDatas(e.detail.item.special_id)
  111. },
  112. closeTips() {
  113. this.setData({
  114. tipsFlag: false,
  115. tipsDatas: null
  116. })
  117. },
  118. onPageScroll(e) {
  119. clearTimeout(this.showTop);
  120. this.showTop = setTimeout(() => {
  121. let scrollTop = e.scrollTop;
  122. if (scrollTop >= 300) {
  123. this.setData({
  124. isScroll: true
  125. })
  126. }
  127. else {
  128. this.setData({
  129. isScroll: false
  130. })
  131. }
  132. }, 100);
  133. },
  134. backTop() {
  135. wx.pageScrollTo({
  136. scrollTop: 0,
  137. duration: 300
  138. })
  139. },
  140. onShareAppMessage: function () {
  141. console.log('index onShareAppMessage')
  142. let relay_id = 100
  143. return {
  144. title: `${app.globalData.channel}小程序`,
  145. path: "/pages/index/index?relay_id=${relay_id}"
  146. }
  147. },
  148. onReachBottom: function () {
  149. if (this.data.isSendProp) {
  150. return;
  151. }
  152. let surplus_special_num = this.data.surplus_special.length;
  153. if (surplus_special_num > 0) {
  154. wx.showLoading({
  155. title: '加载中'
  156. });
  157. this.setData({
  158. isSendProp: true
  159. });
  160. this.data.isSendProp = true;
  161. let prop_special = this.data.surplus_special;
  162. let sent_down_special = prop_special.splice(0, 8);
  163. this.setData({
  164. surplus_special: prop_special,
  165. prop_special: this.data.prop_special.concat(sent_down_special)
  166. })
  167. this.setData({
  168. isSendProp: false
  169. });
  170. setTimeout(function () {
  171. wx.hideLoading()
  172. }, 1500)
  173. }
  174. else {
  175. return;
  176. }
  177. }
  178. })