index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. let app = getApp();
  2. import recordSource from '../../utils/recordSource'
  3. const getReq = require('./../../config.js').getReq;
  4. Page({
  5. data: {
  6. tabs: [],
  7. prop_special: [],
  8. surplus_special: [],
  9. special_datas: {},
  10. summery: [],
  11. isScroll: false,
  12. isSendProp: false,
  13. firstLoad: true
  14. },
  15. onShow: function () {
  16. if (app.globalData.backLogin && !this.data.firstLoad) {
  17. app.globalData.backLogin = false;
  18. this.getDatas(0)
  19. }
  20. },
  21. onLoad: function () {
  22. this.getDatas(0)
  23. },
  24. getDatas(special_id) {
  25. let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
  26. // let fromSource = app.globalData.fromSource
  27. // let currentSource = new RecordSource('act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini').encode()
  28. // app.setFromSource(currentSource)
  29. wx.showLoading({
  30. title: '加载中'
  31. });
  32. let self = this;
  33. getReq({
  34. act: 'special',
  35. op: 'index',
  36. special_id,
  37. page: 10,
  38. curpage: 1,
  39. from: fromSource
  40. }, function (res) {
  41. if (res.code == 200) {
  42. let prop_special = res.datas.special_list;
  43. let sent_down_special = prop_special.splice(0, 8);
  44. self.setData({
  45. surplus_special: prop_special,
  46. prop_special: sent_down_special,
  47. special_datas: res.datas,
  48. summery: res.datas.summary,
  49. firstLoad: false
  50. });
  51. }
  52. setTimeout(function () {
  53. wx.hideLoading()
  54. }, 1000)
  55. })
  56. },
  57. req_tabs() {
  58. let self = this
  59. getReq({
  60. act: 'index',
  61. op: 'tabs'
  62. }, function (res) {
  63. if (res.code == 200) {
  64. self.getDatas(res.datas.tabs[0].special_id);
  65. // console.log(res.datas.tabs[0].special_id);
  66. // self.getDatas(1364);
  67. self.setData({
  68. tabs: res.datas.tabs
  69. });
  70. }
  71. })
  72. },
  73. onMyEvent: function (e) {
  74. this.setData({
  75. prop_special: [],
  76. surplus_special: [],
  77. special_datas: {},
  78. summery: []
  79. });
  80. this.getDatas(e.detail.item.special_id)
  81. },
  82. onPageScroll(e) {
  83. clearTimeout(this.showTop);
  84. this.showTop = setTimeout(() => {
  85. let scrollTop = e.scrollTop;
  86. if (scrollTop >= 300) {
  87. this.setData({
  88. isScroll: true
  89. })
  90. }
  91. else {
  92. this.setData({
  93. isScroll: false
  94. })
  95. }
  96. }, 100);
  97. },
  98. backTop() {
  99. wx.pageScrollTo({
  100. scrollTop: 0,
  101. duration: 300
  102. })
  103. },
  104. onShareAppMessage: function () {
  105. return {
  106. title: "熊猫美妆小程序",
  107. path: "/pages/index/index"
  108. }
  109. },
  110. onReachBottom: function () {
  111. if (this.data.isSendProp) {
  112. return;
  113. }
  114. let surplus_special_num = this.data.surplus_special.length;
  115. if (surplus_special_num > 0) {
  116. // wx.showLoading({
  117. // title: '加载中'
  118. // });
  119. this.setData({
  120. isSendProp: true
  121. });
  122. this.data.isSendProp = true;
  123. let prop_special = this.data.surplus_special;
  124. let sent_down_special = prop_special.splice(0, 8);
  125. this.setData({
  126. surplus_special: prop_special,
  127. prop_special: this.data.prop_special.concat(sent_down_special)
  128. })
  129. this.setData({
  130. isSendProp: false
  131. });
  132. // wx.hideLoading();
  133. }
  134. }
  135. })