search-result.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {
  2. getSearchList
  3. } from '../../services/index.js'
  4. import {
  5. imgServerUrl,
  6. imgServerUrl_new
  7. } from '../../config/config.js'
  8. const app = getApp();
  9. Page({
  10. data: {
  11. imgServerUrl: imgServerUrl,
  12. keyWord: '',
  13. pageNo: 1, //当前分页
  14. isScroll: true, //是否可以滚动
  15. list: [],
  16. cityName: '',
  17. showNoMore: "没有更多信息...", //显示已无更多
  18. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  19. },
  20. onLoad: function(options) {
  21. let {
  22. searchVal
  23. } = options
  24. this.setData({
  25. keyWord: searchVal
  26. })
  27. this.fetchList()
  28. },
  29. //获取列表数据
  30. fetchList() {
  31. if (!this.data.isScroll) {
  32. return false
  33. }
  34. let paramsObj = {
  35. pageNo: this.data.pageNo,
  36. searchName: this.data.keyWord,
  37. }
  38. getSearchList(paramsObj).then(data => {
  39. var pageNo = data.data.pageNo;
  40. let setData = {};
  41. // 是否可以滚动加载数据
  42. if (data.data.isLast) {
  43. setData.isScroll = false
  44. }
  45. if (data.data.searchPosition.length != 0) {
  46. setData.list = this.data.list.concat(data.data.searchPosition)
  47. setData.pageNo = pageNo;
  48. } else {
  49. setData.list = this.data.list;
  50. }
  51. this.setData({
  52. ...setData
  53. })
  54. })
  55. },
  56. onReachBottom: function() {
  57. var pageNo = this.data.pageNo + 1;
  58. this.setData({
  59. pageNo
  60. })
  61. this.fetchList();
  62. },
  63. onShareAppMessage: function(e) {
  64. console.log(e)
  65. },
  66. //去详情页
  67. toDetail(e) {
  68. const {
  69. id,
  70. cate
  71. } = e.currentTarget.dataset
  72. wx.navigateTo({
  73. url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
  74. })
  75. },
  76. })