index.js 3.1 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. 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. let prop_special = res.datas.special_list;
  41. let sent_down_special = prop_special.splice(0, 8);
  42. self.setData({
  43. surplus_special: prop_special,
  44. prop_special: sent_down_special,
  45. special_datas: res.datas,
  46. summery: res.datas.summary,
  47. firstLoad: false,
  48. fromSource: app.globalData.fromSource
  49. });
  50. }
  51. setTimeout(function () {
  52. wx.hideLoading()
  53. }, 1000)
  54. })
  55. },
  56. req_tabs() {
  57. let self = this
  58. getReq({
  59. act: 'index',
  60. op: 'tabs'
  61. }, function (res) {
  62. if (res.code == 200) {
  63. self.getDatas(res.datas.tabs[0].special_id);
  64. self.setData({
  65. tabs: res.datas.tabs
  66. });
  67. }
  68. })
  69. },
  70. onMyEvent: function (e) {
  71. this.setData({
  72. prop_special: [],
  73. surplus_special: [],
  74. special_datas: {},
  75. summery: []
  76. });
  77. this.getDatas(e.detail.item.special_id)
  78. },
  79. onPageScroll(e) {
  80. clearTimeout(this.showTop);
  81. this.showTop = setTimeout(() => {
  82. let scrollTop = e.scrollTop;
  83. if (scrollTop >= 300) {
  84. this.setData({
  85. isScroll: true
  86. })
  87. }
  88. else {
  89. this.setData({
  90. isScroll: false
  91. })
  92. }
  93. }, 100);
  94. },
  95. backTop() {
  96. wx.pageScrollTo({
  97. scrollTop: 0,
  98. duration: 300
  99. })
  100. },
  101. onShareAppMessage: function () {
  102. return {
  103. title: "熊猫美妆小程序",
  104. path: "/pages/index/index"
  105. }
  106. },
  107. onReachBottom: function () {
  108. if (this.data.isSendProp) {
  109. return;
  110. }
  111. let surplus_special_num = this.data.surplus_special.length;
  112. if (surplus_special_num > 0) {
  113. wx.showLoading({
  114. title: '加载中'
  115. });
  116. this.setData({
  117. isSendProp: true
  118. });
  119. this.data.isSendProp = true;
  120. let prop_special = this.data.surplus_special;
  121. let sent_down_special = prop_special.splice(0, 8);
  122. this.setData({
  123. surplus_special: prop_special,
  124. prop_special: this.data.prop_special.concat(sent_down_special)
  125. })
  126. this.setData({
  127. isSendProp: false
  128. });
  129. setTimeout(function () {
  130. wx.hideLoading()
  131. }, 1500)
  132. }
  133. else {
  134. return;
  135. }
  136. }
  137. })