index.js 3.9 KB

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