<template>
    <div>
      <div style="display:flex; justify-content:flex-end;align-items: center;height: 50px;">
        <el-button type="danger" @click="delPlan">删除</el-button>
      </div>
        <el-table
        :data="tableData"
        border
        class="table"
        height="750"
        :span-method="objectSpanMethod"
        :row-class-name="tableRowClassName"
        v-loading="loading"
        style="min-width: 100%; overflow:auto">

        <el-table-column prop="right" label="权要"  align="center"  width="200px" :filters="rightList" :filter-method="filterHandler">
          <template slot-scope="scope">  
            <el-tooltip class="item" effect="dark" :content="scope.row.right" placement="top">
              <span>{{scope.row.right}}</span>
            </el-tooltip>     
          </template>
        </el-table-column>

        <el-table-column prop="resultant" label="对比组合" align="center" width="300px" :filters="resultant" :filter-method="filterHandler">
          <!-- <template slot="header">
            <div>
               <span>对比组合</span>
              <el-dropdown size="small">
              <div class="el-dropdown-link">
                <i class="el-icon-arrow-down el-icon--right"></i>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="item in resultant" @click.native="handleClick(item)">
                  <span>{{ item.text }}</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            </div>
          </template> -->
          <template slot-scope="scope" >
            <div >
              <el-checkbox-group v-model="checkList" >
                <el-checkbox :label="scope.row.id" @change="getFunInfo(scope.row)" >
                  <!-- <p>对比组合{{(scope.$index+1)}}</p>  -->
                  <p>{{ scope.row.resultant}}</p>
                </el-checkbox>
              </el-checkbox-group>
            </div>
           
          </template>
        </el-table-column>
        <el-table-column prop="assoRecordsFeatures" label="特征"  align="center"  width="200px">
          <template slot-scope="scope">
            <!-- <div >
              <tr v-for="i in scope.row.assoRecordsFeatures" style="margin:0 auto">
                <td style="width:100%">特征{{i.features.featuresOrder}}</td>
              </tr>
            </div>   -->
            

              <!-- <span>{{scope.row.content}}</span> -->
              <div class="innerTable" v-if="scope.row.assoRecordsFeatures" style="width:calc(100% + 20px);margin-left:-10px">
                  <p v-for="i in scope.row.assoRecordsFeatures">
                    <el-tooltip class="item" effect="dark" :content="i.features.content" placement="top">
                      <span>特征{{i.features.featuresOrder}}</span>
                    </el-tooltip>  
                  </p>
              </div>
          </template>
        </el-table-column>
        <el-table-column prop="patentNo" label="公识"  align="center"  width="100px">
          <template slot-scope="scope">  
              <!-- <span>{{scope.row.patentNo}}</span> -->
              <div class="innerTable" v-if="scope.row.assoRecordsFeatures" style="width:calc(100% + 20px);margin-left:-10px">
                  <p v-for="i in scope.row.assoRecordsFeatures">
                    <span  v-if="i.compareRecords">
                     
                    </span>
                    <span v-else >
                      公识
                    </span>
                  </p>
              </div>
          </template>
        </el-table-column>
        <el-table-column prop="patentNo" label="对比专利"  align="center"  width="200px">
          <template slot-scope="scope">  
              <!-- <span>{{scope.row.patentNo}}</span> -->
              <div class="innerTable" v-if="scope.row.assoRecordsFeatures" style="width:calc(100% + 20px);margin-left:-10px">
                  <p v-for="i in scope.row.assoRecordsFeatures">
                    <span  v-if="i.compareRecords">
                      {{i.compareRecords.patentNo}}
                    </span>
                    <span v-else >
                      <!-- 公识 -->
                    </span>
                  </p>
              </div>
          </template>
        </el-table-column>
        <el-table-column prop="content" label="对比内容"  align="center" min-width="200px">
          <template slot-scope="scope">  
              <!-- <span>{{scope.row.content}}</span> -->
              <div class="innerTable" v-if="scope.row.assoRecordsFeatures" style="width:calc(100% + 20px);margin-left:-10px">
                  <p v-for="i in scope.row.assoRecordsFeatures">
                    <span  v-if="i.compareRecords">
                      {{i.compareRecords.content}}<img v-if="i.compareRecords.filePath" :src="$p + i.compareRecords.filePath" width="100px" @click="showImage(i.compareRecords.filePath)" />
                    </span>
                    <span v-else>
                      <!-- 公识 -->
                    </span>
                  </p>
              </div>
          </template>
        </el-table-column>
        <el-table-column prop="contrastResult" label="对比结论/理由"  align="center"  width="300px">
          <template slot-scope="scope">  
              <span v-html="scope.row.contrastResult"></span>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog :visible.sync="showFile">
        <img width="100%" :src="imageUrl" alt="查不到该图片">
      </el-dialog>
    </div>
</template>

<script>
export default {
    props:['reportId'],
    data() {
        return {
          imageUrl:'',
          showFile :false,
          checkList:[],
          rightList:[],
          resultant:[],
            tableData:[],
            loading:false,
            mergeObj: {},
            mergeArr: [ 'right'],
        }
    },
    mounted() {
        this.getContrastPlan()
    },
    methods: {
       //查看图片
    showImage(url){
      this.imageUrl =this.$p + url
      this.showFile = true
    },
    filterHandler(value, row, column) {
        const property = column['property'];
        return row[property] === value;
      },
      // 表格隔行变色
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex % 2 === 0) {
          return 'success-row'
        } else  {
          return ''
        }
      },
      delPlan(){
        console.log(this.checkList)
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.deleteCompareScenarios(this.checkList).then(response=>{
            if(response.code == 200){
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.getContrastPlan()
              this.checkList = []
            }
            
          })
          
        }).catch(() => {        
        });
        
      },
        getContrastPlan(){
            this.$api.selectCompareScenarios({reportID:this.reportId}).then(response=>{
                if(response.code == 200){
                    console.log(response.data)
                    response.data.forEach((item,index)=>{
                      var a = this.rightList.findIndex(i=>{
                        return i.value == item.right
                      })
                      if(a==-1){
                        this.rightList.push({
                          text:item.right,
                          value:item.right
                        })
                      }
                      this.resultant.push({
                          text:'对比组合'+(index+1),
                          value:'对比组合'+(index+1)
                      })
                      item.resultant = '对比组合'+(index+1)
                      item.featuresList.forEach(i=>{
                        item.assoRecordsFeatures.push({
                          featureId:i.id,
                          features:i
                        })
                      })
                      item.assoRecordsFeatures.sort((a,b)=>{
                        return a.featureId - b.featureId
                      })
                    })
                    this.tableData = response.data
                    this.getSpanArr(this.tableData)
                }
            })
        },
        getSpanArr(data) {
            this.mergeArr.forEach((key, index1) => {
                let count = 0;
                this.mergeObj[key] = [];
                data.forEach((item, index) => {
                  // item.assoRecordsFeatures.forEach(i=>{
                  //   if(i.compareRecords){
                  //     this.mergeObj[key].push(0)
                  //   }else{
                  //     this.mergeObj[key].push(2)
                  //   }
                  // })
                if (index === 0) {
                    this.mergeObj[key].push(1);
                } else {
                    if (item[key] === data[index - 1][key]&& item[key] !== 'explainText' ) {
                    this.mergeObj[key][count] += 1;
                    this.mergeObj[key].push(0);
                    } else {
                    count = index;
                    this.mergeObj[key].push(1);
                    }
                }
                })
            })
            // data.forEach((item,index)=>{
            //   if (index === 0) {
            //         this.mergeObj[key].push(1);
            //   }
            // })
        },
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {

            if (this.mergeArr.indexOf(column.property) !== -1) {
                if (this.mergeObj[column.property][rowIndex]) {
                return [this.mergeObj[column.property][rowIndex], 1]
                } else {
                return [0, 0];
                } 
            }

    }
    },
}
</script>
<style>
.success-row {
  background-color:#eaf3fb !important; 
}
.success-row:first-child td:first-child{
  background-color: #FFF;
}
</style>
<style lang="scss" scoped>
.innerTable p{
  // min-width:200px;
  display: flex;
  justify-content: center;
  align-items:center;
  height: 150px;
  line-break:normal;
  border-bottom:1px solid #EBEEF5;
}

.innerTable p:nth-child(1){
  border-bottom: 1px solid #EBEEF5;
}
.innerTable p:last-child{
  border-bottom: none;
}
.table{
  cursor: pointer;
}
</style>