<template>
  <!-- 外部人员输入识别码 -->
  <div>
    <div style="width:500px;height:300px;position:absolute;top:0;bottom:0;left:0;right:0;margin:auto;">
      <img src="@/assets/logo-3.png" alt="" style="width:300px;margin:0 100px 30px">
      <div style="background:white;height:150px;padding:20px;">
        <p>请输入识别码：</p>
        <div class="input">
          <p class="code" style="display:inline-block;width:80%">
            <el-input v-model="code" placeholder="请输入识别码" @input="change"></el-input>
            <span v-if="show">{{ content }}</span>
          </p>
          <el-button type="primary" @click="submit" style="display:inline-block;margin-left:20px">提交</el-button>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      show: false,
      content: "",
      code: '',
      btnLoading: "",
      coordination: true,
    }
  },
  methods: {
    submit() {
      if (this.code) {
        this.$api.getTaskByCode({ code: this.code }).then(res => {
          if (res.code == 200) {
            // 进入专利列表页面
            // let a = this.$router.resolve({
            //   path: '/reportPatentList',
            //   query: {
            //     taskId: res.data.id,
            //     projectId: res.data.projectId,
            //     taskType: res.data.type,
            //     reportType: res.data.reportType,
            //     isResult: 1,
            //   }
            // })
            // // this.$store.commit("COORDINATION", this.coordination)
            // window.open(a.href, "_blank")
            this.teamworkTask(res.data)
          } else {
            document.getElementsByClassName("el-input__inner")[0].style.border = "1px solid red"
            this.show = true;
            this.content = "识别码错误"
          }
        }).catch(error => {
          document.getElementsByClassName("el-input__inner")[0].style.border = "1px solid red"
          this.show = true;
          this.content = "识别码错误"
        })

      } else {
        document.getElementsByClassName("el-input__inner")[0].style.border = "1px solid red"
        this.show = true;
        this.content = "请输入识别码"
      }
    },
    change() {
      document.getElementsByClassName("el-input__inner")[0].style.border = "1px solid #DCDFE6"
      this.show = false;
    },
    teamworkTask(row) {
      if (row.reportType == 3) {//fto
        let router = this.$router.resolve({
          path: '/reportPatentList',
          query: {
            taskId: row.id,
            projectId: row.projectId,
            taskType: row.type,
            reportType: row.reportType,
            isResult: 1,
            handlerType:row.handlerType,//1是外部协同人
          }
        })
        window.open(router.href, '_blank')
      } else {//侵权
        var patentNo = this.getPatent(row.projectId,row.id)
        var router = this.$router.push(
          {
            path: '/patentDetails/' + patentNo,
            query: {
              projectId: row.projectId,
              taskId: row.id,
              isResult:1,
              taskType:row.type,
              reportType: row.reportType,
              handlerType:row.handlerType,
            }
          }
        )
        window.open(router.href, '_blank')
      }

    },

       // 请求专利(侵权分析协同用到)
    async getPatent(projectId,taskId) {
      let params = {
        current: 1,//分页信息
        size:10,
        projectId: projectId,
        taskId: taskId,
        searchQuery: '',//检索条件
        customFields: [],
        orderDTOList: [],//排序信息
      }
      var patentNo = ''
      await this.$api.QueryPatent(params).then(res => {
        if (res.code == 200) {
          patentNo = res.data.data[0].patentNo
        }
      }).catch(error => {
      })
      return patentNo
    },
  }
}
</script>
<style>
.code {
  position: relative;
}

.code span {
  position: absolute;
  top: calc(100% + 10px);
  left: 0px;
  color: red;
  font-size: 12px;
}
</style>