brand.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const getReq = require('./../../config.js').getReq;
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. special_datas: {},
  8. summery: [],
  9. hasmore:false,
  10. curpage:1,
  11. brand_id : '',
  12. hot_id:'',
  13. keyword:'',
  14. isScroll: false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. wx.setNavigationBarTitle({
  21. title: options.title ? options.title : "熊猫美妆"
  22. })
  23. wx.showLoading({
  24. title: '加载中',
  25. });
  26. const brand_id = options.brand_id ? options.brand_id : '';
  27. const hot_id = options.hot_id ? options.hot_id : '';
  28. const keyword = options.keyword ? options.keyword : '';
  29. const curpage = this.data.curpage;
  30. this.setData({
  31. hot_id,
  32. brand_id,
  33. keyword
  34. })
  35. let self = this;
  36. getReq({
  37. act: 'search',
  38. op: 'index',
  39. brand_id,
  40. hot_id,
  41. keyword,
  42. curpage
  43. }, function (res) {
  44. if (res.code == 200) {
  45. self.setData({
  46. special_datas: res.datas,
  47. summery: res.datas.summary,
  48. hasmore: res.datas.mobile_page.hasmore
  49. });
  50. wx.hideLoading();
  51. }
  52. })
  53. },
  54. onPageScroll(e) {
  55. clearTimeout(this.showTop);
  56. this.showTop = setTimeout(() => {
  57. let scrollTop = e.scrollTop;
  58. if (scrollTop >= 300) {
  59. this.setData({
  60. isScroll: true
  61. })
  62. }
  63. else {
  64. this.setData({
  65. isScroll: false
  66. })
  67. }
  68. }, 100);
  69. },
  70. backTop() {
  71. wx.pageScrollTo({
  72. scrollTop: 0,
  73. duration: 300
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. if(this.data.hasmore) {
  106. wx.showLoading({
  107. title: '加载中',
  108. });
  109. let self = this;
  110. getReq({
  111. act: 'search',
  112. op: 'index',
  113. brand_id: this.data.brand_id,
  114. hot_id: this.data.hot_id,
  115. keyword: this.data.keyword,
  116. curpage: this.data.curpage+1
  117. }, function (res) {
  118. if (res.code == 200) {
  119. let newDatas = res.datas;
  120. let newSummery = res.datas.summary;
  121. let oldDatas = self.data.special_datas;
  122. let oldSummery = self.data.summery;
  123. let buildDatas = (function(){
  124. let buildDatas = {};
  125. for (let i in oldDatas) {
  126. if (oldDatas[i] instanceof Array) {
  127. buildDatas[i] = oldDatas[i].concat(newDatas[i]);
  128. }
  129. }
  130. return buildDatas;
  131. })();
  132. let buildSummery = (function(){
  133. let buildDatas = [];
  134. buildDatas = oldSummery.concat(newSummery);
  135. return buildDatas;
  136. })();
  137. self.setData({
  138. curpage: self.data.curpage+1,
  139. special_datas: buildDatas,
  140. summery: buildSummery,
  141. hasmore: res.datas.mobile_page.hasmore
  142. });
  143. wx.hideLoading();
  144. }
  145. })
  146. }
  147. }
  148. })