index.js 3.1 KB

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