<template>
  <div class="content">
    <div class="item" v-for="item in patentMark" :key="item.id" :style="{'background':item.markColor}">
      <el-popover
        placement="bottom"
        width="200"
        trigger="hover">
      <div>
        <p><span style="color: #409EFF;">栏位：</span><span>{{ item.fieldName }}</span></p>
        <!-- <p>栏位：{{ item.scratchField }}</p> -->
        <p><span style="color: #409EFF;" class="noWrap">选中文本：</span>{{ item.text }}</p>
        <p v-if="item.remark" class="noWrap"><span style="color: #409EFF;">标注：</span>{{ item.remark }}</p>
      </div>
      <div slot="reference" style="height:100%;width:100%" @click.prevent.stop="runTo(item)"></div>
      </el-popover>
    </div>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  props:['patentNo','reportType'],
  data() {
    return {
      patentMark:[]
    }
  },
  computed: {
    ...mapGetters(['highlight']),
  },
  watch: {
    patentNo(val) {
      this.getPatentMark()
    },
  },
  mounted() {
    this.getPatentMark()
  },
  methods: {
    getPatentMark() {
      var contrastList = []
      var pizhu = this.highlight.piZhuContrastList
      if(this.reportType == 1 || this.reportType == 2){
        contrastList = this.highlight.contrastList
      }
      var data = contrastList.concat(pizhu)
      this.$nextTick(() => {
        this.patentMark=[]
        var a = ['摘要', '权利要求', '说明书']
        // var b = data.filter(item => {
        //   if(item.patentNo == this.patentNo){
        //     var obj = {
        //       id:item.id,
        //       position:item.position || item.markSite,
        //       fieldName:item.fieldName || item.markSelectField,
        //       markColor:item.markColor,
        //       text:item.evidenceText || item.markSelectText,
        //       patentNo:item.patentNo,
        //       markType:item.markType,
        //       remark:item.markNoteText
        //     }
        //     return obj
        //   }
        // })
        var b = []
        for(var i = 0;i<data.length;i++){
          var item = data[i]
          if(item.patentNo == this.patentNo){
            var obj = {
              id:item.id,
              position:item.position || item.markSite,
              fieldName:item.fieldName || item.markSelectField,
              markColor:item.markColor,
              text:item.evidenceText || item.markSelectText,
              patentNo:item.patentNo,
              markType:item.markType,
              remark:item.markNoteText,
              highlightType:item.position?'c':'p'
            }
            b.push(obj)
          }
        }
        console.log(b,data)
        /**方案四 */
        var c = []
        a.forEach((item,index) => {
          c[index] = b.filter(item2 => {
            return item2.fieldName.indexOf(item) != -1
          })
          c[index].sort((a, b) => {
            return a.position - b.position
          })
        })
        this.patentMark = [].concat(...c)
      })
    },
    runTo(val) {
      this.$emit('biaozhu',val)
    }
  },
}
</script>

<style lang="scss" scoped>
.item{
  width: 8px;
  height: 8px;
  border: 1px solid black;
  margin:2px 2px;
}
.content{
  max-width: 300px;
  max-height: 50px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
}
</style>