export default {
    props: {
      // 给定一个固定的高度，优先级高
      height: {
        type: Number,
        default: 0
      },
      // 自动计算高度，优先级中
      autoHeight: {
        type: Boolean,
        default: true
      },
      // 给的一个去除的额外高度，会自动计算表格高度，优先级低
      screenExtraHeight: {
        type: Number,
        default: 110
      },
      // 列表之外的高度
      extraHeight: {
        type: Number,
        default: 82
      },
    },
    data() {
      return {
        // 屏幕高度
        screenHeight: 0,
        // 当前组件高度
        currentHeight: 0,
        
      };
    },
    computed: {
      tableHeight() {
        if (this.height > 0) {
          return this.height - this.extraHeight;
        }
        if (this.autoHeight) {
          return this.currentHeight - this.extraHeight;
        }
        if (this.screenExtraHeight > 0) {
          return this.screenHeight - this.screenExtraHeight - this.extraHeight;
        }
        return '';
      }
    },
    created() {
      window.addEventListener("resize", this.screenResize);
    },
    destroyed() {
      window.removeEventListener("resize", this.screenResize);
    },
    mounted() {
      this.screenResize();
    },
    methods: {
      // 屏幕大小变化
      screenResize() {
        this.screenHeight = document.documentElement.clientHeight || document.body.clientHeight;
        this.$nextTick(() => {
          this.currentHeight = this.$refs.list.offsetHeight;
        });
        
      },
    }
  };