brand.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. wx.setNavigationBarTitle({
  20. title: options.title ? options.title : "熊猫美妆"
  21. })
  22. wx.showLoading({
  23. title: '加载中',
  24. });
  25. const brand_id = options.brand_id ? options.brand_id : '';
  26. const hot_id = options.hot_id ? options.hot_id : '';
  27. const keyword = options.keyword ? options.keyword : '';
  28. const curpage = this.data.curpage;
  29. this.setData({
  30. hot_id,
  31. brand_id,
  32. keyword
  33. })
  34. let self = this;
  35. getReq({
  36. act: 'search',
  37. op: 'index',
  38. brand_id,
  39. hot_id,
  40. keyword,
  41. curpage
  42. }, function (res) {
  43. if (res.code == 200) {
  44. self.setData({
  45. special_datas: res.datas,
  46. summery: res.datas.summary,
  47. hasmore: res.datas.mobile_page.hasmore
  48. });
  49. wx.hideLoading();
  50. }
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. if(this.data.hasmore) {
  83. wx.showLoading({
  84. title: '加载中',
  85. });
  86. let self = this;
  87. getReq({
  88. act: 'search',
  89. op: 'index',
  90. brand_id: this.data.brand_id,
  91. hot_id: this.data.hot_id,
  92. keyword: this.data.keyword,
  93. curpage: this.data.curpage+1
  94. }, function (res) {
  95. if (res.code == 200) {
  96. let newDatas = res.datas;
  97. let newSummery = res.datas.summary;
  98. let oldDatas = self.data.special_datas;
  99. let oldSummery = self.data.summery;
  100. let buildDatas = (function(){
  101. let buildDatas = {};
  102. for (let i in oldDatas) {
  103. if (oldDatas[i] instanceof Array) {
  104. buildDatas[i] = oldDatas[i].concat(newDatas[i]);
  105. }
  106. }
  107. return buildDatas;
  108. })();
  109. let buildSummery = (function(){
  110. let buildDatas = [];
  111. buildDatas = oldSummery.concat(newSummery);
  112. return buildDatas;
  113. })();
  114. self.setData({
  115. curpage: self.data.curpage+1,
  116. special_datas: buildDatas,
  117. summery: buildSummery,
  118. hasmore: res.datas.mobile_page.hasmore
  119. });
  120. wx.hideLoading();
  121. }
  122. })
  123. }
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage: function () {
  129. }
  130. })