<template>
  <el-drawer :visible.sync="drawer" :with-header="false" :custom-class="`${type}_drawer`" direction="rtl" append-to-body :show-close="false" v-on="$listeners">
    <div style="position: relative">
      <div class="lDrawer">
        <div id="lDrawer__header" class="lDrawer__header">
          <slot name="modalHeader" v-if="$slots.modalHeader"> </slot>
          <div class="lDrawer__header__title" v-else>
            <span class="lIcon" />
            {{ title }}
          </div>
        </div>

        <div class="lDrawer__content">
          <slot />
        </div>
        <div v-if="$slots.modalFooter" style="padding: 0 10px">
          <div class="lDrawer__footer">
            <slot name="modalFooter" />
          </div>
        </div>
        <div class="closeBtns" @click="drawer = false">
          <i class="el-icon-close" />
        </div>
      </div>
    </div>
  </el-drawer>
</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: '我是标题'
    }
  },
  data() {
    return {
      otherSelect: false,
      drawer: 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(item) {
      // debugger
      this.drawer = true
      this.$emit('afterShow', item)
      // console.log(123123123, this.$parent.$options.name, this.$ui)
    },
    hide() {
      this.drawer = 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';

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

  // margin-left: 36px;
  .closeBtns {
    cursor: pointer;
    width: 36px;
    height: 36px;
    background: $activeBg;
    border-radius: 18px 0px 0px 18px;
    position: absolute;
    left: -36px;
    top: 50%;
    text-align: center;
    line-height: 36px;
    color: #fff;
    margin-top: -18px;
  }
  &__content {
    flex: 1;
    overflow-y: auto;
    width: 100%;
    background: $bgColor;
    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;
    padding: 8px 0;
    // box-sizing: border-box;
  }
}
</style>
