<template>
  <div id="app">
    <router-view />
    <div id="absoParent" v-if="$route.path != '/login'" v-drag  class="absoParent1">
      <div id="abso" class="abso1" >
          <span style="">
              <i class="el-icon-edit icon"></i>
            <span class="mouseEnter" style="cursor: pointer;">意见反馈</span>
          </span>
      </div>
    </div>
    
    <feedback ref="feedback"></feedback>

    <div class="caidan" style ="display:none;"  v-if="$permission('/workspace/scratchWords')">
          <div style="display: flex;align-items: center;">
                <div class="dropbtn" :style='{"background-color":mark.color,"border-radius":"50%","width":"12px","height":"12px","margin-top":"1px"}'>
                  <el-input type="color" v-model="mark.color"  style="opacity: 0;user-select:none;" @input="changeColor()"/>
                </div>
                &NonBreakingSpace;&NonBreakingSpace;&NonBreakingSpace;
                <div style="font-size: 14px;font-weight: 500;">
                  <span @click="handleRadioClick(2)" style="margin:0 10px">波浪线</span>
                  <span @click="handleRadioClick(0)" style="margin:0 10px">下划线</span>
                  <span @click="handleRadioClick(1)" style="margin:0 10px">高亮</span>
                </div>
                &NonBreakingSpace;&NonBreakingSpace;
                <a onclick="pizhu()" style="font-size: 14px;font-weight: 500;"> 批注</a>
                &NonBreakingSpace;&NonBreakingSpace;
                <a v-if="mark.id" @click="hiddenPiZhuDelete" style="font-size: 14px;font-weight: 500;">删除</a>
                &NonBreakingSpace;&NonBreakingSpace;
          </div>
    </div>
    <pizhu :gaoLiangCaiDan="gaoLiangCaiDan" :piZhuDelete="piZhuDelete"></pizhu>
  </div>
</template>

<script>
import feedback from "@/views/feedback/components/feedback.vue";
import pizhu from "@/views/workspace/gaoliang/components/pizhu.vue";
export default {
  name: 'app',
  components: {
    feedback,
    pizhu,
  },
  data() {
    return {
      height: (document.documentElement.clientHeight) + 'px',
      gaoLiangCaiDan:false,
      piZhuDelete:false,
    }
  },
  computed:{
    mark() {
      return this.$store.state.patent.index || {
        rangeType:[]
      }
    },
  },
  created() {
  },
  mounted() {
    var time = new Date(this.$c.updateTime).getTime()
    var time2 = new Date().getTime()
    if(time2 < time && !localStorage.canShow){
        this.$router.push({path: '/'})
        return false
    }
    document.addEventListener('mousedown',function(e){
      let btn = document.getElementsByClassName("caidan");
      let box = document.getElementsByClassName('pizhu')
      if(btn[0].style.display!='none'){
        if ( !btn[0].contains(e.target)) {
          btn[0].setAttribute("style", "display:none;");
        }
      }else{
        // if ( !box[0].contains(e.target)) {
        //   box[0].setAttribute("style", "display:none;");
        // }
      }
      
    })
  },
  methods: {
    feedback() {
      this.$refs.feedback.open()
    },
    changeColor(){},
    changeRadio(val) {
      this.mark.scratchType = val
      // 仅自己可见仅本专题可见
      this.mark.permissionType=0
      this.mark.rangeType =this.mark.rangeId? true:false
      this.gaoLiangCaiDan = !this.gaoLiangCaiDan
      this.handleCaiDan()
    },
    // 在el-radio-group无法对默认项点击
    handleRadioClick(val) {
      this.changeRadio(val)
    },
    handleCaiDan() {
      let btn = document.getElementsByClassName("caidan");
      if(btn[0].style.display!='none'){
        btn[0].setAttribute("style", "display:none;");
      }
    },
    hiddenPiZhuDelete() {
      this.piZhuDelete = !this.piZhuDelete
      this.handleCaiDan()
    },
  },
    //注册局部组件指令
    directives: {
    drag: function (el,data,vnode) {
      let dragBox = el; //获取当前元素
      // 当前页面可视区的高
      let clientHeight = document.documentElement.clientHeight 
      dragBox.onmousedown = e => {
        //算出鼠标相对元素的位置
        let disX = e.clientX - dragBox.offsetLeft;
        let disY = dragBox.offsetTop - e.clientY;
        // let disY = e.clientY - dragBox.offsetTop;
        document.onmousemove = e => {
          if ( e.stopPropagation ) {
            e.stopPropagation()
          }
          if ( e.preventDefault ) {
            e.preventDefault()
          }
          //用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
          let left = disX + 100 +'px';
          let top = -(clientHeight - e.clientY);
          if (top > -50) {
            top=-50
          } else if (top < -clientHeight) {
            top = -clientHeight
          }
          // let left = e.clientX - disX;
          // let top = e.clientY - disY;
          //移动当前元素
          dragBox.style.left = left + "px";
          dragBox.style.top = top + "px";
        };
        document.onmouseup = e2 => {
          //鼠标弹起来的时候不再移动
          document.onmousemove = null;
          //预防鼠标弹起来后还会循环（即预防鼠标放上去的时候还会移动）  
          document.onmouseup = null;
          if ( e.clientX == e2.clientX && e.clientY == e2.clientY ) {
            vnode.context.feedback()//想要添加的元素的点击事件
          }
        };
      };
    }
  }
}
</script>
<style lang="less">
.opinion .el-form-item{
  margin-bottom: 10px;
  .el-form-item__content,.el-form-item__label{
    line-height: normal;
    min-height: 30px;
  }
}
.caidan{
  user-select:none;
  a{
    user-select:none;
    cursor: pointer;
  }
  
}
</style>
<style lang="scss">

.showPiZhu{
  position: absolute;
  background: rgb(255 249 199);
  left:0;
  width:200px;
  box-shadow: 5px 5px 5px rgb(227, 227, 75);
  padding: 5px;
  border-radius: 5px;
}
.pizhuLightHeigh{
  position: relative;
  background: #409EFF !important;
}

.greenColor{
  background: #409EFF !important;
}

   .jinzhi{
    cursor: not-allowed;
    pointer-events:none;
  }
  .el-dropdown .el-button-group .el-button--primary:first-child{
    padding: 0;
    p{
      margin: 0;
      min-width: 50px;
      line-height: 30px;
      height: 30px;
      padding: 0 10px;
    }
  }
  </style>
<style lang="less">
.cursor_pointer{
  cursor:pointer
}
textarea {
  font-family: 微软雅黑;
}
html, body, #app {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background: #f4f4f4;
}
.margin-left_0 {
  margin-left: 0 !important;
}
.margin-top_10 {
  margin-top: 10px !important;
}
.margin-left_10 {
  margin-left: 10px !important;
}
.padding-left_10 {
  padding-left: 10px;
}
.padding-right_10 {
  padding-right: 10px;
}
.margin-left_20 {
  margin-left: 20px;
}
.container-white-no-padding {
  background: #fff !important;
  padding: 0 !important;
}
.container-common-main {
  background: #fff;
  padding: 5px 20px !important;
  margin-top: 20px !important;
}
.footer-common {
  height: 70px !important;
  text-align: right;
}
.margin-right_20 {
  margin-right: 20px !important;
}
.width_100 {
  width: 100% !important;
}
.margin-bottom_10 {
  margin-bottom: 10px;
}
.float_right {
  float: right
}
.float_left {
  float: left;
}
.color-red {
  color: red !important;
}
.color-black {
  color: black;
}
.padding_0_5 {
  padding: 0 5px;
}
.color-primary {
  color: #409eff;
}
.margin-right_10 {
  margin-right: 10px !important;
}
.text-align_center {
  text-align: center !important;
}
.position_relative {
  position: relative;
}
.no-body-padding-dialog {
  .el-dialog__body {
    padding: 0 !important;
  }
}
.custom-table-header > th {
  word-break: break-word;
  background-color: #f8f8f9 !important;
  color: #515a6e;
  height: 40px;
  font-size: 13px;
}
.el-header {
  padding: 13px 0 !important;
  .el-form {
    .el-form-item {
      margin-bottom: 0 !important
    }
  }
}
.custom-drawer-form {
  .el-drawer__header {
    padding: 0 20px !important;
    margin: 15px 0 !important;
    span {
      font-size: 18px;
      color: #303133;
    }
  }
  .el-drawer__body {
    border-top: 1px solid #e6e6e6;
  }
}
.upload-file {
  width: 100% !important;
  .el-upload, .el-upload-dragger {
    width: 100% !important;
  }
  .el-upload-dragger .el-icon-refresh {
    font-size: 67px;
    color: #C0C4CC;
    margin: 40px 0 16px;
    line-height: 50px;
  }
}
.scrollable {-webkit-overflow-scrolling: touch;}
::-webkit-scrollbar {width: 5px;height: 5px;}
::-webkit-scrollbar-thumb {background-color: rgba(50, 50, 50, 0.3);}
::-webkit-scrollbar-thumb:hover {background-color: rgba(50, 50, 50, 0.6);}
::-webkit-scrollbar-track {background-color: rgba(50, 50, 50, 0.1);}
::-webkit-scrollbar-track:hover {background-color: rgba(50, 50, 50, 0.2);}
.el-aside {border-right: 1px solid #e6e6e6;background: #fff;}
.el-header {background: #fff;border-bottom: 1px solid #e6e6e6;padding:13px 15px;display: flex;justify-content: space-between;align-items: center;}
.el-header .left-panel {display: flex;align-items: center;}
.el-header .right-panel {display: flex;align-items: center;}
.el-header .right-panel > * + * {margin-left:10px;}
.el-footer {background: #fff;border-top: 1px solid #e6e6e6;padding:13px 15px !important;}
.el-main {padding:15px;}
.el-main.nopadding {padding:0;background: #fff;}
// .el-main {flex-basis: 0}
.el-container {height: 100%;}
</style>
<style lang="less" scoped>
.absoParent1{
  cursor: move;
  width: 40px;
  height: 50px;
  border: 1px solid #1a65b8;
  background: #fff;
  color: black;
  border-top-left-radius:10px; 
  border-bottom-left-radius:10px; 
  float: right;
  position: relative;
  bottom: 100px;
  right: 0px;
  z-index: 6;
  .icon{
    font-size: 24px;
  };
  .mouseEnter{
    display: none;
  }
}
.absoParent1:hover{
  width:100px;
  background:#1a65b8;
  color:white;
  .icon{
    font-size: 30px;
  };
  .mouseEnter{
    display: inline-block;
  };
  .abso1{
    width:100px
  }
}
.abso1{
  width: 40px;
  height: 50px;
  border-top-left-radius:10px; 
  border-bottom-left-radius:10px; 
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
.abso1:hover{
  width:100px;
}

</style>
