<template>
  <div class="height_100">
    <el-container>
      <el-header>
        <div style="padding: 20px;">
          <p> 标的专利号：<el-link type="primary" @click="toPatentDetails(patentNo)">{{ patentNo }}</el-link> </p>
        </div>
      </el-header>
      <el-main style="padding:20px;height: calc(100% - 100px);">
        <!-- 拆分特征公用组件 -->
        <splitPage style="height: calc(100% - 103px);overflow: auto;" :tableData="tableData"
        :patentNo="patentNo" :projectId="projectId" :columnList="columnList" @splitSelect="splitSelect"
          @isSave="isSave"></splitPage>

        <!-- 回避设计总体方向 -->
        <div style="margin-top: 20px;">
          <p>回避设计总体方向：</p>
          <div>
            <myRichText v-model="wholeContent" placeholder="请输入回避设计总体方向（可粘贴图片）"></myRichText>
          </div>
        </div>
      </el-main>
    </el-container>

  </div>
</template>

<script>
import { patentDetails } from '../../components/mixins/index2'
import mixins from './mixins'
import splitPage from '../../components/splitPage/splitPage.vue';
export default {
  props: ['patentNo', 'projectId',],
  mixins:[patentDetails,mixins],
  components: {
    splitPage,
  },
  data() {
    return {
     
    };
  },
  watch: {
  },
  mounted() {

  },
  methods: {
    // 保存
    isSave(val) {
      // let params = this.handleData(val)
      let params = {
        projectId: this.projectId,
        wholeContent: this.wholeContent,
        avoidDesignDTOS: val,
      }
      this.$api.addAvoidDesign(params).then(res => {
        if (res.code == 200) {
          this.$message.success('保存成功')
        }
      })
    },
    // 处理需要保存的数据()
    handleData(tableData) {
      let keepArr = [
        {
          rightName: tableData[0].pRightName,
          signPatentNo: tableData[0].pSignPatentNo,
          patentNo: tableData[0].pPatentNo,
          content: tableData[0].pContent,
          contentOut: tableData[0].pContentOut,
          sort: tableData[0].pSort,
          type: tableData[0].pType,
          projectId: tableData[0].pReportId,
          features: [],
        }
      ]
      var j = 0
      for (let i = 0; i < tableData.length; i++) {
        if (keepArr.findIndex(item => { return item.rightName == tableData[i].pRightName }) < 0) {

          j += 1
          keepArr.push(
            {
              rightName: tableData[i].pRightName,
              signPatentNo: tableData[i].pSignPatentNo,
              patentNo: tableData[i].pPatentNo,
              content: tableData[i].pContent,
              contentOut: tableData[i].pContentOut,
              sort: tableData[i].pSort,
              type: tableData[i].pType,
              projectId: tableData[i].pReportId,
              features: [],
            }
          )
        }
        keepArr[j].features.push({
          content: tableData[i].content,
          direction: tableData[i].direction ? tableData[i].direction : '',
          projectId: tableData[i].projectId,
          explainText: tableData[i].explainText ? tableData[i].explainText : '',
          contentOut: tableData[i].contentOut ? tableData[i].contentOut : '',
          rightSort: tableData[i].rightSort,
          rightType: tableData[i].rightType,
          id: tableData[i].id,
          patentNo: tableData[i].patentNo,
        })
      }
      let keepStr = {
        projectId: this.projectId,
        avoidDesignDTOS: keepArr,
        wholeContent: this.wholeContent ? this.wholeContent : ''
      }
      return keepStr
    },
    // 改变拆分条件
    splitSelect(split) {
      this.getList(split,true)
    },
    // 获取拆分数据(弃用)
    getSplitList(val) {
      let params = {
        patentNo: this.patentNo,
        projectId: Number(this.projectId),
        ...val,//拆分条件
      }
      this.$api.spiltFeature(params).then(res => {
        if (res.code == 200) {
          // this.textarea.wholeDirection = res.data.wholeDirection
          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
          }
        }
      })
    },
   

  }
}
</script>

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