PullUp.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <!-- 移动端上拉加载更多 -->
  3. <!--<a @click="scrollToTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>-->
  4. </template>
  5. <script>
  6. // import { scrollTo } from '~utils/scroll'
  7. export default {
  8. data () {
  9. return {
  10. hideToTop: true
  11. }
  12. },
  13. props: {
  14. searchMore: {
  15. type: Boolean
  16. },
  17. allPage: {
  18. type: Number
  19. },
  20. page: {
  21. type: Number
  22. },
  23. fixId: {
  24. type: String,
  25. default: null
  26. },
  27. isValid: {
  28. type: Boolean,
  29. default: true
  30. }
  31. },
  32. mounted () {
  33. let _this = this
  34. _this.$nextTick(function () {
  35. let obj = this.fixId ? document.getElementById(this.fixId) : window
  36. obj.addEventListener('scroll', function () {
  37. if (_this.isValid) {
  38. _this.scroll()
  39. }
  40. }, false)
  41. })
  42. },
  43. methods: {
  44. scroll: function () {
  45. let scrolled = 0
  46. let height = 0
  47. // console.log(document.getElementById(this.fixId).scrollHeight)
  48. // console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
  49. if (this.fixId) {
  50. let obj = document.getElementById(this.fixId)
  51. height = obj.scrollHeight
  52. let _scrollHeight = 0.88
  53. if (this.$route.fullPath.indexOf('order') > -1) {
  54. _scrollHeight = 1.26
  55. }
  56. scrolled = obj.scrollTop - document.body.scrollWidth / 750 * 100 * _scrollHeight
  57. } else {
  58. height = document.body.scrollHeight
  59. scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  60. }
  61. // this.hideToTop = scrolled <= window.screen.availHeight
  62. // console.log(this.hideToTop)
  63. // console.log(this.allPage)
  64. // console.log(this.page)
  65. if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
  66. this.getMore()
  67. }
  68. },
  69. getMore: function () {
  70. if (!this.searchMore) {
  71. this.$emit('pullUpAction')
  72. }
  73. },
  74. scrollToTop () {
  75. // console.log(1)
  76. let el = document.querySelector('.mobile-fix-content')
  77. if (el) {
  78. el.scrollTop = 0
  79. }
  80. // console.log(el.scrollTop)
  81. // scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. a {
  88. position: fixed;
  89. right: .1rem;
  90. bottom: 1.1rem;
  91. background: rgba(0,0,0,.4);
  92. color: #fff;
  93. width: .88rem;
  94. height: .88rem;
  95. line-height: .88rem;
  96. border-radius: 100%;
  97. text-align: center;
  98. i {
  99. font-size: .46rem;
  100. }
  101. }
  102. </style>