<template>
  <div>
    <el-table
            border
            style="width: 100%;"
            ref="mainTable"
            :data="tableData"
            :height="height - 120"
            v-loading="loading"
            header-row-class-name="custom-table-header"
            :default-sort="{ prop : 'date', order: 'descending' }">
            <el-table-column prop="patentNo"  label="专利号" sortable width="200" align="center">
              <template slot-scope="scope">
                <div>
                  <el-link @click.native="toContrast(scope.row,scope.$index)" :reportId="reportId">{{scope.row.patentNo}}</el-link>
                </div>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="name" label="专利标题" sortable width="300" align="center"></el-table-column>
            <el-table-column prop="abstractStr" label="摘要" sortable  align="center"></el-table-column> -->
            <el-table-column v-for="column in fieldsArr" :label="column.name" :key="column.key" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                <div style="" v-for="data in getColumnValue(scope.row, column)">
                  <template v-if="column.key === 'name'">
                      <span v-html="getViewDom2(scope.row, 'name')"></span>
                      <br>
                      <el-link type="primary" @click.native="handleChange(scope.row, 'name')">
                        <span v-if="!scope.row.change">切换译文</span>
                        <span v-else>切换原文</span>
                      </el-link>
                    </template>
                    <template v-else-if="column.key === 'abstractStr'">
                      <span v-html="getViewDom2(scope.row, 'abstractStr')"></span>
                      <br>
                      <el-link type="primary" @click.native="handleChange(scope.row, 'abstractStr')">
                        <span v-if="!scope.row.change2">切换译文</span>
                        <span v-else>切换原文</span>
                      </el-link>
                    </template>
                  <template v-else>
                    <span v-html="getViewDom(data)"></span>
                  </template>
                </div>
              </template> 
            </el-table-column>
				  </el-table>
        <div style="width: 100%;background-color: #fff; text-align: center;">
          <el-pagination background layout="total, prev, pager, next, jumper" :current-page.sync="queryParams.current"
            :page-size.sync="queryParams.size" @current-change="handleCurrentChange" :total="queryParams.total">
          </el-pagination>
        </div>
  </div>
</template>

<script>
import { Contrast } from './mixins';
import { PatentViewFieldJs, } from "@/views/task/components/PatentViewField";
import { changeTranslation, patentKeywordsHighlight} from '@/views/components/common/mixins'
export default {
 
  mixins:[Contrast, changeTranslation, patentKeywordsHighlight,PatentViewFieldJs],
  props:["fieldsArr","activeName","taskId","reportId","onChangesIn","formS","taskStatus",'type','signPatentNo','reportType',"coordination","taskWorkRemak",'reportName' ,'params',"height"],
  data() {
    return {
      tableData: [],
      loading: false,
      queryParams: {
        signPatentNo:this.signPatentNo,
        taskId: this.taskId,
        reportId: this.reportId,
        reportName:this.reportName,
        // applicationName: "",//申请人
        // obligeeName: "",//权利人
        // patentNo:"",
        // applicationNo:"",
        // numberIpc:"",
        // numberCpc:"",
        // numberUpc:"",
        // patentName:"",
        // abstractStr:"",
        filedOptions: [],//数组，用来存放自定义字段勾选项进行筛选
        taskStatus:"3",//0未、1已、3全部
        current: 1,
        size: 10,
        total: 0,
        type:this.type,
        reportType:this.reportType,
        taskName:this.params.taskName
      }
    }
  },
  created() {
  },
  mounted() {
    this.getList();
    this.getCompareMessage()
  },
  computed: {
    formTed() {
      return JSON.stringify(this.formS);
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.queryParams.current=val
      this.getList()
    },
    getCompareMessage() {
      let a = {
        "taskId": null,
        // current: 1,
        // size:10,
          "reportId": this.queryParams.reportId,
          "compareResult": 2
        }
      this.$api.getComparedMessage(a).then(res => {
        if (res.code == 200) {
            this.queryParams.compareResult = res.data.records
        }
      })
    },
    getList() {
      this.loading=true
      this.$api.reTaskPatents(this.queryParams).then(res => {
        if (res.code == 200) {
          this.queryParams.total=res.data.total
          this.tableData = res.data.records
          this.loading=false
        }
      }).catch(error=>{
        this.loading=false
      })
    },
  },
  watch: {
    activeName(val){
      this.queryParams.taskStatus = this.activeName=='first'?0:1
      this.getList()
    },
    onChangesIn(val) {
      this.queryParams.filedOptions = val
      this.getList()
    },
    formTed(val) {
      let value=JSON.parse(val)
      if (Object.keys(value).length != 0) {
        // console.log(value);
        // console.log("you");
        for (let key in value) {
          this.queryParams[key]=value[key]
        } 
        this.getList()
      } else {
        // console.log("空");
        this.getList()
      }
      
      // this.queryParams.applicationName=val.applicationName
      // this.queryParams.obligeeName = val.obligeeName
      // this.queryParams.patentNo = val.patentNo
      // this.queryParams.applicationNo = val.applicationNo
      // this.queryParams.numberIpc = val.numberIpc
      // this.queryParams.numberCpc = val.numberCpc
      // this.queryParams.numberUpc = val.numberUpc
      // this.queryParams.patentName = val.patentName
      // this.queryParams.abstractStr = val.abstractStr
      // this.getList()
    },
    taskStatus(val) {
      this.queryParams.taskStatus = val
      this.getList()
    },
  },
  // .doLayout()对表格进行重绘
  updated(){
    this.$refs.mainTable.doLayout()
  },
}
</script>

<style lang="scss">
.incompleteTable .el-table .cell.el-tooltip{
  white-space: break-spaces; 
}
</style>