brand.js 3.9 KB

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