search.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. BeautyArchiveApi.setSearchKeywords({keyword: this.listQuery.name}, (res) => {
  26. if (res.code === 0) {
  27. console.log('搜索词统计成功')
  28. }
  29. })
  30. })
  31. this.getList()
  32. },
  33. mounted() {
  34. const self = this
  35. window.addEventListener('scroll', debounce(function () {
  36. const scrollTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
  37. if (document.body.scrollHeight <= window.screen.height + scrollTop) {
  38. console.log('已经滚动到底部了')
  39. if (!self.hasNextPage) return
  40. self.getList()
  41. }
  42. }))
  43. },
  44. methods: {
  45. filterList() {
  46. this.listQuery.pageNum = 1
  47. this.getList()
  48. },
  49. getList() {
  50. const self = this
  51. if (this.listQuery.pageNum > this.totalPage) {
  52. this.listQuery.pageNum = this.totalPage
  53. }
  54. if (this.listQuery.pageNum < 1) {
  55. this.listQuery.pageNum = 1
  56. }
  57. shopBikeApi.FetchEntryList(this.listQuery, function (res) {
  58. self.list = [...self.list, ...res.data.results]
  59. self.totalPage = res.data.totalPage
  60. self.hasNextPage = res.data.hasNextPage
  61. self.totalRecord = res.data.totalRecord
  62. self.listQuery.pageNum++
  63. })
  64. }
  65. }
  66. })