<template>
  <el-dialog :visible.sync="dialog" top="6vh" :title="title" append-to-body :show-close="$slots.modalHeader ? false : true" :width="width" :destroy-on-close="destroyed" v-on="$listeners">
    <div class="relative">
      <div class="lModal">
        <div id="lModal__header" class="lModal__header">
          <slot name="modalHeader" />
        </div>

        <div class="lModal__content">
          <slot />
        </div>
        <div v-if="$slots.modalFooter" style="padding: 0 10px">
          <div class="lModal__footer">
            <slot name="modalFooter" />
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>
<script>
// 1200   832
import style from '~/style/e-variables.scss'
export default {
  name: 'Workbench',
  components: {},
  props: {
    type: {
      type: String,
      default: 'normal'
    },
    title: {
      type: String,
      default: '我是标题'
    },
    width: {
      type: String,
      default: '50%'
    },
    destroyed: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      otherSelect: false,
      dialog: false,
      bindProps: {},
      h: 0,
      customH: 0,
      searchH: 0
    }
  },
  created() {
    const that = this

    const pname = this.$parent.$options.name
    // debugger
    this.$ui.addQueue(pname, {
      show: that.show,
      hide: that.hide
    })
  },
  destroyed() {
    const pname = this.$parent.$options.name
    this.$ui.removeQueue(pname)
    // console.log(123123123, this.$parent.$options.name, this.$ui)
  },
  methods: {
    show() {
      // debugger
      this.dialog = true
      console.log(123123123, this.$parent.$options.name, this.$ui)
    },
    hide() {
      this.dialog = false
    },
    handleClose() {},
    init() {
      const that = this
      const h = window.innerHeight
      this.$nextTick(() => {
        const customH = document.querySelector('#container__header').offsetHeight

        that.customH = customH
        that.h = `${h - style.headerHeightNum - style.breadheightNum - customH - 48}px`
        const searchH = document.querySelector('#container__searchBar').offsetHeight

        that.searchH = searchH

        // console.log(123, customH, searchH, h)
      })
    },
    getScroll(e) {
      const scrollTop = window.modalYOffset || document.documentElement.scrollTop || document.body.scrollTop

      // console.log(scrollTop)
      if (scrollTop >= this.searchH - 2) {
        // debugger
        this.bindProps = {
          height: this.h
        }
        // console.log(window.innerHeight, style.headerHeightNum, style.breadheightNum)
      } else {
        this.bindProps = {}
      }
    },

    // 刷新
    refresh() {
      setTimeout(() => {
        this.resetBtn()
      }, 100)
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~/style/e-variables.scss';

.lModal {
  width: 100%;
  height: 100%;
  // padding: 0 10px;
  background: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 80vh;
  overflow-y: hidden;

  &__content {
    flex: 1;
    overflow-y: auto;
    width: 100%;
    background: #fff;
    padding-bottom: 48px;
    // padding: 0 10px;
    // background: green;
    // overflow: hidden;
    // .el-scrollbar {
    //   width: 100%;
    //   height: 100%;
    //   overflow-y: auto;
    // }
  }
  &__header {
    z-index: 10;
    right: 10px;
    background: #fff;
    box-sizing: border-box;
    width: auto;
    line-height: 50px;
    box-shadow: 0 5px 10px #eee;

    &__title {
      font-size: 16px;
      font-weight: bold;
      color: #333333;
      line-height: 50px;
      padding: 0 20px;
      position: relative;
      .lIcon {
        padding: 0 2px;
        // width: 4px;
        height: 18px;
        background: $activeBg;
        margin-right: 10px;
      }
    }
  }

  &__footer {
    // max-height: 52px;
    background: #fff;
    box-sizing: border-box;
    align-items: center;
    text-align: right;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    height: 48px;
    // box-sizing: border-box;
  }
}
</style>

<style lang="scss">
@import '~/style/e-variables.scss';
.relative {
  position: relative;
  width: 100%;
  // height: 100%;
  max-height: 85vh;
  overflow: hidden;
}

.el-dialog__body {
  padding: 0 10px !important;
  // max-height: calc(100vh - 200px);
}

.el-dialog__header {
  border-bottom: 1px solid #e6e6e6;
  height: 53px;
  line-height: 53px;
  padding: 0px !important;

  .el-dialog__title {
    font-size: 18px;
    font-family: Source Han Sans SC;
    font-weight: bold;
    color: #333333;
    height: 18px !important;
    line-height: 18px !important;
    margin-left: 10px;

    &::before {
      content: '';
      display: inline-block;
      vertical-align: middle;
      width: 4px;
      height: 18px;
      line-height: 18px !important;
      background: $activeBg;
      margin-right: 10px;
    }
  }
}
</style>
