<template>
  <!-- 标的专利特征拆分 -->
  <div style="height: calc(100% - 20px);">
    <splitPage :isEdit="this.reportType==5?false:true" :isResult="reportType==5?9:''" :tableData="tableData" :patentNo="patentNo" @splitSelect="splitSelect" @isSave="save">
      <!-- <div slot="handleLeft">
        <span>标的专利：</span><el-link type="primary" @click="toPatentDetails(patentNo)">{{ patentNo }}</el-link>
      </div> -->
      <!-- <div slot="handleRight"></div> -->
    </splitPage>
  </div>
</template>

<script>
import { patentDetails } from '../../mixins/index2'
import splitPage from '../../splitPage/splitPage.vue';
export default {
  props: ['patentNo', 'projectId','reportType'],
  mixins: [patentDetails],
  components: {
    splitPage,
  },
  data() {
    return {
      // 数据源
      tableData:[],
    }
  },
  mounted() {
    if(this.reportType == 5){
      this.getSpiltFeature()
    }else{
      this.getList()
    }
    
  },
  methods: {
    save(data){
      var params = {
        projectId:this.projectId,
        featuresList:data
      }
      this.$api.saveBatchFeature(params).then(response=>{
        if(response.code == 200){
          this.$message.success('保存成功')
        }
      }).catch(error=>{
        this.$message.error('保存失败')
      })
    },
    // 改变拆分条件
    splitSelect(split) {
      this.getList(split,true)
    },
    getList(split = { splitType: '1', splitBy: '2' }, ifReSplit = false){
        var params = {
            projectId:this.projectId,
            patentNo:this.patentNo,
            ...split,
            ifReSplit: ifReSplit,
        }
        this.$api.spiltFeature(params).then(response=>{
            if(response.code == 200){
              var data = []
              response.data.data.forEach(RightVosItem => {
                if (RightVosItem.features.length > 0) {
                  RightVosItem.features.forEach(FeaturesItem => {
                    FeaturesItem.featureId = FeaturesItem.id
                    FeaturesItem.pRightName = RightVosItem.rightName
                    FeaturesItem.pSignPatentNo = RightVosItem.signPatentNo
                    FeaturesItem.pPatentNo = RightVosItem.patentNo
                    FeaturesItem.pContentOut = RightVosItem.contentOut
                    FeaturesItem.pContent = RightVosItem.content
                    FeaturesItem.pProjectId = RightVosItem.projectId
                    FeaturesItem.pType = RightVosItem.type
                    FeaturesItem.pSort = RightVosItem.sort
                    this.hasOwn(FeaturesItem)
                    data.push(FeaturesItem)
                  })
                }
              })
              this.tableData = data
            }
        }).catch(error=>{
            this.tableData = []
        })
    },
    getSpiltFeature() {
      let params = {
        patentNo:this.patentNo,
        projectId: Number(this.projectId),
        // ...split,//拆分条件
      }
      this.$api.getSpiltFeature(params).then(res => {
        if (res.code == 200) {
          if (res.data.data.length > 0) {
            var data = []
            res.data.data.forEach(RightVosItem => {
              if (RightVosItem.features.length > 0) {
                RightVosItem.features.forEach(FeaturesItem => {
                  FeaturesItem.pRightName = RightVosItem.rightName
                  FeaturesItem.pSignPatentNo = RightVosItem.signPatentNo
                  FeaturesItem.pPatentNo = RightVosItem.patentNo
                  FeaturesItem.pContentOut = RightVosItem.contentOut
                  FeaturesItem.pContent = RightVosItem.content
                  FeaturesItem.pProjectId = RightVosItem.projectId
                  FeaturesItem.pType = RightVosItem.type
                  FeaturesItem.pSort = RightVosItem.sort
                  this.hasOwn(FeaturesItem)
                  data.push(FeaturesItem)
                })
              }
            })
            this.tableData = data
          }
        }
      })
    },
    hasOwn(item) {
      if (!item.hasOwnProperty("explainText")) {
        item.explainText = ''
      }
    },
  },
}
</script>

<style lang="scss" scoped></style>