searchList.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var Util = require('../../utils/util.js');
  2. var host = getApp().globalData.servsers;
  3. // 热销新品
  4. Page({
  5. data: {
  6. contentList: [],
  7. commodity_name: '',
  8. page: 0, // 默认第一页
  9. limit: 10, // 每页请求最多数据
  10. requestState:true, //表示还可以请求
  11. loginStatic: false, //登陆状态,默认为false
  12. },
  13. onShow(){
  14. let that = this;
  15. if (wx.getStorageSync('channelIdObj').channelId) {
  16. that.setData({
  17. loginStatic: true,
  18. })
  19. }
  20. },
  21. //滚动到底部触发事件
  22. /**
  23. * 页面上拉触底事件的处理函数
  24. */
  25. onReachBottom: function () {
  26. let that = this;
  27. if (that.data.requestState){
  28. that.setData({
  29. page:that.data.page + 1
  30. })
  31. that.getSearchList(that)
  32. }
  33. },
  34. searResult(e){
  35. console.log(e,"dd")
  36. let that = this;
  37. that.setData({
  38. commodity_name: e.detail.value,
  39. contentList: [],//数据初始化
  40. requestState:true, //数据初始化
  41. page: 0,//数据初始化
  42. })
  43. that.getSearchList(that)
  44. },
  45. getSearchList(that){
  46. if (that.data.commodity_name){
  47. let data = {
  48. commodity_name: that.data.commodity_name,
  49. offset: that.data.page,
  50. limit: that.data.limit,
  51. channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
  52. }
  53. wx.request({
  54. url: host + "commodityapi/findAllforseach",
  55. data: data,
  56. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  57. header: {
  58. 'Accept': 'application/json'
  59. },
  60. success: function (res) {
  61. let contentList = that.data.contentList;
  62. contentList.push(...res.data.rows)
  63. that.setData({
  64. contentList: contentList ,
  65. commodity_name: that.data.commodity_name,
  66. requestState: res.data.rows.length == that.data.limit
  67. });
  68. if (res == null || res.data == null) {
  69. console.error('网络请求失败');
  70. return;
  71. }
  72. }
  73. });
  74. } else {
  75. wx.showToast({
  76. title: "没有搜索关键词",
  77. icon:'none'
  78. })
  79. }
  80. },
  81. toGoodsDetail(e) { // 进入商品详情页
  82. let that = this, id = e.currentTarget.dataset.id;
  83. wx.navigateTo({
  84. url: '/pages/buy/buy?com_id=' + id,
  85. })
  86. },
  87. })