<template>
  <div class="drag-container">
    <div id="drag-container-top" class="drag-container-top">
      <slot name="top" />
    </div>
    <div id="drag-container-bar" class="drag-container-bar">
      <div>
        <slot name="bar" />
      </div>
      <div>
        <i class="iconfont icon-tuozhuai" />
      </div>
      <div />
    </div>
    <div id="drag-container-bottom" class="drag-container-bottom">
      <slot name="bottom" />
    </div>
  </div>
</template>

<script>
export default {
  mounted() {
    this.dragChangeHeight('drag-container-bar', 'drag-container-top', 'drag-container-bottom')
  },
  methods: {
    dragChangeHeight(drag, panel, panelB) {
      var dragEl = document.getElementById(drag)
      var panelEl = document.getElementById(panel)
      var panelBottom = document.getElementById(panelB)
      dragEl.onmousedown = function(ev) {
        var disH = panelEl.offsetHeight
        var disY = ev.clientY
        var disT = panelEl.offsetTop
        var b = ''

        document.onmousemove = function(ev) {
          panelEl.style.height = disH + (ev.clientY - disY) + 'px'
          panelBottom.style.height = `calc(100vh - 310px - ${panelEl.style.height})`
          // panelEl.style.top = disL - (ev.clientY - disY) + 'px'
        }

        document.onmouseup = function() {
          document.onmousemove = document.onmouseup = null
        }
        return false
      }
    },
    dragChangeWidth(drag, panel) {
      var dragEl = document.getElementById(drag)
      var panelEl = document.getElementById(panel)
      dragEl.onmousedown = function(ev) {
        var disW = panelEl.offsetWidth
        var disX = ev.clientX
        var disL = panelEl.offsetLeft
        var b = ''

        document.onmousemove = function(ev) {
          panelEl.style.width = disW + (ev.clientX - disX) + 'px'
          // panelEl.style.left = disL - (ev.clientX - disX) + 'px'
        }

        document.onmouseup = function() {
          document.onmousemove = document.onmouseup = null
        }
        return false
      }
    }
  }
}
</script>

<style scoped>
 .drag-container {
    /* height: 100vh; */
    width: 100%;
    display: flex;
    flex-direction: column;
  }
  .drag-container-top {
    width: 100%;
    height: 250px;
    background-color: #fff;
    overflow-y: auto;
  }
  .drag-container-bar {
    width: 100%;
    height: 40px;
    background-color: #F5F6F6;
    cursor: move;
    border: 1px solid #F5F6F6;
    border-right: 0px;
    border-left: 0px;
    line-height: 40px;
    font-size: 16px;
    color: #222931;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    /* margin-bottom: 20px; */
    z-index: 20;
  }
  .drag-container-bottom {
    width: 100%;
    flex: auto;
    background-color: #fff;
    height: calc(100vh - 560px);
    overflow-y: auto;
    z-index: 20;
    padding-top: 20px;
  }
</style>
