search.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const searchList = new Vue({
  2. el: '#searchList',
  3. data: {
  4. listQuery: {
  5. shopId: '',
  6. id: '', //词条id,
  7. name: '', //词条名称
  8. typeId: '', //分类id
  9. auditStatus: 2, //百科审核状态:1待审核,2审核通过,3审核失败
  10. onlineStatus: 2, //百科上线状态:1待上线,2已上线,3已下线
  11. status: '', //状态:0保存草稿箱,1已发布
  12. pageNum: 1, //页数
  13. pageSize: 10 //条数
  14. },
  15. totalPage: 0,
  16. totalRecord: 0,
  17. hasNextPage: false,
  18. list: [],
  19. },
  20. created() {
  21. this.listQuery.name = decodeURIComponent(CAIMEI.getUrlParam('keyword'))
  22. this.$nextTick(() => {
  23. $('#searchInput').val(this.listQuery.name)
  24. })
  25. this.getList()
  26. },
  27. mounted() {
  28. const self = this
  29. window.addEventListener('scroll', debounce(function () {
  30. const scrollTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
  31. if (document.body.scrollHeight <= window.screen.height + scrollTop) {
  32. console.log('已经滚动到底部了')
  33. if (!self.hasNextPage) return
  34. self.getList()
  35. }
  36. }))
  37. },
  38. methods: {
  39. filterList() {
  40. this.listQuery.pageNum = 1
  41. this.getList()
  42. },
  43. getList() {
  44. const self = this
  45. if (this.listQuery.pageNum > this.totalPage) {
  46. this.listQuery.pageNum = this.totalPage
  47. }
  48. if (this.listQuery.pageNum < 1) {
  49. this.listQuery.pageNum = 1
  50. }
  51. shopBikeApi.FetchEntryList(this.listQuery, function (res) {
  52. self.list = [...self.list, ...res.data.results]
  53. self.totalPage = res.data.totalPage
  54. self.hasNextPage = res.data.hasNextPage
  55. self.totalRecord = res.data.totalRecord
  56. self.listQuery.pageNum++
  57. })
  58. }
  59. }
  60. })