<template>
  <div class="workspace-content">
    <el-container>
      <el-header class="workspace-content-header">
        <div class="header-tabs" v-if="showLeft">
          <el-tabs v-model="activeName" type="card" @tab-click="handleTabClick">
            <el-tab-pane label="文件夹" name="0"></el-tab-pane>
            <el-tab-pane label="查询筛选" name="1"></el-tab-pane>
            <el-tab-pane label="分类选择" name="2"></el-tab-pane>
          </el-tabs>
        </div>
        <div class="workspace-content-header-left" :style="{ left: showLeft ? '300px' : '0' }">
          <div class="workspace-content-header-left-box" 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>
            <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-right_10 margin-left_10" :disabled="!$permission('/workspace/common/highlight')">
                  高亮<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
              </el-popover>
            <!-- <el-button-group class="margin-left_10">
              <el-tooltip v-for="item in viewList" class="item" effect="dark" :content="item.title" placement="top">
                <el-button @click="handleChangeView(item)" size="small" :type="viewSelected === item.value ? 'primary' : ''" :icon="item.btn"></el-button>
              </el-tooltip>
            </el-button-group>
            <el-popover placement="bottom" title="" width="300" trigger="hover" class="margin-left_10">
              <el-main class="workspace-content-header-query-main">
                <div v-for="(item, index) in queryData" class="workspace-content-header-query-box">
                  <el-alert type="success" :closable="false" v-if="item.data.length">
                    <div class="workspace-content-header-query-content">
                      <div class="color-black">{{ item.name }}</div>
                      <b class="padding-right_10">AND</b>
                      <span class="color-black">
                        <span>
                          <span class="padding_0_5">(</span>
                          <span v-for="(data, i) in item.data">
                            <span class="query-data-label" @click="handleCancelQueryParams(item, index, i)">{{ data.label }}<i class="el-icon-close"></i></span>
                            <b v-if="item.data.length - 1 > i" class="padding_0_5 color-primary">OR</b>
                          </span>
                          <span class="padding_0_5">)</span>
                        </span>
                      </span>
                    </div>
                  </el-alert>
                </div>
              </el-main>
              <el-button slot="reference" size="small" type="primary" style="">
                检索条件<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
            </el-popover>
            <el-button size="small" type="primary" style="margin-left:10px" @click="handleFile">报告文档</el-button>
            <el-button type="primary" size="small" class="margin-left_10" @click="handleQuestion" v-if="$permission('/workspace/event')">事 件</el-button> -->
          </div>
        </div>
        <div class="workspace-content-header-right">
          <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-dropdown trigger="click" split-button type="primary" size="small">
            <p @click="handleField" v-disabled="!($permission('/workspace/common/customField') && $r(projectId,[1,2]))">自定义栏位管理</p>
            <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="handleFieldManage">显示栏位管理</el-dropdown-item>
              <el-dropdown-item @click.native="exportPDF">导出PDF首页</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">
                    <span>
                      导出专利<i class="el-icon-arrow-right el-icon--right"></i>
                    </span>
                    <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-item>
                <el-dropdown  trigger="hover" placement="right-start">
                  <span>
                    {{ familyObj[queryParams.family] }}<i class="el-icon-arrow-right el-icon--right"></i>
                  </span>
                  <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 :disabled="!$permission('/workspace/folder/merge')">
                <el-dropdown trigger="hover" placement="right-start">
                  <span >
                    合并<i class="el-icon-arrow-right el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="handleMerge2" :disabled="!($permission('/workspace/folder/merge/inventorMerge') && $r(projectId,[1,2]))">发明人</el-dropdown-item>
                    <el-dropdown-item @click.native="handleMerge" :disabled="!($permission('/workspace/folder/merge/applicationMerge') && $r(projectId,[1,2]))">申请人/权利人</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-dropdown-item>
              <el-dropdown-item v-if="$permission('/workspace/createReport')">
                <el-dropdown trigger="hover" placement="right-start">
                  <span>
                      创建报告<i class="el-icon-arrow-right el-icon--right"></i>
                  </span>
                   <el-dropdown-menu slot="dropdown" style="margin-top:0px">
                    <!-- 遍历按钮 -->
                      <el-dropdown-item  @click.native="handleAnalyses(3)" v-if="$permission('/workspace/createReport/FTO')">FTO调查</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleAnalyse('custom')" :disabled="!($permission('/workspace/folder/analyticSystem/chartAnalysis') && $r(projectId,[1,2,4]))">图表分析</el-dropdown-item>
              <!-- <el-dropdown-item>
                <el-popover placement="bottom" title="关键词高亮" width="320" trigger="hover">
                  <patent-keywords-highlight :project-id="projectId" />
                  <span slot="reference" v-disabled="!$permission('/workspace/common/highlight')">
                    高亮<i class="el-icon-arrow-right el-icon--right"></i>
                  </span>
                </el-popover>
                </el-dropdown-item> -->
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button type="primary" size="small" @click="handleField" :disabled="!($permission('/workspace/common/customField') && $r(projectId,[1,2]))">自定义栏位管理</el-button>
          <el-button :disabled="!($permission('/workspace/folder/batchUploadSpecification') && $r(projectId,[1,2]))" type="warning" size="small" @click="handleBatch">批量上传说明书</el-button>
          <el-dropdown size="medium">
            <el-button type="warning" size="small" :disabled="!$permission('/workspace/folder/exportPatent')">
              导出专利<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <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 size="medium" class="">
            <el-button type="primary" size="small">
              {{ familyObj[queryParams.family] }}<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-for="(item, key) in familyObj" @click.native="onChangeFamily(key)">{{ item }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-dropdown size="medium" class="">
            <el-button type="primary" size="small" :disabled="!$permission('/workspace/folder/merge')">
              合并<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleMerge2" :disabled="!($permission('/workspace/folder/merge/inventorMerge') && $r(projectId,[1,2]))">发明人</el-dropdown-item>
              <el-dropdown-item @click.native="handleMerge" :disabled="!($permission('/workspace/folder/merge/applicationMerge') && $r(projectId,[1,2]))">申请人/权利人</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown> -->
        </div>
      </el-header>
      <el-container class="workspace-content-container">
        <el-aside v-if="showLeft" width="300px" class="workspace-content-container-aside" v-loading="menuLoading">
          <div v-if="refresh" class="workspace-content-container-aside-box">
            <patent-folder-filter v-show="activeName === '0'" ref="patentFolderFilter" @on-change="folderFilterChange" />
            <patent-query-filter v-show="activeName === '1'" ref="patentQueryFilter" @on-change="queryFilterChange" @text-change="textQueryFilterChange" />
            <patent-tree-filter v-if="activeName === '2'" ref="patentTreeFilter" @on-change="treeFilterChange" />
          </div>
        </el-aside>
        <el-container>
          <el-header class="workspace-content-container-header">
            <div>
              <div class="float_right selected-total" v-if="queryParams.selected.length">
                已勾选 <b>{{ queryParams.selected.length }}</b> 条
              </div>
              <div v-show="queryParams.selected.length" class="workspace-content-container-header-fast-option">
                <el-dropdown size="medium" v-loading="fastEditLoading">
                  <el-button type="primary" size="small" :disabled="!$permission('/workspace/folder/batchOperation')">
                    批量操作<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 @click.native="handleMove(0)" v-if="queryParams.folder" :disabled="!($permission('/workspace/folder/batchOperation/move') && $r(projectId,[1,2]))">移动</el-dropdown-item>
                    <el-dropdown-item @click.native="handleMove(1)" :disabled="!($permission('/workspace/folder/batchOperation/copy') && $r(projectId,[1,2]))">复制</el-dropdown-item>
                    <el-dropdown-item @click.native="handleRemove" :disabled="!($permission('/workspace/folder/batchOperation/remove') && $r(projectId,[1,2]))">移除</el-dropdown-item>
                    <el-dropdown-item @click.native="handleIndex" :disabled="!($permission('/workspace/folder/batchOperation/batchIndexing') && $r(projectId,[1,2]))">批量标引</el-dropdown-item>
                    <el-dropdown-item @click.native="checkPatentWorth"  v-if="queryParams.selected.length && $permission('/workspace/patent/worth')">价值曲线</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div>
              <!-- <el-button size="small" type="primary" @click="checkPatentWorth" v-if="queryParams.selected.length && $permission('/workspace/patent/worth')">价值曲线</el-button>
              <el-dropdown size="medium" v-if="$permission('/workspace/createReport')">
                <el-button type="primary" size="small" >
                    创建报告<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                   <el-dropdown-menu slot="dropdown" style="margin-top:0px">
                      <el-dropdown-item  @click.native="handleAnalyses(3)" v-if="$permission('/workspace/createReport/FTO')">FTO调查</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <el-button size="small" type="primary" style="margin-right:10px" @click.native="handleAnalyse('custom')" :disabled="!($permission('/workspace/folder/analyticSystem/chartAnalysis') && $r(projectId,[1,2,4]))">图表分析</el-button>

              <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-right_10" :disabled="!$permission('/workspace/common/highlight')">
                  高亮<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
              </el-popover>
              <el-button size="small" type="warning" @click="handleFieldManage">显示栏位管理</el-button> -->
              <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"></el-input>
                    <span>到</span>
                    <el-input size="mini" v-model="queryParams.endNumber"></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>
              <!-- <el-button type="text" size="small" class="margin-left_10" @click="handleCancelSelectNumber">取消选择</el-button> -->
              
            </div>
          </el-header>
          <el-main id="patent-list-container" v-loading="loading">
            <div v-if="refreshList">
              <component
                  ref="patentViewList"
                  :is="viewSelected"
                  @download="handleDownload"
                  @change-read="handleChangeRead"
                  @select-change="handleSelect"
                  :projectId="projectId"
                  :selected.sync="queryParams.selected"
                  :patentNoList.sync="patentNoList"
                  :view-field="patentViewField"
                  @index-setting="handleIndexSetting"
                  @on-sort="handleSort"
                  :queryParams="queryParams"
              ></component>
            </div>
          </el-main>
          <el-footer class="workspace-content-patent-page" v-if="viewSelected != 'PatentPDFListView'">
            <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="getList"
                :total="total">
            </el-pagination>
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
    <CreateReport ref="ReportForm"></CreateReport>
    <project-file-drawer  ref="projectFileDrawer" />
    <patent-applicant-merge-drawer @close="close" ref="patentApplicantMergeDrawer" />

    <patent-inventor-merge-drawer @close="close" ref="patentInventorMergeDrawer" />

    <patent-view-field @close="close" @reset="getPatentViewField(true)" @update="updatePatentViewField" ref="patentViewField" />

    <patent-batch-index :params="queryParams" @submit="submitIndex" ref="patentBatchIndex" />

    <patent-move-select-folder :params="queryParams" :move-type="moveType" @submit="handleMovePatent" ref="patentMoveSelectFolder" />

    <patent-index-setting @close="close2" @submit="submitIndex" ref="patentIndexSetting" />

    <report-template-drawer @close="close" ref="reportTemplateDrawer" />

    <project-field-drawer @close="close" ref="projectFieldDrawer" />

    <batch-instruction-dialog @close="close" ref="batchInstructionDialog" />
    
  </div>
</template>

<script>
import ProjectFileDrawer from "@/views/workspace/components/drawer/File.vue";
import PatentApplicantMergeDrawer from './components/drawer/MergeApplicant'
import PatentInventorMergeDrawer from './components/drawer/MergeInventor'
import ReportTemplateDrawer from './components/drawer/ReportTemplate'
import PatentQueryFilter from './components/filter/Query'
import PatentFolderFilter from './components/filter/Folder'
import PatentTreeFilter from './components/filter/Tree'
import PatentAbstractListView from './components/view/Abstract'
import PatentTableListView from './components/view/Table'
import PatentViewField from "./components/dialog/PatentViewField"
import PatentMoveSelectFolder from "./components/dialog/PatentMoveSelectFolder"
import PatentBatchIndex from "./components/dialog/PatentBatchIndex"
import PatentIndexSetting from "./components/dialog/PatentIndexSetting"
import PatentKeywordsHighlight from "./components/PatentKeywordsHighlight"
import ProjectFieldDrawer from '@/views/workspace/components/drawer/Field'
import BatchInstructionDialog from '@/views/workspace/components/dialog/BatchInstruction'
import { downLoad2, getTreeDataList, getTreeLastChildren, getPatentCountry } from "@/utils"

import CreateReport from '../folder/articles/components/CreateReport.vue'
import PatentPictureListView from './components/view/Picture'

import PatentPDFListView from './components/view/PDF.vue'
export default {
  components: {
    ProjectFileDrawer,
    ProjectFieldDrawer,
    BatchInstructionDialog,
    ReportTemplateDrawer,
    PatentApplicantMergeDrawer,
    PatentInventorMergeDrawer,
    PatentQueryFilter,
    PatentFolderFilter,
    PatentTreeFilter,
    PatentAbstractListView,
    PatentTableListView,
    PatentViewField,
    PatentMoveSelectFolder,
    PatentBatchIndex,
    PatentIndexSetting,
    PatentKeywordsHighlight,
    CreateReport,
    PatentPictureListView,
    PatentPDFListView
  },
  data() {
    return {
      searchFiled:[
        {
          label:'标题',
          value:'name',
          type:1,
          placeholder:'请输入查询内容'
        },
        {
          label:'摘要',
          value:'abstractStr',
          type:1,
          placeholder:'请输入查询内容'
        },
        {
          label:'权利要求',
          value:'rightContent',
          type:1,
          placeholder:'请输入查询内容'
        },
        {
          label:'公开号',
          value:'publicNo',
          type:1,
          placeholder:'请输入查询内容'
        },
        {
          label:'申请号',
          value:'applicationNo',
          type:1,
          placeholder:'请输入查询内容'
        },
      ],
      searchOption:{},
      sizeArr:[10, 20, 30, 40, 50, 100],
      patentNoList:[],
      showLeft: true,
      projectId: 0,
      moveType: 0,
      queryParams: {
        folder: null,
        projectId: null,
        read: 'all',
        current: 1,
        size: 10,
        name: '',
        abstractStr: '',
        publicNo: '',
        applicationNo: '',
        rightContent: '',
        sort: {
          order: 'asc',
          prop: 'id'
        },
        field: [],
        tree: [],
        selected: [],
        startNumber: 1,
        endNumber: 0,
        family: 0
      },
      activeName: '0',
      total: 0,
      viewSelected: 'patent-table-list-view',
      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',
        }
      ],
      patentViewField: [],
      refresh: true,
      refreshList: true,
      exportLoading: false,
      chartLoading: false,
      loading: false,
      fastEditLoading: false,
      selectNumberLoading: false,
      familyObj: {
        0: '不区分同族',
        1: '简单同族',
        2: 'INPADOC同族',
        3: '扩展同族',
      },
      scrollTop:0
    }
  },
  computed: {
    records() {
      return this.$store.state.patent.records
    },
    menuLoading() {
      return this.$store.state.patent.menuLoading
    },
    queryData() {
      return this.$store.state.patent.queryData
    },
    params() {
      return this.$store.state.patent.params
    },
    closeFieldDrawer() {
      return this.$store.state.project.closeFieldDrawer
    }
  },
  watch: {
    closeFieldDrawer() {
      this.getPatentViewField()
      this.getList()
    }
  },
  created() {
    this.projectId = this.$route.query.id
    this.queryParams.projectId = this.projectId
    this.$store.commit('SET_PATENT_PROJECT_ID', this.projectId)
  },
  mounted() {
    this.getPatentViewField()
    this.getList()
  },
  methods: {
    //搜索
    search(val){
      var params = {}
      if(val.length>0){
        val.forEach(item => {
          if(item.type == 3){
            params[item.value] = item.searchValue.map(item1=>{
              return item1.value
            }) 
          }else{
            params[item.value] = item.searchValue.label
          }
        });
      }
      this.searchOption = params
      this.queryParams.current = 1
      this.getList()
    },
    //查看价值曲线
    checkPatentWorth(){
      this.$s.setSession('PatentWorth',this.patentNoList)
      const router = this.$router.resolve({
           path: '/patentWorth',
          //  query: {
          //   patentNoList:this.patentNoList
          //  }
          })
      window.open(router.href, '_blank');
    },
    handleFile() {
      this.$refs.projectFileDrawer.open(this.projectId, 1)
    },
    handleAnalyses(id) {
      this.$api.getProject({id:this.projectId}).then(response=>{
        var form = {
          type:id,
          projectId:this.projectId,
          departmentId:response.data[0].departmentId,
          personId:response.data[0].personnelId,
          clientId:response.data[0].clientId,
          proTec:response.data[0].technicalTheme,
          scenarioList:response.data[0].scenarioList
      }
      this.$refs.ReportForm.open(form)
      })

    },
    handleCancelQueryParams(data, index, i) {
      switch (data.type) {
        case 'folder':
          this.$refs.patentFolderFilter.refreshView()
          this.folderFilterChange(null)
          this.$store.commit('SET_PATENT_QUERY_DATA', [])
          break;
        case 'text':
          this.queryParams[data.key] = '';
          data.data.splice(i, 1);
          this.getList()
          break;
        default:
          let query = this.queryParams[data.type].find(item => item.key === data.key)
          const value = data.data[i].value
          const index = query.value.indexOf(value);
          query.value.splice(index, 1);
          if (data.type === 'tree') {
            const keys = data.key.split('-')
            if (keys[1] === '0') {
              const treeData = getTreeDataList(data.tree, [])
              const children = getTreeDataList(treeData.filter(item => item.id === value), [])
              children.forEach(item => {
                query.value.splice(query.value.indexOf(item.id), 1);
              })
            }
            try {
              this.$refs.patentTreeFilter.refreshTreeSelected(keys, value)
            } catch (e) {
              // console.error(e)
            }
          } else {
            this.$refs.patentQueryFilter.refreshSourceData()
          }
          data.data.splice(i, 1);
          this.getList();
          break
      }
    },
    handleIndexSetting(patent, field) {
      if (field) {
        this.$refs.patentIndexSetting.open(this.queryParams.projectId, patent, field)
      }
    },
    handleSort(data) {
      this.queryParams.sort = data
      this.getList()
    },
    handleRead(status) {
      this.handleChangeRead(this.queryParams.selected, status)
    },
    handleRefreshList() {
      this.getList()
      // this.refreshList = false
      // this.$nextTick(() => {
      //   this.refreshList = true
      // })
    },
    handleSelectNumber(type) {
      let params = { ...this.queryParams }
      if(params.field.length == 0){
        params.field = params.tree
      }
      
      switch (type) {
        case 0:
          this.queryParams.selected = this.records.map(item => item.id);
          this.handleRefreshList()
          break
        case 1:
          params.startNumber = 1;
          params.endNumber = this.total
        case 2:
          this.selectNumberLoading = true
          this.$api.getPatentListIds(params).then(response => {
            this.queryParams.selected = response.data
            this.selectNumberLoading = false
            this.handleRefreshList()
          }).catch(error => {
            this.selectNumberLoading = false
          })
          break
      }
    },
    handleCancelSelectNumber() {
      this.queryParams.selected = []
      this.handleRefreshList()
    },
     // 事件按钮
    handleQuestion() {
      let a=this.$router.resolve({
        path: '/questionEvent',
        query: {
          projectId:this.projectId
        }
      })
      window.open(a.href, '_blank');
    },
    handleRemove() {
      this.$confirm('确认操作吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const folder = this.queryParams.folder
        const ids = this.queryParams.selected.toString()
        if (folder) {
          this.$api.deleteProjectFolderPatent({ folderId: folder, ids: ids }).then(response => {
            this.queryParams.selected = []
            this.getList()
            this.$refs.patentFolderFilter.getList()
            this.$message.success('操作成功')
          }).catch(error => {

          })
        } else {
          this.$api.deleteProjectPatent({ projectId: this.projectId, ids: ids }).then(response => {
            this.queryParams.selected = []
            this.getList()
            this.$refs.patentFolderFilter.getList()
            this.$message.success('操作成功')
          }).catch(error => {

          })
        }
      })
    },
    handleMove(type) {
      this.moveType = type
      this.$refs.patentMoveSelectFolder.open(type === 0 ? '移动' : '复制')
    },
    handleIndex() {
      this.$refs.patentBatchIndex.open(this.patentNoList)
    },
    updatePatentViewField(data) {
      this.patentViewField = data
      // this.getList()
      // this.refreshList = false
      // this.$nextTick(() => {
      //   this.refreshList = true
      // })
    },
    async getPatentViewField(refresh) {
      let params = {
        projectId: this.projectId,
        type: 'list',
        view: this.viewSelected,
        refresh: refresh
      }
      const { data } = await this.$api.getUserSettingField(params)
      this.patentViewField = data
    },
    handleSelect(data) {
      // this.queryParams.selected = data
    },
    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
      })
    },
    handleMovePatent() {
      this.$refs.patentFolderFilter.getList()
      this.queryParams.selected = []
      this.getList()
    },
    getList(key) {
      // let params = JSON.parse(JSON.stringify(this.queryParams))
      let params = {
          ...JSON.parse(JSON.stringify(this.queryParams)),
          ...this.searchOption
        }
      params.tree.map(tree => {
        let field = params.field.filter(item => item.key === tree.key)
        if (field.length === 0) {
          params.field.push(tree)
        }
      })
      params.tree = undefined
      this.$store.commit('SET_PATENT_PARAMS', params)
      if(!key){
        this.scrollTop = 0
        this.loading = true
      }
      
      this.$api.getPatentListV2(params).then(response => {
        this.total = response.data.total
        this.queryParams.endNumber = response.data.total
        let records = response.data.records
        records.forEach(item => {
          const country = getPatentCountry(item.patentNo)
          let change = false
          if (country !== 'CN') {
            change = true
          }
          this.$set(item, 'change', change)
          this.$set(item, 'change2', change)
        })
        this.$store.commit('SET_PATENT_RECORDS', records)
        this.$nextTick(() => {
          if (this.viewSelected === 'patent-table-list-view') {
            document.getElementsByClassName('el-table__body-wrapper')[0].scrollTop = this.scrollTop
          } else {
            document.getElementById('patent-list-container').scrollTop = this.scrollTop
          }
          this.loading = false
        })
      }).catch(error => {
        this.loading = false
      })
    },
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },
    async handleFieldManage() {
      await this.getPatentViewField()
      this.$refs.patentViewField.open(this.patentViewField, this.projectId, this.viewSelected)
    },
    onChangeFamily(key) {
      this.queryParams.current = 1
      this.queryParams.family = parseInt(key)
      this.getList()
    },
    async saveSelectPatent(selectId) {
      const params = JSON.parse(JSON.stringify(this.params))
      params.selected = this.queryParams.selected
      params.selectId = selectId
      if (selectId && params.selected.length === 0) {
        this.$message.error('请选择专利')
        return false
      }
      const { data } = await this.$api.saveSelectPatent(params)
      return data
    },
    handleField() {
      this.$refs.projectFieldDrawer.open(this.projectId)
    },
    handleBatch() {
      this.$refs.batchInstructionDialog.open()
    },
    exportPDF(){
      let params = JSON.parse(JSON.stringify(this.queryParams))
      params.tree.map(tree => {
        let field = params.field.filter(item => item.key === tree.key)
        if (field.length === 0) {
          params.field.push(tree)
        }
      })
      params.tree = undefined
      this.$api.pdfFirstPage(params).then(response=>{
        if(response.code == 200){
          const router = this.$router.resolve({
            path: '/taskList',
            query: {
              projectId:this.projectId,
            }
          })
          window.open(router.href,'_blank')
        }
      })
    },
    handleTemplate() {
      this.$refs.reportTemplateDrawer.open(this.projectId)
    },
    async handleAnalyse(path) {
      this.chartLoading = true
      const key = await this.saveSelectPatent(false)
      this.chartLoading = false
      const router = this.$router.resolve({
        path: '/analyse/' + path,
        query: {
          id: this.projectId,
          key: key
        }
      })
      window.open(router.href, '_blank');
    },
    async handleExport(selectId) {
      this.exportLoading = true
      const key = await this.saveSelectPatent(selectId)
      if (!key) {
        return false
      }
      this.exportLoading = false
      this.$router.push({
        path: '/workspace/folder/export/patent',
        query: {
          id: this.projectId,
          key: key
        }
      })
    },
    handleMerge() {
      this.$refs.patentApplicantMergeDrawer.open(this.projectId)
    },
    handleMerge2() {
      this.$refs.patentInventorMergeDrawer.open(this.projectId)
    },
    close() {

    },
    close2() {

    },
    submitIndex() {
      this.$store.commit('SET_SUBMIT_INDEX_SETTING')
      this.getScrollTop()
      this.getList(true)
    },
    getScrollTop(){
      if (this.viewSelected === 'patent-table-list-view') {
        this.scrollTop = document.querySelector('.el-table__body-wrapper').scrollTop
      }else{
        this.scrollTop = document.querySelector('#patent-list-container').scrollTop
      }
    },
    handleTabClick() {

    },
    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
      }
      await this.getPatentViewField()
      this.getList()
    },
    folderFilterChange(data) {
      Object.assign(this.$data, this.$options.data())
      this.projectId = this.$route.query.id
      this.queryParams.projectId = this.projectId
      this.queryParams.folder = data
      this.$store.commit('SET_PATENT_FOLDER', data)
      this.getPatentViewField()
      this.handleSearch()
    },
    queryFilterChange({ read, field, key }) {
      this.queryParams.field = field
      this.queryParams.read = read
      this.handleSearch(key)
    },
    textQueryFilterChange(data) {
      this.queryParams.name = data.name
      this.queryParams.abstractStr = data.abstractStr
      this.queryParams.publicNo = data.publicNo
      this.queryParams.applicationNo = data.applicationNo
      this.queryParams.rightContent = data.rightContent
      this.handleSearch()
    },
    treeFilterChange(data) {
      this.queryParams.tree = data
      this.handleSearch()
    },
    handleSearch(key) {
      this.queryParams.current = 1
      console.log(this.queryData)
      this.getList(key)
    }
  }
}
</script>

<style lang="scss">
.workspace-content {
  #patent-list-container {
    padding: 0;
    background: #fff;
  }
  .workspace-content-patent-page {
    padding: 5px !important;
    height: auto !important;
  }
  .workspace-content-header {
    position: relative;
    .workspace-content-header-left {
      position: absolute;
      .workspace-content-header-left-box {
        padding: 10px;
        font-size: 14px;
        margin-top: 3px;
      }
    }
    .workspace-content-header-right {
      position: absolute;
      right: 0;
      .el-dropdown {
        margin-right: 10px;
      }
    }
  }
  .workspace-content-container {
    height: 0;
    .workspace-content-container-aside {
      padding: 15px;
      .workspace-content-container-aside-box {
        display: inline
      }
    }
    .workspace-content-container-header {
      height: 45px !important;
      padding: 0 10px !important;
      .el-dropdown {
        margin-right: 10px;
      }
      .workspace-content-container-header-fast-option {
        margin-right: 10px;
        display: inline-block;
      }
      .select-patent-family {
        width: 140px;
        padding-left: 10px;
      }
      .selected-total {
        margin-top: 7px;
        font-size: 14px;
        b {
          color: #1e9fff;
        }
      }
    }
  }
  .header-tabs {
    position: absolute;
    bottom: 0;
    height: 100%;
    padding-right: 9px;
    left: 12px;
    border-right: 1px solid #e6e6e6;
    .el-tabs {
      margin-top: 19px;
    }
    .el-tabs__header {
      margin-bottom: 0 !important;
    }
  }
}
.workspace-content-header-query-main {
  padding: 0 !important;
  height: 250px;
  .workspace-content-header-query-box {
    margin-top: 10px;
    .workspace-content-header-query-content {
      line-height: 30px;
      font-size: 14px;
    }
  }
}
.query-data-label {
  cursor: pointer;
  &:hover {
    text-decoration: underline;
    color: red;
  }
}
.custom-filter-tree-node {
  font-size: 14px;
  .name {
  }
  .total {
    color: #1e9fff;
    padding-left: 10px;
  }
}
.patent-fast-edit-popover {
  padding: 0 !important;
  .btn {
    color: #000;
    line-height: 40px;
    border-radius: 5px;
    padding-left: 10px;
    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>
