<template>
  <!-- 移动端上拉加载更多 -->
  <!--<a @click="scrollToTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>-->
</template>
<script>
//  import { scrollTo } from '~utils/scroll'
  export default {
    data () {
      return {
        hideToTop: true
      }
    },
    props: {
      searchMore: {
        type: Boolean
      },
      allPage: {
        type: Number
      },
      page: {
        type: Number
      },
      fixId: {
        type: String,
        default: null
      },
      isValid: {
        type: Boolean,
        default: true
      }
    },
    mounted () {
      let _this = this
      _this.$nextTick(function () {
        let obj = this.fixId ? document.getElementById(this.fixId) : window
        if (obj) {
          obj.addEventListener('scroll', function () {
            if (_this.isValid) {
              _this.scroll()
            }
          }, false)
        }
      })
    },
    methods: {
      scroll: function () {
        let scrolled = 0
        let height = 0
//        console.log(document.getElementById(this.fixId).scrollHeight)
//        console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
        if (this.fixId) {
          let obj = document.getElementById(this.fixId)
          height = obj.scrollHeight
          let _scrollHeight = 0.88
          if (this.$route.fullPath.indexOf('order') > -1) {
            _scrollHeight = 1.26
          }
          scrolled = obj.scrollTop - document.body.scrollWidth / 750 * 100 * _scrollHeight
        } else {
          height = document.body.scrollHeight
          scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
        }
//        this.hideToTop = scrolled <= window.screen.availHeight
//        console.log(this.hideToTop)
//        console.log(this.allPage)
//        console.log(this.page)
        if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
          this.getMore()
        }
      },
      getMore: function () {
        if (!this.searchMore) {
          this.$emit('pullUpAction')
        }
      },
      scrollToTop () {
//        console.log(1)
        let el = document.querySelector('.mobile-fix-content')
        if (el) {
          el.scrollTop = 0
        }
//        console.log(el.scrollTop)
//        scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
      }
    }
  }
</script>
<style lang="scss" scoped>
  a {
    position: fixed;
    right: .1rem;
    bottom: 1.1rem;
    background: rgba(0,0,0,.4);
    color: #fff;
    width: .88rem;
    height: .88rem;
    line-height: .88rem;
    border-radius: 100%;
    text-align: center;
    i {
      font-size: .46rem;
    }
  }
</style>
