export default {
  data(){
    return{
      id:'table',
      // 默认最大高度
      scrollY: 200,   //高度
      tableHeight: document.body.clientHeight,
      showSearch: true,
      // searchH:0
    }
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.scrollY=this.getTableScroll()
      })()
    };
    window.addEventListener('resize', () => {
      this.scrollY=this.getTableScroll()
    })
    this.scrollY=this.getTableScroll()
  },
  // computed:{
  //   scrollY(){
  //     return this.getTableScroll()
  //   }
  // },
  watch: {
    tableHeight(val) {
      console.log("实时屏幕高度：", val, this.scrollY);
      // this.scrollY=this.getTableScroll()
      // console.log(this.scrollY,'scrollY')
    },
    toggleFormTag(val) {
      this.$nextTick(() => {
        this.scrollY = this.getTableScroll()
      })
    },
    isShow(val) {
      this.$nextTick(() => {
        this.scrollY = this.getTableScroll()
      })
    }

  },
  methods: {
    getTableScroll(extraHeight = this.extraHeight, id = this.id) {
      if (typeof extraHeight == "undefined") {
        //  默认底部分页60 + 边距18
        extraHeight = 118
      }
      let tHeader = null
      if (id) {
        tHeader = document.getElementById(id)?.getElementsByClassName("ant-table-thead")?.[0] || null
      } else {
        tHeader = document.getElementsByClassName("ant-table-thead")[0]
      }
      //表格内容距离顶部的距离
      let tHeaderBottom = 0
      if (tHeader) {
        tHeaderBottom = tHeader.getBoundingClientRect().bottom
      }
      let height = document.body.clientHeight - (tHeaderBottom + extraHeight)
      // console.log(height,22)
      // 添加最小高度
      if (height < 200) {
        height = 200
      }
      return height
    },
    changeShow(val){
      // console.log(val)
      this.$nextTick(() => {
        this.scrollY = this.getTableScroll()
      })
    },
  }
}

