<template>
  <div>
    <myContextMenu @operateDirectory="getMethod"></myContextMenu>
    <contrast ref="contrast"></contrast>
    <!-- 批注 -->
    <annotation ref="annotation"></annotation>
    <my-ImageViewer v-if="showImg" :on-close="closeViewer" :url-list="[imgSrc]"></my-ImageViewer>
    <translate ref="translate"></translate>
    <noveltySearchContrast ref="noveltySearchContrast"></noveltySearchContrast>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import contrast from '@/views/components/dialog/menuDialog/contrast.vue'
import annotation from '@/views/components/dialog/menuDialog/annotation.vue'
import translate from '@/views/components/dialog/menuDialog/translate.vue'
import noveltySearchContrast from '@/views/components/dialog/menuDialog/noveltySearchContrast.vue'
export default {
  name: 'myCommonUse',
  components: {
    contrast,
    annotation,
    translate,
    noveltySearchContrast
  },
  props: {},
  data() {
    return {
      showImg: false,
      imgSrc: '',
    };
  },
  watch: {},
  computed: {
    ...mapGetters(["highlight"])
  },
  created() { },
  mounted() {
    // window.selectMark = this.selectMark
  },
  methods: {
    //查看图片
    checkImg(e) {
      if(e.target){
        this.imgSrc = e.target.src
      }else{
        this.imgSrc = e
      }
      
      this.showImg = true
    },
    //关闭图片弹窗
    closeViewer() {
      this.showImg = false
    },
    //点击图标回显数据
    selectMark(id, selectType) {
      var Id = id.substring(selectType.length, id.length)
      switch(selectType){
        case 'p'://批注
          if(!this.$permission.FunPermissions('xiaoshi/annotationLibrary')){
              this.$showPermissionDialog()
              return false
          }
          var index = this.highlight.piZhuContrastList.findIndex(item => {
            if (item.id == Id) {
              // 清空currentSelectObj，否则Id与id同时存在
              this.$store.commit("SET_PATENT_INDEX", item)
            }
            return item.id == Id
          })
          if (index != -1) {
            // 打开批注框
            this.$refs.annotation.open()
          }
          break;
        case 'c'://对比
          let a = this.highlight.contrastList.find(item => {
            return item.id == Id
          })
          a.column = a.fieldName
          a.text = a.evidenceText
          this.$store.commit("SET_PATENT_INDEX", a)
          this.contrast()
          break;
        case 'o'://陈述意见
          break;
        case 'novelty'://查新检索
          let novelty = this.highlight.NoveltySearchContrastList.find(item => {
            return item.id == Id
          })
          if(novelty){
            this.$store.commit("SET_PATENT_INDEX", novelty)
            this.noveltySearchContrast()
          }
          
          break;
      }

    },
    getMethod(type) {
      var types = ['wave','underscore','addHighlight','mark']
      if(types.indexOf(type)!=-1){
        if(!this.$permission.FunPermissions('xiaoshi/annotationLibrary')){
            this.$showPermissionDialog()
            return false
        }
      }
      if (this[type]) {
        this[type]()
      }
    },
    //翻译
    translate(){
      this.$refs.translate.open()
    },
    //波浪线
    wave() {
      this.$refs.annotation.submit2(2)
    },
    //下划线
    underscore() {
      this.$refs.annotation.submit2(0)
    },
    //高亮
    addHighlight() {
      this.$refs.annotation.submit2(1)
    },
    //批注
    mark() {
      this.$refs.annotation.open()
    },
    //修改颜色
    changeColor() {
      this.$refs.annotation.submit2()
      console.log('修改颜色')
    },
    //对比
    contrast() {
      this.$refs.contrast.open()
    },
    //删除批注
    deleteMark() {
      console.log('删除')
    },
    //查新对比
    noveltySearchContrast(){
      this.$refs.noveltySearchContrast.open()
    },
  },
};
</script>
<style lang="scss" scoped></style>