export const explain = {
  data() {
    return {
      innerHtml:''
    }
  },
  mounted() {
    // document.addEventListener('cut',(event1) =>{
    //   const selection = document.getSelection( ) ;
    //   event1.clipboardData.setData( 'text/plain', selection.toString() .toUpperCase());document.getSelection().deleteFromDocument();
    //   event1.preventDefault();
    //   event1.stopPropagation();
    //   let cut = (event1.clipboardData || window.clipboardData).getData('text/plain');
    //   cut = cut.replace( / style/gi, "data-style ");
    //   console.log(cut)
    //   this.$forceUpdate()
    //   });
      
  },
  methods: {
     // 解释所需方法
    saveValue(val) {//点击输入触发,第一次为空不打印
      console.log("saveValue",val);
      if (this.keepSure) {
        this.keepSure = false;
      }
      this.innerhtml = val
      console.log(this.innerhtml)
    },
    getValue(row,name) {//失去焦点触发，row本行数据，name是传过来的row里面每一个属性
      console.log("getValue",row[name]);
      if (this.innerhtml != '') {
        row[name] = this.innerhtml
        this.innerhtml = ''
      }
    },
    handlePaste(event, row,name) {//图片的处理(剪切板方法clipboard)//row本行数据，name是传过来的row里面每一个属性
      console.log("handleP",event,row);
      const items = (event.clipboardData || window.clipboardData).items;
      console.log((event.clipboardData || window.clipboardData).items)
      let file = null;
      if (!items || items.length === 0) {//？
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      const reader = new FileReader();
      reader.onload = (event) => {
        var blobUrl = event.target.result

        var new_img = '<img src="' + blobUrl + '" style="width:80px;height: 80px;border: 1px solid #f9f6f675;vertical-align:middle" >';
        let str = row[name]?row[name]:''
        console.log(str,this.innerhtml)
      var arr =  this.SplitHtmlTag(this.innerhtml)
      var b = []
      arr.forEach(item => {
        if(item.text.indexOf('style="width:80px;height: 80px;border: 1px solid #f9f6f675;vertical-align:middle"') !=-1 || item.type == 'text'){
          b.push(item.text)
        }
      });
      var html = b.join(' ')
      console.log(html)
      str = html
        if (html) {//不为空
          // row[name] = this.innerhtml + new_img
          this.$set(row,name,html + new_img)
          this.innerhtml = ''
        } else {
          // row[name] = str + new_img
          this.$set(row,name,str + new_img)
        }
        this.$forceUpdate()
        if(this.tableHeight){
          this.setHeight()
        }
       
       
      };
      reader.readAsDataURL(file);
      this.pasteFile = file;
    },
    SplitHtmlTag(el){
      let temInnerHtml = el.trim();
      let pattern = /<[^>]+>/g;
      let Indexs =[];
      let i=0
      var match = null
      while((match = pattern.exec(temInnerHtml)) != null){
          Indexs[i] = match;
        //   console.log(match);
          //Indexs[i] =[ match.index,m.value];
          i++;
      }
      //var m = temInnerHtml.match(pattern);
      var splitStrings = new Array();
      i=0;
      var currentIndex =0;
      for(var index=0;index<Indexs.length;index++){
          if(Indexs[index].index >currentIndex){
              splitStrings[i] = {"text":  temInnerHtml.substring(currentIndex,Indexs[index].index), "type":"text"};
              i++;
              splitStrings[i] = {"text":  Indexs[index][0], "type":"tag"};
              i++;
          }
          else
          {
              splitStrings[i] = {"text":  Indexs[index][0], "type":"tag"};;
              i++;
          }

          currentIndex = Indexs[index].index + Indexs[index][0].length;

      }

      if(currentIndex< temInnerHtml.length){
          splitStrings[i] = {"text": temInnerHtml.substring(currentIndex,temInnerHtml.length), "type":"text"};
      }
      console.log(splitStrings)
      return splitStrings;

  },
  },
}

export const editContrast = {
  methods: {
    editContrast(patentNo){
      var params = {
        signPatentNo:this.patentNo,
        type:2,
        reportId:this.reportId
      }
      const router = this.$router.resolve({
        path: '/ContrastIndex/' + patentNo,
        query: {
          patentNo:patentNo,
        }
      })
    this.$s.setSession('params', params)
    window.open(router.href, '_blank');
    }
  },
}

export const importPatent ={
  methods:{
    importPatent(reportId){
        this.$router.push({
          path: '/import',
          query: {
            id: reportId
          }
        })
    }
  }
}