index.js 2.9 KB

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