<template>
  <div style="background: white; height: 100%">
    <el-container style="padding: 0 20px">
      <el-header class="workspace-content-container-header" style="display: flex; justify-content: space-between">
        <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' : ''"
                :icon="item.btn"></el-button>
            </el-tooltip>
          </el-button-group>

        </div>

        <!-- <div style="max-width:calc(100% - 620px)">
          <p><span>条件：</span>{{ searchData.searchCondition }}</p>
        </div> -->
        <div style="max-width: 850px;margin-top: 0px;display: flex;justify-content: center;align-items: center;" v-if="condition.component != 'patentNoSearch'">
          <search :field="field" :searchResult="true" :searchValue="false" :countryList="queryParams.countryList"
            @search="search"></search>
          <p><el-link style="width: 50px;color: #409EFF;" @click="searches">检索式</el-link></p>
        </div>
        <div>
          <el-button type="primary" size="small" v-if="noveltySearch" @click="reporting">生成报告</el-button>
          <el-button v-if="outside || projectId" type="primary" size="small" @click="importToProject">{{condition.isUpdateCriteria?'保存定期更新条件':'导入专利'}}{{ (!outside && condition.importToType == 3)?'到查新检索报告':'' }}</el-button>
          <el-button size="small" type="warning" @click="handleFieldManage">显示栏位管理</el-button>
        </div>
      </el-header>
      <el-main id="patent-list-container" v-loading="loading">
        <div class="height_100">
          <component ref="patentViewList" :is="viewSelected" :semanteme="semanteme" :outside="outside" :retrieveRecordId="retrieveRecordId"  :noveltySearch="noveltySearch" :column="columnList" :tableData="tableData"  @clickPatentNo="handleClick" :canSort="condition.component != 'patentNoSearch'?true:false"
            @select-change="handleSelect" :selected.sync="queryParams.selected" :queryParams="queryParams" :patentNoList.sync="patentNoList" :refresh='true'
            :view-field="patentViewField" @on-sort="handleSort" @addSelect="getChoosePatentNo" :projectId="projectId" :contrastFileList="saveRemarkList" @saveRemark="saveRemark"></component>
        </div>
      </el-main>
      <el-footer class="workspace-content-patent-page foot-total">
        <div>
          <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>
        <div class="foot-total">
          <span class="total">共{{ total }}条</span>
          <el-pagination background layout="total, sizes, prev, pager, next, jumper"
            :current-page.sync="queryParams.current" :page-size.sync="queryParams.size" :page-sizes="pageSizes"
            :page-count="getPageCount()" @current-change="handleCurrentChange" @size-change="changeSize">
          </el-pagination>
        </div>
      </el-footer>
    </el-container>


    <field ref="field" type="patent" :projectId="0" @getFieldList="getFieldList"></field>
    <!-- <projectListDialog ref="projectListDialog" :importData="searchData"></projectListDialog> -->
    <projectListDialog ref="projectListDialog" :importData="condition"></projectListDialog>

    <el-dialog custom-class="checkCondition" title="查看/编辑检索式" :visible.sync="visible" width="500px"
      :before-close="() => { visible = false }" :close-on-click-modal="false" append-to-body>
      <div>
        <el-input type="textarea" readonly :rows="4" v-model="condition.searchCondition"></el-input>
      </div>
      <span slot="footer" class="dialog-footer footer2">
        <div>
          <el-button @click="editSearchCondition">编 辑</el-button>
        </div>
        <div>
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="searchFinish">检 索</el-button>
          <el-button type="primary" v-if="condition.reportType==1||condition.reportType == 2||condition.reportType == 3" @click="saveSearchCondition">保存检索式</el-button>
        </div>
      </span>
    </el-dialog>
    <addAndEditSearchRecords ref="addAndEditSearchRecords" :projectId="condition.importToId"></addAndEditSearchRecords>
    <inventionPointDialog v-if="noveltySearch" :projectId="projectId" :retrieveRecordId="retrieveRecordId"  :contrastFileList="saveRemarkList" @updateInventionPoint="getPatentSimilarMess"></inventionPointDialog>
    <reportTemplateDialog ref="reportTemplateDialog"></reportTemplateDialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import moment from 'moment';
import PatentTableListView from "@/views/project/patentCollection/components/views/Table.vue";
import PatentAbstractListView from "@/views/project/patentCollection/components/views/Abstract";
import PatentPictureListView from "@/views/project/patentCollection/components/views/Picture";
import field from '@/views/components/dialog/fields.vue';
import projectListDialog from "./components/projectListDialog.vue";
import search from '@/utils/model/search/search.vue'
import addAndEditSearchRecords from '@/views/report/analysisAndOpinion/components/searchRecords/dialog/addAndEditSearchRecords.vue';
import reportTemplateDialog from '@/views/noveltySearch/components/dialog/reportTemplate/reportTemplateDialog.vue';
export default {
  components: {
    PatentTableListView,
    PatentAbstractListView,
    PatentPictureListView,
    field,
    projectListDialog,
    search,
    addAndEditSearchRecords,
    reportTemplateDialog
  },
  props: {
    searchData: {},
    noveltySearch:{},
    retrieveRecordId:{},
    projectId:{},
    outside:{
      type:Boolean,
      default:true
    },
    innerProjectId:{},
    semanteme:''
  },
  data() {
    return {
      columnList: [],
      pageSizes: [10, 20, 30, 40, 50],
      viewSelected: "patent-abstract-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",
        },
      ],
      patentNoList: [],
      queryParams: {
        selected: [],
        current: 1,
        size: 10,
        isAdd: [],
        isDelete: [],
        OrderBy: "AD",
        OrderByType: "DESC",
        retrieveRecordId: this.retrieveRecordId,
        asCompare: this.asCompare
      },
      patentViewField: [],
      tableData: [],
      total: 0,
      selectNumberLoading: false,
      loading: false,
      selectedTotal: 0,
      startNumber: 1,
      endNumber: 0,
      quickSelect: false,
      quickSelectArr: [],
      /**检索式 */
      // 公用数据
      field: JSON.parse(JSON.stringify(this.$constants.searchField)),
      // 打开弹窗
      visible: false,
      // 检索式及其他信息
      condition: this.searchData,
      saveRemarkList:[]
    };
  },
  watch: {
    retrieveRecordId(){
      this.queryParams.retrieveRecordId = this.retrieveRecordId
    },
    noveltySearch(val){
      if(val){
        this.queryComparePatent()
      }
    }
  },
  computed: {
    userinfo(){
      return this.$s.getObj('userinfo')
    },
  },
  created() { },
  async mounted() {
    this.columnList = await this.$commonJS.getCustomField('patent',{ projectId: 0, taskId: null })
    if(this.noveltySearch){
      this.queryComparePatent()
    }
    await this.getList();
    

  },
  methods: {
    //查询对比文件
    queryComparePatent(){
      var params = {
        projectId:this.projectId
      }
      this.$api.queryComparePatent(params).then(response=>{
        if(response.code == 200){
          this.saveRemarkList = response.data.data
        }
      })
    },
    reporting(){
      this.$refs.reportTemplateDialog.open(this.projectId)
    },
    saveRemark(data){
      if(this.noveltySearch){
        this.queryComparePatent()
      }
    },
    //保存检索式
    saveSearchCondition(){
      var form = {
        searchCondition:this.condition.searchCondition,
        searchBase:'小世系统',
        allNum:this.total,
        searchPerson:this.userinfo.name,
        searchTime:moment().format("YYYY-MM-DD")
      }
      this.$refs.addAndEditSearchRecords.open(form)
    },
    handleClick(row, location) {
      var params = {
        ...this.searchData,
        ...this.queryParams,
      }
      var search = {
        searchOption: params,
        location: location,
      }
      if(!this.outside){
        search.searchOption = {
          searchQuery: this.condition.searchCondition || '',
          moreConditions:true
        }
        if(this.queryParams.OrderBy && this.queryParams.OrderByType){
          var orderDTOList = [
            {
              orderBy:this.queryParams.OrderBy,
              orderType:this.queryParams.OrderByType == 'DESC'?1:0
            }
          ]
          search.searchOption.orderDTOList = orderDTOList
        }
      }
      this.$s.setSession('search', search)
      this.$s.setSession('import',this.searchData)
      this.$router.push(
        {
          path: '/patentDetails/' + row.patentNo,
          query: {
            outside:this.outside,
            noveltySearch:this.noveltySearch,
            projectId:this.projectId,
            innerProjectId:this.innerProjectId || 0,
            retrieveRecordId:this.queryParams.retrieveRecordId
          }
        }
      )
    },
    //子组件返回检索式 
    async search(val) {
      if (val.searchStr == '') {
        this.$message.error('检索信息不能为空')
        return false
      }
      if (val.isRepeat) {
        this.condition.searchCondition = `${this.condition.searchCondition} AND ${val.searchStr}`
      } else {
        this.condition.searchCondition = val.searchStr
      }
      if(val.data){
        var params = this.$s.getSession('conditionImport')
        if(params && params.data && params.data.component != 'AdvancedSearch' && params.data.component != 'patentNoSearch'){
          if(val.isRepeat){
            if(params.data.data && params.data.data.length>0){
              params.data.data.push(val.data[0])
            }else{
              params.data.data=[val.data[0]]
            }
            var data = []
            params.data.data.forEach(item=>{
              if(item.dataType == 3){
                if(item.value && item.value.length>0){
                  data.push(item)
                }
              }else{
                if(item.value){
                  data.push(item)
                }
              }
            })
            params.data.data = data
          }else{
            params.data.data = val.data
          }
          params.data.component = 'customSearch'
          this.$s.setSession('conditionImport',params)
        }else if(params.data.component == 'AdvancedSearch' || params.data.component == 'patentNoSearch'){
          params.data.data = this.condition.searchCondition
          params.data.component = 'AdvancedSearch'
          this.$s.setSession('conditionImport',params)
        }
      }
      await this.searchBth()
    },
    //编辑检索式，跳转到检索界面
    editSearchCondition(){
      var params = this.$s.getSession('conditionImport')
      if(!params || !params.data){
        var data = {
          DBType:this.condition.DBType,
          component:'AdvancedSearch',
          data:this.condition.searchCondition
        }
        this.$s.setSession('conditionImport',{
          data:data,
        })
      }
      this.$router.push({
        path: '/conditionImport',
        query:{
          isEdit:true,
          importData:JSON.stringify(this.searchData),
          noveltySearch:this.noveltySearch,
          projectId:this.projectId,
        }
      })
    },
    searchBth() {
      if(this.outside){
        this.queryParams.retrieveRecordId = null
      }
      this.queryParams.current = 1
      this.getList()
      if(this.outside){
        this.reLoadQuery()
      }
      
    },
    // 打开检索式弹窗
    searches() {
      this.visible = true
    },
    // 编辑、查看检索式
    async searchFinish() {
      await this.searchBth()
      this.visible = false
    },
    //导入到专题库
    importToProject() {
      if(this.outside){
        var form = {
          // ...this.searchData,
          ...this.condition,
          orderBy: this.queryParams.OrderBy,
          orderByType: this.queryParams.OrderByType,
          // startNumber: this.selectedTotal > 0 ? this.startNumber : 1,
          // endNumber: this.selectedTotal > 0 ? this.endNumber : this.total,
          patentNos: this.queryParams.isAdd,
          // isDeletePatentNos: this.queryParams.isDelete,
        }
        this.$refs.projectListDialog.open(form);
        return
      }
      if(!this.projectId){
        return 
      }
      var params = {
        stringRequest:{
          projectId: this.innerProjectId,
          searchQuery: this.condition.searchCondition || '',
          orderDTOList:this.sort,
        },
        startNumber:1, //开始位置
        endNumber:(this.queryParams.isAdd && this.queryParams.isAdd.length>0)?0:this.total,//结束位置
        fromProjectId:this.innerProjectId, //来源专题库项目id
        toProjectId:this.projectId, //目标报告项目id
        isAdd:this.queryParams.isAdd, //去除专利号
      }
      if(this.queryParams.OrderBy && this.queryParams.OrderByType){
        var orderDTOList = [
          {
            orderBy:this.queryParams.OrderBy,
            orderType:this.queryParams.OrderByType == 'DESC'?1:0
          }
        ]
        params.stringRequest.orderDTOList = orderDTOList
      }
      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:'导入失败'
            }
          )
      })
      
    },
    //切换页数
    async handleCurrentChange(val) {
      this.queryParams.current = val;
      this.patentNoList = []
      await this.getList();
      this.$nextTick(() => {
        if (this.quickSelect) {
          this.commonSwitch()
        } else {
          if (this.queryParams.isAdd.length > 0) {
            this.getHaveChoose([])
          }
        }
      })
    },
    //切换页大小
    async changeSize(val){
      this.queryParams.size = val
      this.queryParams.current = 1
      this.patentNoList = []
      await this.getList();
      this.$nextTick(() => {
        if (this.quickSelect) {
          this.commonSwitch()
        } else {
          if (this.queryParams.isAdd.length > 0) {
            this.getHaveChoose([])
          }
        }
      })
    },
    //获取最大页数
    getPageCount() {
      if(this.outside){
        var a = Math.ceil(Number(this.total) / Number(this.queryParams.size))
        return a > 200 ? 200 : a
      }else{
        return Math.ceil(Number(this.total) / Number(this.queryParams.size))
      }
      
    },
    //开始条数校验
    change1(val) {
      if (!isNaN(val)) {
        if (!val || val <= 0) {
          this.queryParams.startNumber = 1
        } else {
          if (this.queryParams.startNumber > this.total) {
            this.queryParams.startNumber = this.total
          }
        }
      } else {
        this.queryParams.startNumber = 1
      }
    },
    //结束条数校验
    change2(val) {
      if (!isNaN(val)) {
        if (!val || val <= 0) {
          this.queryParams.endNumber = this.total
        } else {
          if (this.queryParams.endNumber > this.total) {
            this.queryParams.endNumber = this.total
          }
        }
      } else {
        this.queryParams.endNumber = this.total
      }
    },
    //查询内部数据库数据
    async getInnerProjectPatent(){
      let params = {
        current: this.queryParams.current, //页码（最多 200 页）
        size: this.queryParams.size, //每页返回条数（最多 50 条）
        projectId: this.innerProjectId,
        searchQuery: this.condition.searchCondition || '',//检索条件
        semanteme:this.semanteme
      }
      if(this.queryParams.OrderBy && this.queryParams.OrderByType){
        var orderDTOList = [
          {
            orderBy:this.queryParams.OrderBy,
            orderType:this.queryParams.OrderByType == 'DESC'?1:0
          }
        ]
        params.orderDTOList = orderDTOList
      }
      this.loading = true;
      this.$store.commit("SET_PATENT_RECORDS", []);
      await this.$api.QueryPatent(params).then((response) => {
        if (response.code == 200) {
          this.total = response.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)
          let records = response.data.data
          if(params.semanteme){
            records.forEach(item=>{
              if(!item.score){
                item.score =  'error'
              }else{
                var score = (item.score * 100 + '').substring(0, 5)
                item.score =  Number(score)
              }
              
            })
          }
          this.tableData = records
          this.$store.commit("SET_PATENT_RECORDS", records);
          this.loading = false;
        }
      }).catch((error) => {
          this.loading = false;
        });
    },
    //查询专利
    async getList() {
      if(!this.outside){
        await this.getInnerProjectPatent()
        return
      }
      let queryParams = JSON.parse(JSON.stringify(this.queryParams));
      var params = {
        // CurrentQuery: this.searchData.searchCondition, //检索式
        // DBType: this.searchData.DBType, //”CN”或”WD”,表示检索中文库或世界库
        CurrentQuery: this.condition.searchCondition, //检索式
        DBType: this.condition.DBType, //”CN”或”WD”,表示检索中文库或世界库
        PageNum: this.queryParams.current, //页码（最多 200 页）
        RowCount: this.queryParams.size, //每页返回条数（最多 50 条）
        OrderBy: this.queryParams.OrderBy, //排序字段：“AD”，“PD”，“GD”, “ID”（检索引擎自生成字段，排序顺序固定）
        OrderByType: this.queryParams.OrderByType, //排序方式：“ASC”，“DESC” 即正序倒序
        retrieveRecordId: this.queryParams.retrieveRecordId,

        //专利号检索
        numberQuery:this.condition.NO,
        redisKey:this.condition.redisKey,
      };
      if(!this.queryParams.retrieveRecordId){
        params.projectId = this.projectId
        var conditionImport = this.$s.getSession('conditionImport')
        params.searchSetting=conditionImport?JSON.stringify(conditionImport):''
      }
      // console.log(this.$s.getSession('retrieveRecordId'),)
      queryParams.params = params;
      this.$store.commit("SET_PATENT_PARAMS", queryParams);
      this.$store.commit("SET_PATENT_RECORDS", []);
      this.loading = true;
      this.$commonJS.scrollToTop()
      await this.$api.patentSelect(params).then((response) => {
        if (response.code == 200) {
          this.total = response.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)
          let records = response.data.data
          this.tableData = records
          params.retrieveRecordId = response.data.retrieveRecordId
          if(!this.queryParams.retrieveRecordId && response.data.retrieveRecordId && !response.data.redisKey){
            this.queryParams.retrieveRecordId = response.data.retrieveRecordId
            this.reLoadQuery()
          }
          
          this.$store.commit("SET_PATENT_PARAMS", queryParams);
          this.$store.commit("SET_PATENT_RECORDS", records);
          this.getImageAndStatus()
          this.getPatentSimilarMess()
          this.loading = false;
          if(response.data.redisKey && !this.condition.redisKey){
            this.condition.redisKey = response.data.redisKey
            this.condition.NO=''
            this.reLoadQuery()
          }
        }
      })
        .catch((error) => {
          this.loading = false;
        });

    },
    //刷新网页参数
    reLoadQuery(){
      this.$router.replace({
        path: '/searchResult',
        query: {
          data: JSON.stringify(this.condition),
          noveltySearch:this.noveltySearch,
          projectId:this.projectId,
          retrieveRecordId:this.queryParams.retrieveRecordId,
          outside:this.outside,
          innerProjectId:this.innerProjectId,
          semanteme:this.semanteme
        }
      })
    },
    //获取摘要附图和法律状态
    getImageAndStatus(){
      this.tableData.forEach(item=>{
        var params = {
          appNo: item.rowApplicationNo,
        }
        // this.$api.getPictureGuid(params).then(response => {
        //   if (response.code == 200) {
        //     this.$set(item, 'pictureGuid', response.data)
        //   }
        // })
        this.$api.getLegalStatus(params).then(response => {
          if (response.code == 200) {
            this.$set(item, 'legalStatus', response.data)
          }
        })
      })
      
    },
    //获取专利相似度
    getPatentSimilarMess(){
      if(this.tableData.length == 0 || !this.noveltySearch){
        return
      }
      this.tableData.forEach(item=>{
        let params = {
          projectId:this.projectId,
          patentScoreDTOList:[]
        }
        var obj = {
          patentNo:item.patentNo,
          appNo:item.appNo,
          rowApplicationNo:item.rowApplicationNo,
          publicNo:item.publicNo,
          grantNo:item.grantNo
        }
        params.patentScoreDTOList.push(obj)
        this.$api.getPatentSimilarMess(params).then(response=>{
          if(response.code == 200){
            var data = response.data.patentScoreDTOList
            if(!data){
              this.$set(item, 'score', 'error')
              return
            }
            for(var i = 0;i<this.tableData.length;i++){
              var item1 = this.tableData[i]
              var index = data.findIndex(j=>{
                return j.patentNo == item1.patentNo
              })
              if(index!=-1){
                var score = (data[index].score * 100 + '').substring(0, 5)
                this.$set(item1, 'score', Number(score))
                data.splice(index,1)
              }else{
                this.$set(item1, 'score', 'error')
              }
            }
          }
        }).catch(error=>{
          this.$set(item, 'score', 'error')
        })
      })
      return
      var params = {
        projectId:this.projectId,
        patentScoreDTOList:[]
      }
      this.tableData.forEach(item=>{
        var obj = {
          patentNo:item.patentNo,
          appNo:item.appNo,
          rowApplicationNo:item.rowApplicationNo,
          publicNo:item.publicNo,
          grantNo:item.grantNo
        }
        params.patentScoreDTOList.push(obj)
      })
      this.$api.getPatentSimilarMess(params).then(response=>{
        if(response.code == 200){
          var data = response.data.patentScoreDTOList
          for(var i = 0;i<this.tableData.length;i++){
            var item = this.tableData[i]
            var index = data.findIndex(j=>{
              return j.patentNo == item.patentNo
            })
            if(index!=-1){
              this.$set(item, 'score', data[index].score.toFixed(4))
              data.splice(index,1)
            }
          }
        }
      })
    },
    handleSelect(data) {
      // this.queryParams.selected = data
    },
    async handleChangeView(item) {
      // console.log(item)
      if (this.viewSelected == item.value) {
        return false
      }
      if (this.viewSelected != "patent-picture-list-view" && item.value != "patent-picture-list-view") {
        this.queryParams.size = 10;
        this.viewSelected = item.value;
      } else if (this.viewSelected == "patent-picture-list-view" || item.value == "patent-picture-list-view") {
        if (item.value === "patent-picture-list-view") {
          this.$set(this.queryParams, "size", 20);
        } else {
          this.queryParams.size = 10;
        }
        this.viewSelected = item.value;
        this.getList();
      }
    },
    async handleFieldManage() {
      this.$refs.field.open(this.columnList)
    },
    //获取自定义栏位
    getFieldList(data) {
      this.columnList = []
        this.$nextTick(()=>{
            this.columnList = data
        })
    },
    //快速选择
    handleSelectNumber(type) {
      switch (type) {
        case 0: //本页选择
          this.patentNoList = [...new Set(this.patentNoList.concat(this.tableData.map((item) => item.patentNo))),];
          this.queryParams.isAdd = [...new Set(this.queryParams.isAdd.concat(this.tableData.map((item) => item.patentNo))),];
          break;
        case 1: //全部选择
          this.startNumber = 1;
          this.endNumber = this.total;
          this.$set(this.queryParams, 'startNumber', 1)
          this.$set(this.queryParams, 'endNumber', this.total)
        case 2: //范围选择
          this.queryParams.isDelete = [];
          this.queryParams.isAdd = [];
          this.patentNoList = [];
          this.quickSelect = true;
          if (type == 2) {
            if (!Number(this.queryParams.startNumber) || !Number(this.queryParams.endNumber)) {
              this.$set(this.queryParams, 'startNumber', this.endNumber > 0 ? this.startNumber : 1)
              this.$set(this.queryParams, 'endNumber', this.endNumber > 0 ? this.endNumber : this.total)
              break;
            }
            this.startNumber = this.queryParams.startNumber;
            this.endNumber = this.queryParams.endNumber;
          }
          this.commonSwitch();
          break;
      }
      this.getSelectedTotal()
    },
    //每页全部选择或范围选择的专利
    commonSwitch() {
      var arr = []
      if (this.queryParams.size * this.queryParams.current >= this.startNumber) {
        if (this.queryParams.size * this.queryParams.current >= this.endNumber) {
          if (this.queryParams.size * (this.queryParams.current - 1) + 1 <= this.startNumber) {
            var a = this.startNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            var b = this.endNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            for (var y = a; y <= b; y++) {
              arr.push(this.tableData[y].applicationNo)
            }
          } else {
            var a = this.queryParams.size * (this.queryParams.current - 1) + 1 - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            var b = this.endNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            for (var y = a; y <= b; y++) {
              arr.push(this.tableData[y].applicationNo)
            }
          }
        } else {
          if (this.queryParams.size * (this.queryParams.current - 1) + 1 <= this.startNumber) {
            var a = this.startNumber - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            var b = this.queryParams.size * this.queryParams.current - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            for (var y = a; y <= b; y++) {
              arr.push(this.tableData[y].applicationNo)
            }
          } else {
            var a = this.queryParams.size * (this.queryParams.current - 1) + 1 - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            var b = this.queryParams.size * this.queryParams.current - (this.queryParams.size * (this.queryParams.current - 1) + 1);
            for (var y = a; y <= b; y++) {
              arr.push(this.tableData[y].applicationNo)
            }
          }
        }
      }
      // this.patentNoList = JSON.parse(JSON.stringify(arr))
      this.quickSelectArr = JSON.parse(JSON.stringify(arr))
      this.getHaveChoose(arr)
    },
    //获取已选择的专利
    getHaveChoose(arr) {
      var arr1 = [...new Set(arr.concat(this.queryParams.isAdd))]
      this.patentNoList = arr1.filter((x) => this.queryParams.isDelete.indexOf(x) == -1)
    },
    //获取已选择的总条数
    getSelectedTotal() {
      this.selectedTotal = Number(this.endNumber) - Number(this.startNumber) + 1 + Number(this.queryParams.isAdd.length) - Number(this.queryParams.isDelete.length)
    },
    //获取手动选择的专利
    getChoosePatentNo(patentNo) {
      if (this.quickSelect) {
        var index = this.queryParams.isDelete.findIndex(item => {
          return item == patentNo
        })
        if (index == -1) {
          var index2 = this.quickSelectArr.findIndex(item => {
            return item == patentNo
          })
          if (index2 == -1) {
            this.setIsAdd(patentNo)
          } else {
            this.queryParams.isDelete.push(patentNo)
          }
        } else {
          this.queryParams.isDelete.splice(index, 1)
        }
      } else {
        this.setIsAdd(patentNo)
      }
      this.getSelectedTotal()
    },
    //是否加入isAdd里面
    setIsAdd(patentNo) {
      var index = this.queryParams.isAdd.findIndex(item => {
        return item == patentNo
      })
      if (index != -1) {
        this.queryParams.isAdd.splice(index, 1)
      } else {
        this.queryParams.isAdd.push(patentNo)
      }
    },
    //取消选择
    handleCancelSelectNumber() {
      this.patentNoList = [];
      this.queryParams.isAdd = []
      this.queryParams.isDelete = []
      this.startNumber = 1
      this.queryParams.startNumber = 1
      this.queryParams.endNumber = this.total
      this.endNumber = 0
      this.quickSelect = false
      this.selectedTotal = 0
      // this.getList()
    },
    //排序
    handleSort(data) {
      const o = {
        publicAccreditDate: "GD",
        publicDate: "PD",
        applicationDate: "AD",
      };
      var orderType = {
        ascending: "ASC",
        descending: "DESC"
      }
      this.queryParams.OrderBy = o[data.prop] || data.prop;
      this.queryParams.OrderByType = orderType[data.order];
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.footer2{
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.total {
  margin-right: 10px;
  font-weight: 400;
  color: #606266;
  display: inline-block;
  font-size: 13px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  vertical-align: top;
  box-sizing: border-box;
}

.foot-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.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>
