export default {
  bind(el, binding) {
    const odiv = el // 获取当前元素
    console.log(odiv)
    odiv.onmousedown = e => {
      console.log('??鼠标按下了')
      // 算出鼠标相对元素的位置
      const disX = e.clientX - odiv.offsetLeft
      const disY = e.clientY - odiv.offsetTop
      // const moveWrapDom = document.getElementById(binding.value)

      document.onmousemove = function(e) {
        // 用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
        const left = e.clientX - disX
        const top = e.clientY - disY
        if (top > window.screen.availHeight - this.selfHeight) {
          this.positionX = window.screen.availHeight - this.selfHeight
          return
        }
        if (left > window.screen.availHeight - this.selfWidth) {
          this.positionY = window.screen.availHeight - this.selfWidth
          return
        }

        // 绑定元素位置到positionX和positionY上面
        this.positionX = top
        this.positionY = left

        // 移动当前元素
        odiv.style.left = left + 'px'
        odiv.style.top = top + 'px'
      }
      document.onmouseup = function(e) {
        document.onmousemove = null
        document.onmouseup = null
      }
    }
  }
}
