<template>
  <div class="height_100">
    <el-container>
      <!-- 统计 -->
      <el-aside class="height_100" :width="showLeft ? '300px' : '0px'" v-show="showLeft">
        <div class="height_100">
          <customFields ref="customFields" :projectId="projectId" :searchOption="searchStr" :customFields="customFields"
            @customTab="handleCustomFields" :searchPatentCheck="searchPatentCheck" :groupField="queryParams.groupField">
          </customFields>
        </div>
      </el-aside>
      <!-- 专利列表 -->
      <el-container>
        <el-header style="display:flex;justify-content:space-between">
          <div style="display:flex">
            <el-tooltip class="item" effect="dark" :content="(showLeft ? '隐藏' : '显示') + '左侧菜单'" placement="top">
              <i :class="showLeft ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
                style="font-size: 25px;position: relative; top: 5px; color: #2f2f2f; cursor: pointer"
                @click="showLeft = !showLeft"></i>
            </el-tooltip>

            <searchPatent ref="searchPatent" :searchFiled="searchFiled" :searchPatentCheck="searchPatentCheck"
              @searchValue="handleSearchValue"></searchPatent>
            
            <el-button size="mini" type="primary" class="margin-left_10" @click="semanticRetrieval">语义检索</el-button>

            <!-- <mySearch :SearchFields="searchFiled" @search="search" :searchValue="searchOption"></mySearch> -->
            <el-popover placement="bottom" title="关键词高亮" width="320" trigger="click">
              <patent-keywords-highlight :project-id="projectId" />
              <el-button slot="reference" size="small" type="primary" class="margin-left_10">
                高亮<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
            </el-popover>

            <el-button size="small" type="success" @click="handleAnalyses" class="margin-left_10" style="font-size:16px;padding:0px 9px;font-wight:0"><i class="el-icon-s-data" style="font-size:18px;"></i> 图表分析</el-button>

          </div>
          <div style="display:flex;align-items:center;">
            <div id="step2">
                <span>分组：</span>
                <el-select v-model="queryParams.groupField" size="small"
                  @change="onChangeFamily" style="width:200px">
                  <el-option v-for="(item, key) in familyObj" :key="key" :label="item" :value="key">
                  </el-option>
                </el-select>
              </div>
            <el-button-group class="margin-left_10">
              <el-tooltip v-for="item in viewList" :key="item.value" class="item" effect="dark" :content="item.title"
                placement="top">
                <el-button @click="handleChangeView(item)" size="small"
                  :type="viewSelected === item.value ? 'primary' : ''">
                  <i :class="item.btn" style="font-size: 12px !important;"></i>
                </el-button>
              </el-tooltip>
            </el-button-group>
            <el-button class="margin-left_10" type="primary" size="small" @click="handleFieldManage" v-if="toProjectId && toProjectName">显示栏位管理</el-button>
            <el-dropdown v-else ref="myDropdown" trigger="click" :hide-on-click="false" split-button type="primary" size="small" @command="clickMyDropdown($event)">
              <span @click="handleFieldManage">显示栏位管理</span>
              <el-dropdown-menu slot="dropdown" class="text-align_center">
                <el-dropdown-item @click.native="handleFile">报告文档</el-dropdown-item>
                <!-- <el-dropdown-item @click.native="handleQuestion" v-if="$permission('/workspace/event')">事
                  件</el-dropdown-item> -->
                <el-dropdown-item @click.native="handleField" v-disabled="false">自定义栏位管理</el-dropdown-item>
                <!-- <el-dropdown-item @click.native="exportPDF">导出PDF首页</el-dropdown-item> -->

                <el-dropdown-item command="e">
                  <el-dropdown @command="patentImport($event)" trigger="hover" placement="right-start">
                    <p>
                      专利导入<i class="el-icon-arrow-right el-icon--right"></i>
                    </p>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item command="1"> Excel导入 </el-dropdown-item>
                      <el-dropdown-item command="2">专利号导入 </el-dropdown-item>
                      <el-dropdown-item command="4">检索条件导入 </el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>

                <el-dropdown-item>
                  <el-dropdown trigger="hover" placement="right-start">
                    <p>
                      导出PDF首页<i class="el-icon-arrow-right el-icon--right"></i>
                    </p>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item @click.native="exportPDF(false)">当前全部</el-dropdown-item>
                      <el-dropdown-item @click.native="exportPDF(true)">当前所选</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
                
                <!-- <el-dropdown-item @click.native="handleBatch"
                  :disabled="!($permission('/workspace/folder/batchUploadSpecification') && $r(projectId, [1, 2]))">批量上传说明书</el-dropdown-item>
                <el-dropdown-item> -->
                <el-dropdown trigger="hover" placement="right-start">
                  <p>
                    导出Excel档<i class="el-icon-arrow-right el-icon--right"></i>
                  </p>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="handleExport(false)">当前全部</el-dropdown-item>
                    <el-dropdown-item @click.native="handleExport(true)">当前所选</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <!-- <el-dropdown-item>
                  <el-dropdown trigger="hover" placement="right-start">
                    <p>
                      {{ familyObj[queryParams.groupField] }}<i class="el-icon-arrow-right el-icon--right"></i>
                    </p>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item v-for="(item, key) in familyObj" :key="key" @click.native="onChangeFamily(key)">{{
                        item }}</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item> -->
                <el-dropdown-item>
                  <el-dropdown trigger="hover" placement="right-start">
                    <p>
                      合并<i class="el-icon-arrow-right el-icon--right"></i>
                    </p>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item @click.native="handleMerge(2)">发明人</el-dropdown-item>
                      <el-dropdown-item @click.native="handleMerge(0)">申请人/权利人</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-dropdown trigger="hover" placement="right-start">
                    <p>
                      创建报告<i class="el-icon-arrow-right el-icon--right"></i>
                    </p>
                    <el-dropdown-menu slot="dropdown" style="margin-top:0px">
                      <!-- 遍历按钮 -->
                      <el-dropdown-item @click.native="handleAnalysesFto">FTO调查</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
                <!-- <el-dropdown-item @click.native="handleAnalyses">图表分析</el-dropdown-item> -->
                <el-dropdown-item @click.native="toNoveltySearch">查新检索</el-dropdown-item>
                <el-dropdown-item @click.native="handleAllocation">任务分配</el-dropdown-item>
                <el-dropdown-item @click.native="taskList">任务清单</el-dropdown-item>
                <el-dropdown-item @click.native="importAndExportHistory">导入导出历史</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>

        </el-header>
        <el-main v-loading="loading" style="padding: 0 !important;">
          <div class="patent-list-container">
            <div class="height_100">
              <component ref="patentViewList" :is="viewSelected" :semanteme="semanteme" @download="handleDownload" @change-read="handleChangeRead"
                :projectId="projectId" :patentNoList.sync="patentNoList" @addSelect="getChoosePatentNo"
                @clickPatentNo="handleClick" :column="customList" @index-setting="handleIndexSetting" @on-sort="handleSort"
                :queryParams="queryParams" :tableData="tableData" :refresh='refresh'></component>
            </div>
          </div>
        </el-main>
        <el-footer class="pagination" style="display:flex;justify-content:space-between;align-items:center">
          <div style="display:flex;align-items:center">
            <span v-if="selectedTotal > 0">
              已勾选 <b>{{ selectedTotal }}</b> 条
            </span>
            <el-popover placement="bottom" title="" width="220" trigger="click">
              <el-main class="patent-fast-edit-popover" v-loading="selectNumberLoading">
                <div class="btn" @click="handleCancelSelectNumber">取消选择</div>
                <div class="btn" @click="handleSelectNumber(0)">本页选择</div>
                <div class="btn" @click="handleSelectNumber(1)">全部选择</div>
                <el-divider></el-divider>
                <div class="select-number">
                  <span>从</span>
                  <el-input size="mini" v-model="queryParams.startNumber" @change="change1"></el-input>
                  <span>到</span>
                  <el-input size="mini" v-model="queryParams.endNumber" @change="change2"></el-input>
                  <el-button type="text" size="" @click="handleSelectNumber(2)">确定</el-button>
                </div>
              </el-main>
              <el-button type="info" size="small" class="margin-left_10" slot="reference"> 选择专利<i
                  class="el-icon-arrow-down el-icon--right"></i></el-button>
            </el-popover>

            <div v-show="selectedTotal > 0" class="margin-left_10">
              <el-dropdown size="medium">
                <el-button type="primary" size="small">
                  批量操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <!-- <el-dropdown-item @click.native="handleRead(1)"
                    :disabled="!$permission('/workspace/folder/isRead')">已读</el-dropdown-item>
                  <el-dropdown-item @click.native="handleRead(0)"
                    :disabled="!$permission('/workspace/folder/isRead')">未读</el-dropdown-item> -->
                  <el-dropdown-item v-if="toProjectId && toProjectName" @click.native="addPatentToReport(toProjectId)">加入到报告({{ toProjectName }})中</el-dropdown-item>
                  <template v-else>
                    <el-dropdown-item @click.native="handleIndex">批量标引</el-dropdown-item>
                    <el-dropdown-item @click.native="checkPatentWorth">价值曲线</el-dropdown-item>
                    <el-dropdown-item @click.native="deletePatents">删除</el-dropdown-item>
                  </template>
                  
                </el-dropdown-menu>
              </el-dropdown>
            </div>
            <!-- 编辑暂时隐藏，默认置为true -->
            <!-- <div class="margin-left_10">
              <el-checkbox @change="changeRefresh" :checked="refresh">
                <span>编辑</span>
              </el-checkbox>
            </div> -->
          </div>
          <div>
            <el-pagination background layout="total, sizes, prev, pager, next, jumper"
              :current-page.sync="queryParams.current" :page-sizes="sizeArr" :page-size.sync="queryParams.size"
              @current-change="handleCurrentChange" @size-change="changeSize" :total="total">
            </el-pagination>
          </div>

        </el-footer>
      </el-container>
    </el-container>

    <Field-Drawer ref="FieldDrawer" @close="closeFieldDrawer"></Field-Drawer>
    <field ref="field" type="patent" :projectId="projectId" @getFieldList="getFieldList"></field>
    <!-- 报告文档 -->
    <reportFileDrawer ref="reportFileDrawer"></reportFileDrawer>
    <!-- 创建FTO报告 -->
    <addAndEditReport ref="addAndEditReport" @addPatentToReport="addPatentToReport"></addAndEditReport>
    <!-- 批量那个标引 -->
    <PatentBatchIndexVue ref="PatentBatchIndexVue" @submit="submitIndex(true)" :projectId="projectId"></PatentBatchIndexVue>
    <!-- 单个栏位标引 -->
    <patent-index-setting @submit="submitIndex(false)" :projectId="projectId" ref="patentIndexSetting" />
    <!-- 合并发明人/合并权利人、申请人 -->
    <patentMergeDrawer ref="patentMergeDrawer" :projectId="projectId" @mergeClose="mergeClose"></patentMergeDrawer>
  </div>
</template>

<script>
import { downLoad2, getTreeDataList, getTreeLastChildren, getPatentCountry } from "@/utils"
import { fastSelectPatent } from './components/mixins/fastSelectPatent'
import FieldDrawer from '@/views/components/drawer/Field.vue'
import PatentAbstractListView from './components/views/Abstract'
import PatentTableListView from './components/views/Table.vue'
import PatentPictureListView from './components/views/Picture'
// import PatentPDFListView from './components/views/PDF.vue'
import field from '@/views/components/dialog/fields.vue';
import customFields from '@/views/report/components/patentList/components/customFields/index.vue';
import searchPatent from '@/views/report/components/patentList/components/searchPatent.vue';
import reportFileDrawer from '@/views/report/components/drawer/reportFileDrawer.vue'
import addAndEditReport from '@/views/report/components/dialog/addAndEditReport.vue'
import PatentBatchIndexVue from './components/dialog/PatentBatchIndex.vue'
import patentMergeDrawer from './components/drawer/merge.vue'
import PatentIndexSetting from "./components/dialog/PatentIndexSetting"
import PatentKeywordsHighlight from '../components/PatentKeywordsHighlight.vue'
export default {
  mixins: [fastSelectPatent],
  components: {
    FieldDrawer,
    PatentAbstractListView,
    PatentTableListView,
    PatentPictureListView,
    field,
    customFields,
    searchPatent,
    reportFileDrawer,
    addAndEditReport,
    PatentBatchIndexVue,
    patentMergeDrawer,
    PatentIndexSetting,
    PatentKeywordsHighlight
  },
  props: {},
  data() {
    return {
      //是否隐藏左侧
      showLeft: true,
      //检索字段
      searchFiled: [],
      // //检索条件
      // searchOption: {
      //   name: localStorage.searchContent,
      // },
      //视图方式
      viewList: [
        {
          value: 'patent-table-list-view',
          title: '表格视图',
          btn: 'el-icon-tickets',
        },
        {
          value: 'patent-abstract-list-view',
          title: '摘要视图',
          btn: 'el-icon-news',
        },
        {
          value: 'patent-picture-list-view',
          title: '图片视图',
          btn: 'el-icon-picture-outline',
        },
        // {
        //   value: 'PatentPDFListView',
        //   title: 'PDF视图',
        //   btn: 'iconfont icon-pdf',
        // }
      ],
      //选择的视图
      viewSelected: "patent-abstract-list-view",
      //显示栏位
      customList: [],
      //同族
      familyObj: {
        '0': '不区分同族',
        // 'simpleFamilyId': '简单同族',
        'inpadocFamilyId': '同族',
        // 'patsnapFamilyId': '扩展同族',
      },
      //页大小
      sizeArr: [10, 20, 30, 40, 50, 100],
      //排序
      sort: [],
      //加载
      loading: false,
      // 统计勾选的值（专利著录（专利本身））
      searchPatentCheck: [],
      // 存放专利本身检索条件
      searchStr: '',
      // 存放自定义栏位的检索条件
      customFields: [],
      semanteme:''
    };
  },
  watch: {},
  computed: {
    // 专题库id
    projectId() {
      return this.$route.query.id
    },
    projectName() {
      return this.$route.query.projectName
    },
    toProjectId(){
      return this.$route.query.toProjectId
    },
    toProjectName(){
      return this.$route.query.toProjectName
    },
  },
  created() { },
  async mounted() {
    this.customList = await this.$commonJS.getCustomField('patent', { projectId: this.projectId, taskId: this.taskId })
    await this.getColumn()
    // 获取专利信息
    this.getList()
  },
  methods: {
    //语义检索
    semanticRetrieval(){
      var _this = this;
      const h = _this.$createElement;
      _this.$msgbox({
          title: '语义检索',
          message: h('div', {
              attrs: {
                  class: 'el-textarea',
              },
          }, [
              h('textarea', {
                  attrs: {
                      class: 'el-textarea__inner',
                      autocomplete: 'off',
                      rows: 4,
                      id:'commentContent'
                  },
                  value: _this.semanteme,
                  on: { change: _this.onCommentInputChange }
              })
          ]),
          showCancelButton: true,
          closeOnClickModal:false,
          confirmButtonText: '检索',
          cancelButtonText: '取消',
          beforeClose: (action, instance, done) => {
              if (action === 'confirm') {
                  instance.confirmButtonLoading = true;
                  _this.queryParams.current = 1
                  _this.getList()
                  done();
                  instance.confirmButtonLoading = false;
              } else {
                  done();
              }
          }
        }).then(action => {
           
        });
    },
    onCommentInputChange() {
      this.semanteme = document.getElementById("commentContent").value;
    },
    // 处理后的条件
    handleSearchValue({ searchStr, customFields }) {
      this.searchStr = searchStr
      this.customFields = customFields
      this.queryParams.current = 1
      this.handleCancelSelectNumber()
      this.getList()
      this.$nextTick(()=>{
        this.$refs.customFields.close()
      })
      
    },
    // 统计组件传的值
    handleCustomFields(val) {
      this.searchPatentCheck  = val
      this.$nextTick(() => {
        this.$refs.searchPatent.search2()
      })
    },
    // 点击专利号进行跳转
    handleClick(row, location) {
      var search = {
        searchOption: {
          searchQuery: this.searchStr || '',
          customFields: this.customFields,
          groupField:this.queryParams.groupField,
          orderDTOList: this.sort,
          moreConditions:true
        },
        location: location,
      }
      this.$s.setSession('search', search)
      this.$router.push(
        {
          path: '/patentDetails/' + row.patentNo,
          query: {
            projectId: this.projectId,
            projectType:'1',//判断是不是从专题库进入专利详情1为专题库2为报告(报告未传2)
            projectName:this.projectName
          }
        }
      )
    },
    //获取table栏位及分组字段、检索字段
    //获取检索字段
    async getColumn() {
      //   let params = ['patent']//原获取检索字段
      //   await this.$api.getParamsCommon(params).then(res => {
      //     if (res.code == 200) {
      //       let conditionDTOList = JSON.parse(JSON.stringify(res.data[0].conditionDTOList))
      //       // 搜索字段
      //       this.searchFiled = this.$commonJS.getField(conditionDTOList, (u) => u.ifSearch == true, {
      //         label: 'name',
      //         value: 'value',
      //         type: 'type',
      //       })
      //     }
      //   })
      let params = [{
        tableName: 'patent',
        projectId: this.projectId,
      }]
      await this.$api.getQueryFields(params).then(res => {
        if (res.code == 200) {
          let conditionDTOList = JSON.parse(JSON.stringify(res.data.data[0].conditionDTOList))
          let field = conditionDTOList.filter(item => {
            return item.group == 'nos'
          })
          let custom = conditionDTOList.filter(item => {
            return item.group == 'customField'
          })
          let customField = custom.filter(item => {
            return item.type != 'tree' && item.type != 'Array'
          })
          let arr = field.concat(customField)
          // 搜索字段
          this.searchFiled = this.$commonJS.getField(arr, (u) => u.ifSearch == true, {
            label: 'name',
            value: 'field',
            type: 'type',
            group: 'group',
            fieldType: 'fieldType',
            groupBy: 'groupBy',
            children:'children'
          })
        }
      })
    },
    //检索
    // search(val) {
    //   let params = {}
    //   val.forEach(item => {
    //     if (item.type == 3) {
    //       params[item.value] = item.searchValue.map(itemValue => {
    //         return itemValue.value
    //       })
    //     } else {
    //       params[item.value] = item.searchValue.label
    //     }
    //   })
    //   // 返回字符串
    //   this.searchOption = params
    //   // 调用查询接口
    //   this.queryParams.current = 1
    //   this.getList()
    // },
    //切换视图
    async handleChangeView(item) {
      this.viewSelected = item.value
      this.queryParams.current = 1
      // if (this.viewSelected == 'PatentPDFListView') {
      //   return false
      // }
      if (this.viewSelected === 'patent-picture-list-view') {
        this.$set(this.queryParams, 'size', 20)
      } else {
        this.queryParams.size = 10
      }
      this.getList()
    },
    //查询专利自定义字段对应的值
    getPatentFields(){
      var arr = this.customList.filter(item=>{
        return item.ifPersonal && !item.ifHidden
      })
      if(arr.length == 0){
        return false
      }
      if(this.tableData.length == 0){
        return false
      }
      var patent = this.tableData[0]
      var customFields = patent.customFields
      if(customFields){
        for(var i = 0;i<customFields.length;i++){
          var index = arr.find(item=>{
            return item.value == customFields[i].value
          })
          if(index != -1){
            arr.splice(index,1)
          }
        }
      }
      var patentNos = this.tableData.map(item=>{
        return item.patentNo
      })
      var params = {
        projectId:this.projectId,
        patentNos:patentNos,
        innerFields:arr.map(item=>{
          return {
            fieldType:item.type,
            fieldId:item.value
          }
        })
      }
      this.$api.getPatentFields(params).then(response=>{
        if(response.code == 200){
          var data = response.data.data
          for(var i = 0;i<data.length;i++){
            var index = patentNos.findIndex(item=>{
              return item == data[i].patentNo
            })
            if(index!=-1){
              this.$set(this.tableData[index],'customFields',data[i].innerClassFields)
            }
          }
        }
      })
    },
    //获取专利信息
    getList(size) {
      if (size) {
        this.queryParams.size = size
      }
      let params = {
        ...this.queryParams,//分页信息及区分同族类型
        projectId: this.projectId,
        searchQuery: this.searchStr || '',//检索条件
        customFields: this.customFields,
        orderDTOList: this.sort,//排序信息
        semanteme:this.semanteme
      }
      this.loading = true
      this.$commonJS.scrollToTop()
      // this.$store.commit("SET_PATENT_PARAMS", params);
      this.$store.commit("SET_PATENT_RECORDS", []);
      this.$api.QueryPatent(params).then(res => {
        if (res.code == 200) {
          if(params.semanteme){
            res.data.data.forEach(item=>{
              var score = (item.score * 100 + '').substring(0, 5)
              item.score =  Number(score)
            })
          }
          this.tableData = res.data.data
          
          this.total = res.data.total


          this.$set(this.queryParams, 'startNumber', this.endNumber > 0 ? this.startNumber : 1)
          this.$set(this.queryParams, 'endNumber', this.endNumber > 0 ? this.endNumber : this.total)
          // this.$store.commit("SET_PATENT_PARAMS", params);
          this.$store.commit("SET_PATENT_RECORDS", res.data.data);
          if (this.quickSelect) {
            this.commonSwitch()
          }
          this.isRefresh()
          this.getPatentFields()
          this.loading = false
        }
      }).catch(error => {
        this.tableData = []
        this.total = 0
        this.loading = false
      })
    },
    //排序
    handleSort({ column, prop, order }) {
      //如需要多个字段排序，则不需要清空
      var params = {
        sort: this.sort,
        column,
        prop,
        order,
      }
      this.sort = this.$commonJS.getSortData(params)
      this.queryParams.current = 1
      this.getList()
    },
    //分页
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },
    //切换页大小
    changeSize(val){
      this.queryParams.size = val
      this.queryParams.current = 1
      this.getList()
    },

    //自定义栏位管理
    async handleField() {
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      this.$refs.FieldDrawer.open(this.projectId)
    },
    //关闭自定义栏位弹窗
    async closeFieldDrawer(projectId,change){
      if(change){
        this.customList = await this.$commonJS.getCustomField('patent', { projectId: this.projectId, taskId: this.taskId })
        this.getColumn()
        this.$refs.customFields.refreshField()
      }
    },
    //获取显示栏位
    getFieldList(data) {
      this.customList = []
        this.$nextTick(()=>{
            this.customList = data
            this.getPatentFields()
        })
      
    },
    //显示栏位管理
    async handleFieldManage() {
      this.$refs.field.open(this.customList)
    },
    //报告文档
    handleFile() {
      this.$refs.reportFileDrawer.open(this.projectId)
    },
    //创建FTO报告
    handleAnalysesFto() {
      if(!this.$permission.FunPermissions('xiaoshi/report/FTO')){
        this.$showPermissionDialog()
        return false
      }
      var form = {
        reportType: 3,
        signPatentNo: '',
        matterId: [],
        scenarioId: [],
        assoReportId: this.projectId,
      }
      var havePatent = this.selectedTotal>0
      this.$refs.addAndEditReport.open(form,havePatent)
    },
    //添加专利到报告中
    addPatentToReport(reportId){
      if(!reportId){
        return 
      }
      var params = {
        stringRequest:{
          projectId: this.projectId,
          searchQuery: this.searchStr,
          customFields: this.customFields,
          orderDTOList:this.sort,
          groupField:this.queryParams.groupField
        },
        fromProjectId:this.projectId, //来源专题库项目id
        startNumber:this.startNumber, //开始位置
        endNumber:this.endNumber,//结束位置
        toProjectId:reportId, //目标报告项目id
        isAdd:this.queryParams.isAdd, //去除专利号
        isDelete:this.queryParams.isDelete, //附加专利号
      }
      var message = this.$message({
        type:'warning',
        message: '正在将专利导入报告中...',
        duration: 0 // 设置为0表示不自动关闭
      })

      this.$api.addProjectPatentToReport(params).then(res=>{
        if(res.code == 200){
          message.close()
          this.$message(
            {
              type:'success',
              message:'导入成功'
            }
          )
        }
      }).catch(error=>{
        message.close()
        this.$message(
            {
              type:'error',
              message:'导入失败'
            }
          )
      })
    },
    //切换同族
    onChangeFamily(key) {
      this.queryParams.current = 1
      this.queryParams.groupField = key
      this.handleCancelSelectNumber()
      this.getList()
      this.$nextTick(()=>{
        this.$refs.customFields.refreshOptions(1)
      })
    },
   
    //价值曲线
    async checkPatentWorth(){
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      let obj = {
        isAdd: this.queryParams.isAdd,
        isDelete: this.queryParams.isDelete,
        startNumber: this.startNumber,
        endNumber: this.endNumber,
        searchQuery: this.searchStr,
        customFields: this.customFields,
        groupField:this.queryParams.groupField,
        orderDTOList:this.sort,
        projectId: this.projectId,
      }
      
      let router = this.$router.resolve({
        path: '/patentWorth',
        query: {
          searchData:JSON.stringify(obj)
        }
      })
      window.open(router.href, '_blank')
    },
    //导出专利
    async handleExport(val) {
      if (val) {
        if ( this.endNumber < 1 && this.queryParams.isAdd.length == 0) {
          this.$message.error('请先选择专利')
          return false
        }
      }
      let obj = {
        isAdd: this.queryParams.isAdd,
        isDelete: this.queryParams.isDelete,
        startNumber: this.startNumber,
        endNumber: this.endNumber,
        searchQuery: this.searchStr,
        customFields: this.customFields,
        groupField:this.queryParams.groupField,
        orderDTOList:this.sort,
      }
      if (!val) {
        // 如果是导出全部，endNumber是当前的全部专利
        obj.endNumber=this.total
      }
      let router = this.$router.resolve({
        path: '/exportPatent',
        query: {
          projectId: this.projectId,
          condition: JSON.stringify(obj)
        }
      })
      window.open(router.href, '_blank')
    },
    //PDF首页导出
    exportPDF(sign) {
      if (sign) {
        if ( this.endNumber < 1 && this.queryParams.isAdd.length == 0) {
          this.$message.error('请先选择专利')
          return false
        }
      }
      if(sign){
        var params = {
          projectId: this.projectId,
          searchQuery: this.searchStr || '',//检索条件
          customFields: this.customFields || [],//自定义字段的检索
          groupField:this.queryParams.groupField,
          isAdd: this.queryParams.isAdd,
          isDelete: this.queryParams.isDelete,
          startNumber: this.startNumber,
          endNumber: this.endNumber,
          orderDTOList:this.sort,
        }
      }else{
        var params = {
          projectId: this.projectId,
          searchQuery: this.searchStr || '',//检索条件
          customFields: this.customFields || [],//自定义字段的检索
          groupField:this.queryParams.groupField,
          isAdd: [],
          isDelete: [],
          startNumber: 1,
          endNumber: this.total,//默认是当前全部
          orderDTOList:this.sort,
        }
      }
      
      this.$api.exportPDFFirstPage(params).then(res => {
        if (res.code == 200) {
          const h = this.$createElement;
          this.$msgbox({
            title: '提示',
            message: h('p', null, [
              h('span', null, '任务正在导入，查看任务进度请前往 '),
              h('span', {
                style: 'color: #ff7d38;cursor: pointer;',
                on: {
                  click: () => {//
                    let router = this.$router.resolve({
                      path: '/taskList',
                      query: {
                        importToId: this.projectId,
                      }
                    })
                    window.open(router.href, '_blank')
                    this.$msgbox.close(false)
                  }
                }
              }, '立即前往',)
            ]),
            type: 'warning',
            showConfirmButton: false,
          }).then(action => {
          });
        }
      })
    },
    //图表分析
    async handleAnalyses() {
      var params = {
        condition: this.searchStr || '',//检索条件
        customFields: this.customFields || [],
        groupField:this.queryParams.groupField,
        orderDTOList: this.sort,//排序信息
        projectId:this.projectId
      }
      const router = this.$router.resolve({
        path: '/customChart',
        query: {
          projectId: this.projectId,
          search:JSON.stringify(params),
          patentNum:this.total
        }
      })
      window.open(router.href, '_blank');
    },
    //去查新检索
    toNoveltySearch(){
      const router = this.$router.resolve({
        path: '/conditionImport',
        query:{
          noveltySearch:true,
          innerProjectId:this.projectId
        }
      })
      window.open(router.href, '_blank');
    },
    // 跳转分配任务页面
    async handleAllocation() {
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      this.$router.push(
        {
          path: '/allocationTask',
          query: {
            projectId: this.projectId,
            searchOption: this.searchStr,//输入框检索条件
            groupField:this.queryParams.groupField,
            customFields: JSON.stringify(this.customFields),//右侧勾选自定义栏位的条件
            projectType:1
          }
        }
      )
    },
    //任务清单
    async taskList(){
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      this.$router.push(
        {
          path:'/myTask',
          query:{
            projectId:this.projectId
          }
        }
      )
    },
    //导入导出历史
    async importAndExportHistory(){
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      this.$router.push({
                path: "/taskList",
                query:{
                    importToId:this.projectId
                }
            });
    },
    clickMyDropdown(e){
      if(e == undefined){
        this.$refs.myDropdown.hide()
      }
    },
     //专利导入
    async patentImport(type){
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      var form = {
        importToId:this.projectId,
        importToType:0,
        type:type,
      }
      this.$commonJS.toImportParent(form,type)
    },
    //合并发明人//合并申请人、权利人
    async handleMerge(type) {
      if(!(await this.$permission.projectPermission(this.projectId))){
        this.$showPermissionDialog()
        return false
      }
      let obj = {
        projectId: this.projectId,
        mergeType: type
      }
      let title = type == 2?'合并发明人':'合并申请人/权利人'
      this.$refs.patentMergeDrawer.open(obj,title)
    },
    // 合并发明人、申请人、权利人后子组件发送的消息
    mergeClose() {
      this.getList()
      this.$refs.customFields.refreshOptions(1)
    },



    //自定义栏位以及标签设置值
    async handleIndexSetting(patent, field) {
      if(!(await this.$permission.projectPermission(this.projectId))){
        // this.$showPermissionDialog()
        return false
      }
      let obj = {
        isAdd: [patent.patentNo],
        isDelete: [],
        startNumber: 1,
        endNumber: 0,
        searchQuery: this.searchStr,
        customFields: this.customFields,
        groupField:this.queryParams.groupField,
        orderDTOList:this.sort,
      }
      if (field) {
        this.$refs.patentIndexSetting.open(obj,patent, field)
      }
    },
    submitIndex(value){
      if(value){
        this.handleCancelSelectNumber()
      }
      
      this.getList()
      this.$refs.customFields.refreshOptions(1)
    },

















    //下载PDF
    async handleDownload(patent) {
      const { data } = await this.$api.getPatentInstructionList({ current: 1, size: 9999, patentNo: patent.patentNo })
      if (data.records.length !== 0) {
        downLoad2(data.records[0].url)
      } else {
        this.$alert('专利暂未上传说明书文档', '请求错误', {
          confirmButtonText: '确定',
          type: 'error',
          callback: action => { }
        });
      }
    },
    //切换已读未读
    handleChangeRead(ids, status) {
      let params = {
        patentIds: ids,
        projectId: this.projectId,
        status: status,
        folder: this.queryParams.folder
      }
      this.fastEditLoading = true
      this.$api.updatePatentReadStatus(params).then(response => {
        this.$refs.patentQueryFilter.getPatentReadTotal()
        this.fastEditLoading = false
        this.getList()
      }).catch(error => {
        this.fastEditLoading = false
      })
    },
    //自定义栏位以及标签设置值
    // handleIndexSetting(patent, field) {
    //   if (field) {
    //     this.$refs.patentIndexSetting.open(this.queryParams.projectId, patent, field)
    //   }
    // },

    //取消编辑
    // changeRefresh() {
    //   this.patentNoList = []
    //   // this.refresh = !this.refresh
    // },





  },
};
</script>
<style lang="scss" scoped>
.patent-fast-edit-popover {
  padding: 0 !important;

  .btn {
    color: #000;
    line-height: 30px;
    border-radius: 5px;
    padding-left: 10px;
    text-align: left;
    font-size: 14px;
    cursor: pointer;

    &:hover {
      background: #adadad;
      color: #fff;
    }
  }

  .disabled {
    cursor: not-allowed !important;
  }

  .bottom {
    text-align: right;
    color: #1e9fff;
    line-height: 40px;
    padding-left: 10px;
    font-size: 18px;
  }

  .el-divider--horizontal {
    margin: 10px 0 !important;
  }

  .select-number {
    .el-input {
      width: 70px;
    }

    span {
      padding: 0 3px;
    }
  }
}
</style>