search-result.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. doArrow(e) {
  30. const index = e.currentTarget.dataset.index;
  31. const list = this.data.list;
  32. this.setData({
  33. [`list[${index}].up`]: !list[index].up
  34. })
  35. },
  36. //获取列表数据
  37. fetchList() {
  38. if (!this.data.isScroll) {
  39. return false
  40. }
  41. let paramsObj = {
  42. pageNo: this.data.pageNo,
  43. searchName: this.data.keyWord,
  44. }
  45. getSearchList(paramsObj).then(data => {
  46. var pageNo = data.data.pageNo;
  47. let setData = {};
  48. // 是否可以滚动加载数据
  49. if (data.data.isLast) {
  50. setData.isScroll = false
  51. }
  52. if (data.data.searchPosition.length != 0) {
  53. setData.list = this.data.list.concat(data.data.searchPosition)
  54. setData.pageNo = pageNo;
  55. } else {
  56. setData.list = this.data.list;
  57. }
  58. this.setData({
  59. ...setData
  60. })
  61. })
  62. },
  63. onReachBottom: function() {
  64. var pageNo = this.data.pageNo + 1;
  65. this.setData({
  66. pageNo
  67. })
  68. this.fetchList();
  69. },
  70. //去详情页
  71. toDetail(e) {
  72. const {
  73. id,
  74. cate
  75. } = e.currentTarget.dataset
  76. wx.navigateTo({
  77. url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
  78. })
  79. },
  80. })