<template>
  <div class="height_100 article" :style="{ 'flex-direction': isRight ? 'row-reverse' : 'row' }">
    <articleMenu @event="event" :value="showView" :reportType="reportType" :menu="menuList" :isRight="isRight"
      :projectId="projectId" :taskId="taskId" :searchOption="search.searchOption" :patentNo="patentNo"
      :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" :evidence="evidenceData"></notPatentDetails>
          <!-- <Patent-Details :patentNo="patentNo" :projectId="projectId" :taskId="taskId"></Patent-Details> -->
          <component v-else :is='components' :patentNo="patentNo" :evidence="evidenceData" :projectId="projectId" :taskId="taskId"
            :reportType="reportType" :isResult="isResult"></component>
        </div>
        <div slot="right" style="width:100%">
          <notPatentDetails v-if="evidenceType == 1" :projectId="projectId" :evidence="evidenceData"></notPatentDetails>
          <Patent-Details v-else :patentNo="patentNo" :evidence="evidenceData" :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,
      routeCount: this.$s.getSession('routeCount') || 1,
      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
    },

  },
  created() { },
  mounted() {
    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.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.evidence.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
            // })
            contrastList.push(...response.data.data)
            this.$store.commit("SET_CONTEXT_MENU",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() {
      var a = Number(this.routeCount)
      window.history.go(-a)
      this.$s.setSession('routeCount', 1)
    },
    //协同
    coordination() {
      this.$refs.teamwork.open()
    },
    getPatentLeft(val, sign) {
      var evidenceType = null
      var evidence = {}
      if (sign) {
        this.evidenceData = val
        this.patentNo = val.literatureNo
        evidenceType = val.type
        evidence = JSON.stringify(val)
      } else {
        this.patentNo = val
      }
      this.routeCount = Number(this.routeCount) + 1
      this.$s.setSession('routeCount', this.routeCount)
      this.$router.push(
        {
          path: '/patentDetails/' + this.patentNo,
          query: {
            projectId: this.projectId,
            taskId: this.taskId,
            reportType: this.reportType,
            evidenceType: evidenceType,
            evidence: evidence
          }
        }
      )
    },
  },
};
</script>
<style lang="scss" scoped>
.article {
  display: flex;

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