index.js 3.9 KB

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