<template>
  <div class="height_100 article" :style="{ 'flex-direction': isRight ? 'row-reverse' : 'row' }">
    <articleMenu @event="event" :value="showView" :reportType="reportType" :menu="menuList" :isRight="isRight" :outside="outside"
      :projectId="projectId" :taskId="taskId" :searchOption="search.searchOption" :patentNo="patentNo" :fromPath="search.fromPath"
      :location="search.location" @getPatentLeft="getPatentLeft" :handlerType="handlerType"></articleMenu>
    <div class="height_100 content">
      <my-View :showView="showView">
        <div slot="left" style="width:100%">
          <notPatentDetails v-if="evidenceType == 1" :projectId="projectId" :signPatentNo="signPatentNo" :reportType="reportType" :evidence="evidenceData"></notPatentDetails>
          <!-- <Patent-Details :patentNo="patentNo" :projectId="projectId" :taskId="taskId"></Patent-Details> -->
          <component v-else :is='components' :patentNo="(signPatentNo && showView)?signPatentNo:patentNo" :value="showView" :evidence="evidenceData" :outside="outside" :projectType="projectType" :lock="signPatentNo?true:false" :signPatentNo="signPatentNo"  :projectId="projectId" :taskId="taskId"
            :reportType="reportType" :isResult="isResult"></component>
        </div>
        <div slot="right" style="width:100%">
          <notPatentDetails v-if="evidenceType == 1" :projectId="projectId" :signPatentNo="signPatentNo" :reportType="reportType" :evidence="evidenceData"></notPatentDetails>
          <Patent-Details v-else :patentNo="patentNo" :outside="outside" :value="showView" :projectType="projectType" :evidence="evidenceData" :signPatentNo="signPatentNo" :reportType="reportType" :projectId="projectId" :taskId="taskId"></Patent-Details>
        </div>
      </my-View>
    </div>
    <teamwork ref="teamwork" :patentNo="patentNo" :projectId="projectId" :reportType="reportType"></teamwork>
  </div>
</template>

<script>
import articleMenu from './components/menu.vue'
import PatentDetails from './components/patentDetails.vue'
import tortContrast from '@/views/report/tort/components/tortContrast1.vue'
import teamwork from '@/views/report/components/dialog/teamwork.vue'
import notPatentDetails from './components/notPatentDetails.vue'
import {mapGetters} from 'vuex'
export default {
  components: {
    articleMenu,
    PatentDetails,
    tortContrast,
    teamwork,
    notPatentDetails
  },
  props: {},
  data() {
    return {
      showView: false,
      isRight: false,
      patentNo: this.$route.params.patentNo,
      components: 'PatentDetails',
      menuList: [],
      evidenceData: {}
    };
  },
  watch: {},
  computed: {
    ...mapGetters(['highlight']),
    projectId() {
      return this.$route.query.projectId
    },
    taskId() {
      return this.$route.query.taskId
    },
    reportType() {
      return this.$route.query.reportType
    },
    search() {
      return this.$s.getSession('search') || {}
    },
    isResult() {
      return this.$route.query.isResult
    },
    taskType() {
      return this.$route.query.taskType
    },
    handlerType() {//1外部人员0内部人员（只有外部协同人做协同任务才会传递）
      return this.$route.query.handlerType
    },
    evidenceType() {//证据文献类型，专利类型：0；非专利：1
      return this.$route.query.evidenceType
    },
    evidence() {
      return this.$route.query.evidence
    },
    signPatentNo(){
      return this.$route.query.signPatentNo
    },
    outside() {
      return this.$route.query.outside
    },
    projectType() {
      return this.$route.query.projectType//判断是不是从专题库进入专利详情1为专题库2为报告(报告未传2)
    },
  },
  created() { },
  mounted() {
    if(this.search && !this.search.fromPath){
      this.search.fromPath = window.history.length
      this.$s.setSession('search',this.search)
    }
    if (this.evidence) {
      this.evidenceData = JSON.parse(this.evidence)
    } else {
      this.evidenceData = this.evidence
    }
    this.getMenuPrice()
    this.getComponents()
    if(this.reportType == 1 || this.reportType == 2){
      this.$store.commit("SET_PATENT_CONTRAST",[])
      this.getContrast()
    }
    
  },
  methods: {
    //获取对比记录
    getContrast(){
      if(!this.evidence){
        return false
      }
      var params = {
        literatureId:this.evidenceData.id
      }
      var contrastList = this.highlight.contrastList
      var index = contrastList.findIndex(item=>{
        return item.literatureId == this.evidenceData.id
      })
      if(index !=-1){
        return
      }
      this.$api.queryCompareRecord(params).then(response=>{
        if(response.code == 200){
          
          if(response.data.data.length>0){
            // var obj = response.data.data[0]
            // var newContrastList = contrastList.filter(item=>{
            //   return item.literatureId != obj.literatureId
            // })
            var data = response.data.data.map(item=>{
              item.signPatentNo = this.signPatentNo
              item.projectId = this.projectId
              return item
            })
            contrastList.push(...data)
            this.$store.commit("SET_PATENT_CONTRAST",contrastList)
          }
        }
      })
    },
    // 获取协同按钮
    getMenuPrice() {
      if (this.reportType == 4 && !this.taskId) {
        this.menuList = [
          {
            content: '协同',
            event: 'coordination',
            icon: 'el-icon-s-custom',
          }
        ]
      }
    },
    getComponents() {
      if (this.taskType == '3' || this.taskType == '4') {
        this.components = 'tortContrast'
      }
    },
    //菜单事件
    event(val) {
      this[val]()
    },
    //对比
    contrast() {
      this.showView = !this.showView
    },
    //设置左边或者右边
    setting() {
      this.isRight = !this.isRight
    },
    //返回
    goBack() {
      if(this.search.fromPath){
        var now = window.history.length
        var history= this.search.fromPath
        var len = Number(now) - Number(history) + 1
        window.history.go(-len)
      }
    },
    //协同
    coordination() {
      this.$refs.teamwork.open()
    },
    getPatentLeft(val, sign) {
      var evidenceType = null
      var evidence = null
      if (sign) {
        this.evidenceData = val
        this.patentNo = val.literatureNo
        evidenceType = val.type
        evidence = JSON.stringify(val)
      } else {
        this.patentNo = val
      }
      this.$router.push(
        {
          path: '/patentDetails/' + this.patentNo,
          query: {
            projectId: this.projectId,
            taskId: this.taskId,
            reportType: this.reportType,
            isResult:this.isResult,
            taskType:this.taskType,
            handlerType:this.handlerType,
            evidenceType: evidenceType,
            evidence: evidence,
            signPatentNo:this.signPatentNo,
            outside:this.outside,
            projectType:this.projectType,
          }
        }
      )
    },
  },
};
</script>
<style lang="scss" scoped>
.article {
  display: flex;

  .content {
    width: 100%
  }
}</style>