index.js 2.7 KB

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