index.js 3.3 KB

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