<template>
  <div >
    <div v-if="!showEvidence">
      <div>
        <img src="@/assets/visual/fixed.png" width="20px" height="20px" @click="qx" v-if="fix===true" />
          <img src="@/assets/visual/unfixed.png" width="20px" height="20px" @click="gd" v-if="fix===false"  />
      </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="标的专利" name="patent">
                <ContrastIndex v-bind="$attrs" v-on="$listeners" :reportId="reportId" :evidenceFlieId="getEvidenceId()" :evidence="evidence1" @on-change='changefix' :patentNo="signPatentNo"  :signPatentNo="signPatentNo" :reportType="reportType" :showEvidence="!showEvidence" @openOpinioncontrast="openOpinioncontrast"></ContrastIndex>
            </el-tab-pane>
            <el-tab-pane label="无效请求书" name="InvalidRequest">
                <check-File ref="checkFile"></check-File>
            </el-tab-pane>
        </el-tabs>
    </div>
    <div v-else>
      <div>
        <img src="@/assets/visual/fixed.png" width="20px" height="20px" @click="qx" v-if="fix===true" />
          <img src="@/assets/visual/unfixed.png" width="20px" height="20px" @click="gd" v-if="fix===false"  />
      </div>
       <ContrastIndex v-if="type == 1" v-bind="$attrs" v-on="$listeners" :reportId="reportId" :evidenceFlieId="getEvidenceId()" :evidence="evidence1" @on-change='changefix' :patentNo="evidence1.proofConditions" :signPatentNo="signPatentNo" :reportType="reportType" :showEvidence="showEvidence" @openOpinioncontrast="openOpinioncontrast"></ContrastIndex> 
       <check-File v-else ref="checkFile1"></check-File>
    </div>
    <Add-Opinion ref="addOpinion"></Add-Opinion>
  </div>
</template>

<script>
import ContrastIndex from '@/views/workspace/folder/articles/ContrastIndex.vue';
import checkFile from '@/views/report/InvalidResponse/components/checkFile.vue';
import AddOpinion from '@/views/report/InvalidResponse/components/addOpinion.vue'
export default {
  components: {
    ContrastIndex,
    checkFile,
    AddOpinion
  },
  props: ['isEvidence','evidence','reportId','signPatentNo','reportType','EvidenceList'],
  data() {
    return {
        activeName:'patent',
        fix:false,
        showEvidence:this.isEvidence,
        type:1,
        url:'',
        evidence1:{},
    };
  },
  watch: {
    isEvidence(val){
        if(!this.fix){
            this.showEvidence = val
        }
    },
    'evidence'(val){
        if(!this.fix){
          this.evidence1 = JSON.parse(JSON.stringify(val))
            this.type = val.type
            this.showEvidence = true
            this.getDetails(val)
        }
    },
  },
  computed: {},
  created() {
    
  },
  mounted() {
    // this.$nextTick(()=>{
    //     if(this.evidence.id){
    //         this.getDetails(this.evidence)
    //     }
    // })
  },
  methods: {
    //获取证据文献id
    getEvidenceId(){
      // var row = this.EvidenceList.find(item=>{
      //   if(!this.fix){
      //     console.log(12)
      //      return item.proofConditions == this.evidence1.proofConditions
      //   }else{
      //     console.log(1)
      //     return item.proofConditions == this.evidence.proofConditions
      //   }
       
      // })
      if(!this.fix){
        var row = this.EvidenceList.find(item=>{
           return item.proofConditions == this.evidence1.proofConditions
        })
      }else{
        var row = this.EvidenceList.find(item=>{
           return item.proofConditions == this.evidence1.proofConditions
        })
      }
      if(row){
        return row.id
      }
    },
    // 划词陈述意见
    openOpinioncontrast(val) {
      var form = {}
      form=val
      form.reportId=this.reportId
      form.signPatentNo = this.signPatentNo
      this.$refs.addOpinion.open(form,false)
    },
    qx() {
      this.fix = false

    },
    gd() {
      this.fix = true
    },  
    //获取证据详情
    getDetails(val){
        // 1是文献2是非文献
        if (val.type == 1) {
            // this.getPatent(val.proofConditions)
            // this.getPiZhuContrastList(val.proofConditions)
        } else if (val.type == 2){
            let url = `http://${this.$c.hostname}:8012/onlinePreview?url=` + btoa(encodeURIComponent(this.$p + val.proofConditions))
            this.$nextTick(() => {
                this.$refs.checkFile1.open(url)
            })
        }
    },
    //切换tab栏
    handleClick(){
        if(this.activeName == 'InvalidRequest'){
            if (this.url) {
            let url = `http://${this.$c.hostname}:8012/onlinePreview?url=` + btoa(encodeURIComponent(this.url))
            this.$refs.checkFile.open(url)
          } else {
            var params = {
              reportId: this.reportId,
              type:1,
            }
            this.$api.queryInvalidProcess(params).then((res) => {
              if (res.code==200) {
                this.url = this.$p + res.data[0].reportFile.url
                let url = `http://${this.$c.hostname}:8012/onlinePreview?url=` + btoa(encodeURIComponent(this.url))
                this.$refs.checkFile.open(url)
              }
            }).catch((error) => {
              
            })
          }
        }
    },
    //是否定住
    changefix(val){
        this.fix = val
    },
  },
};
</script>
<style lang="scss" scoped>
</style>