index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/searchGood/index.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '搜索商品',
  12. 'color': false
  13. },
  14. host_product:[],
  15. searchValue:'',
  16. focus:true,
  17. bastList:[],
  18. hotSearchList:[],
  19. first: 0,
  20. limit: 8,
  21. page:1,
  22. loading:false,
  23. loadend:false,
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. },
  30. getRoutineHotSearch: function () {
  31. var that = this;
  32. app.baseGet(app.U({ c: 'store_api', a: "get_routine_hot_search", }), function (res) {
  33. that.setData({ hotSearchList: res.data });
  34. });
  35. },
  36. getProductList:function(){
  37. var that = this;
  38. if(this.data.loading) return;
  39. if(this.data.loadend) return;
  40. this.setData({loading:true,loadTitle:'正在搜索'});
  41. app.baseGet(app.U({ c: 'store_api', a: "goods_search", q:
  42. {
  43. keyword: that.data.searchValue,
  44. page:this.data.page,
  45. limit:this.data.limit
  46. }
  47. }), function (res) {
  48. wx.hideLoading();
  49. var list = res.data, loadend = list.length < that.data.limit;
  50. that.data.bastList = app.SplitArray(list, that.data.bastList);
  51. that.setData({
  52. bastList: that.data.bastList,
  53. loading:false,
  54. loadend: loadend,
  55. page:that.data.page+1,
  56. loadTitle: loadend ? '已全部加载': '加载更多',
  57. });
  58. },function(){
  59. wx.hideLoading();
  60. that.setData({ loading: false, loadTitle:"加载更多"});
  61. });
  62. },
  63. getHostProduct: function () {
  64. var that = this;
  65. app.baseGet(app.U({ c: 'public_api', a: "get_hot_product", q: { offset: 1, limit: 4 } }), function (res) {
  66. that.setData({ host_product: res.data });
  67. });
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. setHotSearchValue: function (event) {
  75. this.setData({ searchValue: event.currentTarget.dataset.item });
  76. this.getProductList();
  77. },
  78. setValue: function (event){
  79. this.setData({ searchValue: event.detail.value});
  80. },
  81. searchBut:function(){
  82. var that = this;
  83. if (that.data.searchValue.length > 0){
  84. that.setData({ page: 1, loadend: false, bastList:[]});
  85. wx.showLoading({ title:'正在搜索中'});
  86. that.getProductList();
  87. }else{
  88. wx.showToast({
  89. title: '请输入要搜索的商品',
  90. icon: 'none',
  91. duration: 1000,
  92. mask: true,
  93. })
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. this.getRoutineHotSearch();
  101. this.getHostProduct();
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function () {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function () {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. this.getProductList();
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {
  128. }
  129. })