<template>
  <div class="search-page wrap">
    <!-- <Header></Header> -->

    <!-- 头部开始 -->
    <div class="header pc">
      <div class="inner">
        <div class="fl header_l">
          <a class="fl" target="_blank"><img src="../../assets/img/logo.png" alt=""></a>
          <div class="header_nav fl">
            <ul>
              <li @click="openSearchPage()">全文检索</li>
              <li @click="openCollectionPage()">我的收藏</li>
              <li class="header_nav_a">我的待办</li>
            </ul>
          </div>
          <div class="header_user fr">
            <ul>
              <el-dropdown>
                <li class="header_nav_a el-dropdown-link">{{nickname}} <i class="el-icon-arrow-down el-icon--right"></i>
                </li>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </ul>
          </div>
        </div>
        <div class="header_r fl">

        </div>

      </div>

    </div>

    <!-- 头部结束 -->
    <div class="pc pcwrap">
      <div class="inner">
        <div class="contain">
          <div class="cont_wrap">
            <div class="search_cont_wrap search_cont_wrap_sc fl">
              <div class="right_cont">

                <!-- 顶部分类开始  -->
                <div class="cont_wrap_nav" style="width: 100%;">
                  <ul>
                    <li v-if="isFfBtn" class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex === 0 }">
                      <input type="radio" id="label1" value="1" @click="setActive(0)" class="hidden-radio" />
                      <label for="label1" class="custom-radio">未分发</label>&nbsp;
                    </li>
                    <li v-if="isFfBtn" class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex === 1 }">
                      <input type="radio" id="label2" value="2" @click="setActive(1)" class="hidden-radio" />
                      <label for="label2" class="custom-radio">已分发</label>&nbsp;
                    </li>
                    <li v-if="isFfBtn" class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex === 2 }">
                      <input type="radio" id="label3" value="3" @click="setActive(2)" class="hidden-radio" />
                      <label for="label3" class="custom-radio">已处理</label>&nbsp;
                    </li>
                    <li v-if="isBlBtn" class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex === 3 }">
                      <input type="radio" id="label4" value="4" @click="setActive(3)" class="hidden-radio" />
                      <label for="label4" class="custom-radio">未处理</label>&nbsp;
                    </li>
                    <li v-if="isBlBtn" class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex === 4 }">
                      <input type="radio" id="label5" value="5" @click="setActive(4)" class="hidden-radio" />
                      <label for="label5" class="custom-radio">已处理</label>&nbsp;
                    </li>

                  </ul>
                </div>
                <!-- 顶部分类结束 -->
                <div class="data_wrap">
                  <div class="left_nav">
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 0 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(0)" label=""
                      value=" ">全部</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 1 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(1)" label="军事"
                      value="军事">军事</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 2 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(2)" label="政治"
                      value="政治">政治</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 3 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(3)" label="经济"
                      value="经济">经济</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 4 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(4)" label="外交"
                      value="外交">外交</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 5 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(5)" label="安全"
                      value="安全">安全</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 6 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(6)" label="科技"
                      value="科技">科技</el-radio>
                    <el-radio class="list_wrap_li_jyfl" :class="{ list_wrap_li_jyfl_h: activeIndex1 === 7 }"
                      v-model="queryParams.navigation.doc_lable" @change.native="setActive1(7)" label="宗教"
                      value="宗教">宗教</el-radio>
                  </div>
                  <h1 class="total_wrap">
                    <div class="search_types search_types_cs fl">
                      <button v-if="isBlBtn" @click="handleExportList()">批量导出</button>
                      <!-- <button @click="quantityMyItems()">批量分配</button> -->
                    </div>
                    <h2 v-if="isFfBtn" class="fl data_list_types_sc">共<span>{{totalResultsCount}}</span>篇文献</h2>
                    <h2 v-if="isBlBtn" class="fl data_list_types_sc">共<span>{{totalResultsCount}}</span>篇待办文献</h2>
                    <div class="block fr date_css date_css_sc">
                      按时间筛选：
                      <el-date-picker v-model="value1" type="daterange" value-format="yyyy-MM-dd" align="right"
                        unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        :picker-options="pickerOptions" @change="handleDateChange">
                      </el-date-picker>
                    </div>
                  </h1>
                  <!-- 数据列表 -->
                  <div class="data_cont_wrap">

                    <!-- 列表页开始 -->
                    <div :class="table==true ? 'leftactive  data_list':'data_list'">
                      <ul style="padding-left:0px">
                        <div v-loading="loading" style="position:absolute;top:85px;left:29%"></div>
                        <el-button type="text" v-for="(result, index) in results" :key="index">
                          <li class="data_list_sc">
                            <!-- <a @click="openDetailPage(result)" target="_blank" v-html="result.doc_title"></a> -->
                            <div class="fl" style="width: auto;line-height: 20px;">
                              <label ref="{{ index }}">{{index + 1}}.</label>
                              <input v-if="isBlBtn" class="data_list_input_sc" type="checkbox" :id="index"
                                :value="index" :uid="result.uid" :docid="result.docid" v-model="selectedItems" />
                            </div>

                            <a class="fl" @click="openDetailCont(result)" v-html="result.doc_title"></a>
                            <!-- <div>
                                    关键词：<span v-html="result.doc_content"></span>
                                </div> -->
                            <div class="abstract_wrap" @click="openDetailCont(result)">
                              <b>摘要：</b><span v-html="decodeHtmlEntity(result.doc_content)"></span>
                            </div>

                            <div>
                              <h2 class="fl" @click="openDetailCont(result)">
                                <b>时间：</b>{{result.file_updatetime}}
                              </h2>
                              <h2 class="fl" @click="openDetailCont(result)">
                                <b>来源：</b>{{result.sourcename}}
                              </h2>
                              <h2 class="fl" @click="openDetailCont(result)">
                                <b>文档类型：</b>{{result.file_type}}
                              </h2>
                              <h2 class="fl" @click="openDetailCont(result)">
                                <b>语种：</b>{{result.language}}
                              </h2>
                              <!-- <h2 class="fl" @click="openDetailCont(result)" >
                                    <b>收藏时间：</b>{{result.crtime}}
                                  </h2> -->
                              <!--<el-button class="fl el-button-tk" size="mini" type="text" icon="el-icon-edit" @click="openForm(result.docid,result.uid,result.doc_lable,result.doc_isindex,result.sourcename)" v-hasPermi="['manager:dig-ftp-source:update']">修改标签</el-button> -->
                              <h2 v-if="isFfBtn" :class="isFfA ? 'collectActive' : 'collectActiveN'" class="fl">
                                <el-button style="margin: 0;padding: 0; font-size: 16px;" class="fl el-button-tk"
                                  size="mini" type="text" icon="el-icon-edit" @click="openOrgForm(result)"
                                  v-hasPermi="['manager:dig-ftp-source:update']">分发</el-button>
                              </h2>
                              <h2 :class="isFfA ? 'collectActive' : 'collectActiveN'" class="fl"><el-button
                                  style="margin: 0;padding: 0; font-size: 16px;" class="fl el-button-tk" size="mini"
                                  type="text" icon="el-icon-edit" @click="processed(result)"
                                  v-hasPermi="['manager:dig-ftp-source:update']">处理</el-button></h2>
                            </div>
                          </li>
                        </el-button>
                      </ul>
                      <!-- 分页 -->
                      <!-- 分页 -->
                      <el-pagination v-if="totalResultsCount != 0" @current-change="handleCurrentChange"
                        :current-page="currentPage" :page-size="10" layout="total,prev, pager,next, jumper"
                        :total="totalResultsCount" prev-text="上一页" next-text="下一页">
                      </el-pagination>
                      <div class="noResult" v-if="totalResultsCount == 0" v-show="!loading"
                        style="padding-bottom:20px;font-size: 16px;line-height: 30px;">
                        <strong>很抱歉！未能搜到您想要的内容</strong>
                        <br />
                        <strong>建议您</strong>
                        <br />
                        <strong>1.看看输入的文字是否有错误</strong>
                        <br />
                        <strong>2.去掉可能不必要的词或条件</strong>
                      </div>
                    </div>
                    <!-- 列表页结束 -->

                    <!-- 文章详情 -->
                    <div :class="table==true ? 'active detail_cont_wrap':'detail_cont_wrap'">
                      <el-drawer ref="drawer" title="文章详情" :visible.sync="table" direction="rtl" size="100%"
                        style="position: absolute" z-index="-1" :append-to-body="false" :show-close="true"
                        :modal="false">
                        <div class="detailcont">
                          <p><strong class="xqxx dz"
                              @click="visitOne(detailData.uid,detailData.docid,detailData.sourcename)">点赞</strong>
                            <!--<strong class="xqxx jrsc" @click="unCollectOne(detailData.uid,detailData.docid)">取消收藏</strong>-->
                            <strong class="xqxx znfx" @click="openAnalysisPage(detailData)">智能分析</strong><strong
                              v-if="isTranslateZw" class="xqxx ckyw" @click="incrementTranslate()">{{isTranslate ?
                              '查看原文' : '查看译文' }}</strong>
                            <!-- <strong class="xqxx zxbj" >在线编辑</strong> -->
                            <strong class="xqxx ywlj fr" @click="open(detailData.file_path)">查看原文路径</strong>
                          </p>
                          <h1 :class=" isTranslate ?'collectActiveN':'collectActive' " v-html="detailData.doc_title">
                          </h1>
                          <h1 :class=" isTranslate ?'collectActive':'collectActiveN' "
                            v-html="detailData.doc_title_translate"></h1>
                          <div style="width: 100%;height: auto;overflow: hidden;"><strong class="fl"
                              style="font-size: 16px;">关键词：</strong>
                            <div style="font-size: 16px;" class="fl" v-html="detailData.doc_keywords"></div>
                          </div>
                          <p><strong>时间：</strong>{{ detailData.file_updatetime }}<strong
                              style="margin-left:40px;">文档类型：</strong>{{ detailData.file_type }}<strong
                              style="margin-left:40px;">语种：</strong>{{ detailData.language }}<strong
                              style="margin-left:40px;">标签：</strong>{{ detailData.doc_lable }}
                            <!-- <strong style="margin-left:40px;">访问量：</strong>{{detailData.doc_visit}} -->
                            <!-- <strong v-show="downloadShow" style="margin-left:40px;color:#016bb5;cursor: pointer; " @click="getDownload">下载文件</strong> -->
                          </p>

                          <p style="overflow:hidden;">
                            <!-- <strong class="fl" style="display:block">正文：</strong> -->
                            <span class="fl" :class=" isTranslate ?'collectActiveN':'collectActive' " style="width:100%"
                              v-html="detailData.doc_content"></span>
                            <span class="fl" :class=" isTranslate ?'collectActive':'collectActiveN' " style="width:100%"
                              v-html="detailData.doc_content_translate"></span>
                          </p>

                        </div>

                        <div class="closeDrawer">
                          <el-button @click="cancelForm">关闭</el-button>
                        </div>
                      </el-drawer>

                    </div>

                    <!-- 文章详情 -->
                  </div>



                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>

    <Footer></Footer>
    <!-- <DigFtpSourceForm ref="formRef" @success="getList" /> -->


    <orgForm ref="formRef" @success="getList" />

  </div>
</template>

<script>
// import Header from './header.vue';
// import Wordcloud from 'vuewordcloud';
import * as echarts from 'echarts';
import Footer from './footer.vue';
import _ from "lodash";
import * as searchPageApi from '@/api/manager/digsearch';
// import DigFtpSourceForm from './DigFtpSourceForm.vue';
import orgForm from './orgForm.vue';
import $ from 'jquery';
import { getPath } from "@/utils/ruoyi";
export default {
  name: "SearchPage",
  components: {
    // Wordcloud,
    Footer,
    // DigFtpSourceForm
    orgForm
    // Header
  },

  data() {
    return {
      // 默认时间
      isTranslate:false,
      isTranslateZw:false,
      isFfBtn:false,
      isYffBtn: false,
      isBlBtn:false,
      isFfA:true,
      // 抽屉
      table: false,
      // nickname
      nickname: '',
      componentKey:0,
      activeIndex:0,
      activeIndex1: 0,
      xzgfListShow:true,
      searchQuery: "",
      results: [],
      selectedItems:[],
      selectedBmItems:[],
      queryParams: {
        keyword: "",
        navigation: {
          sourcename: [],
          file_type: [],
          language: [],
          doc_lable: [],
          file_year:[],
          batch_no: [] 
        },
        sort:{
          // RELEVANCE:'desc'
        },
        sourcename: [],
        language: "",
        selectedYear: "",
        pageNo: 1,
        pageSize: 10,
        advField: [], // 搜索字段
        fieldType: [], // 字段类型
        connect: [], // 逻辑运算符
        advValue: [], // 搜索值
        type: 1,
      },
      availableYears: Array.from({ length: 20 }, (_, i) => new Date().getFullYear() - i),
      loading: false,
      totalResultsCount: 0,      // 总结果数，用于计算分页
      currentPage: 1,            // 当前页码
      itemsPerPage: 10,          // 每页显示条目数
      detailData:'',//详情页内容
      downloadShow: true,
      
       // 区间日期
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      value1: [this.getTodayStartTime(), this.getTodayEndTime()],
      // value2: [new Date(), new Date()],
    };
  },
  

  computed: {
    /*paginatedResults() {
      const start = (this.currentPage - 1) * this.itemsPerPage;
      return this.results.slice(start, start + this.itemsPerPage);
    },*/
    totalPages() {
      return Math.ceil(this.totalResultsCount / this.itemsPerPage);
    },
    visiblePages() {
      const range = 6;
      const start = Math.max(1, this.currentPage - Math.floor(range / 2));
      const end = Math.min(this.totalPages, start + range - 1);
      return Array.from({ length: end - start + 1 }, (_, i) => start + i);
    },
    hasFtp2Perm() {
      return this.$store.getters.permissions.includes("adv/search:ftp2");
    },
    hasDaibanAdmin() {
      return this.$store.getters.roles.includes("jd_daiban_admin");
      // return Array.isArray(this.$store.getters.roles) && this.$store.getters.roles.includes("jd_daiban_admin");
    },

  },
  methods: {
         /** 添加/修改操作 */
    openOrgForm(result) {
      // console.log(data);
      this.$refs["formRef"].open(result);
    },
    decodeHtmlEntity(encodedStr) {
      const doc = new DOMParser().parseFromString(encodedStr, "text/html");
      return doc.body.textContent || doc.body.innerText;
    },
     /** 添加/修改操作 */
    // openForm(docid,uid,doc_lable,doc_isindex,sourcename) {
    //   this.$refs["formRef"].open(docid,uid,doc_lable,doc_isindex,sourcename);
    // },
      /** 查询列表 */
    async getList() {
      this.performSearch();

    },
    // 点击切换
    hover_li(val){
      this.msgLXNameIndex = val;
    },
    // 文档标签
    setActive(index){
      this.activeIndex = index;
      this.queryParams.pageNo = 1;
      this.currentPage = 1
      if (index === 0) {
        this.queryParams.navigation.batch_no = [];
        this.queryParams.navigation.batch_no = [1];
        this.queryParams.navigation.doc_lable = [];
        this.setActive1(0);
        this.isFfA = true;
      } else if (index === 1){
        this.queryParams.navigation.batch_no = [];
        this.queryParams.navigation.batch_no = [2];
        this.queryParams.navigation.doc_lable = [];
        this.setActive1(0);
        this.isFfA = true;
      } else if (index === 2) {
        this.queryParams.navigation.batch_no = [];
        this.queryParams.navigation.batch_no = [3];
        this.queryParams.navigation.doc_lable = [];
        this.setActive1(0);
        this.isFfA = false;
      }else if (index === 3) {
        this.queryParams.navigation.batch_no = [];
        this.queryParams.navigation.batch_no = [2];
        this.queryParams.navigation.doc_lable = [];
        this.setActive1(0);
        this.isFfA = true;
      } else if (index === 4) {
        this.queryParams.navigation.batch_no = [];
        this.queryParams.navigation.batch_no = [3];
        this.queryParams.navigation.doc_lable = [];
        this.setActive1(0);
        this.isFfA = false;
      }

      // console.log(this.queryParams.navigation.doc_lable)
      // this.performSearch();
    },

    setActive1(index){
      console.log(this.queryParams.navigation.batch_no);
      if (this.queryParams.navigation.doc_lable.length) {
        this.queryParams.navigation.doc_lable = [this.queryParams.navigation.doc_lable];
      } else {
        this.queryParams.navigation.doc_lable = [];
      }
      console.log(this.queryParams.navigation.doc_lable);
      this.activeIndex1 = index;
      this.queryParams.pageNo = 1;
      this.currentPage = 1;
      this.performSearch();
    },
    performSearch_s(){
      this.queryParams.pageNo = 1;
      this.currentPage = 1;
      this.performSearch();
    },
    // 获取列表
    async performSearch() {
      this.queryParams.type = 1;
      this.loading = true;

      // 拼接查询参数
      const searchParams = {
        userid: 115,
        starttime: this.value1[0], // 开始时间
        endtime: this.value1[1], // 结束时间
        pageNo: this.queryParams.pageNo,
        pageSize: this.queryParams.pageSize,
        navigation: {
          batch_no: this.queryParams.navigation.batch_no,
          doc_lable: this.queryParams.navigation.doc_lable
        },
        
      };
      // 发送请求到后端
      try {
        // 检查是否有“adv/search:ftp2”权限
        console.log(this.hasDaibanAdmin);
        const res = this.hasDaibanAdmin
          ? await this.performFTPSearch()
          // ? await this.performFTPSearchAdmin()
          : await this.getdaibanList(searchParams);
        // this.isBlBtn = true;
        // this.results = res.data.list; // 假设返回的数据包含 results
        // this.totalResultsCount = res.data.total;
        // this.loading = false;
      } catch (error) {
        console.error("搜索失败:", error);
        this.loading = false;
      }
    },
    //获取待办列表
    async getdaibanList(searchParams) {
      // 发送请求到后端
      try {
        // 检查是否有“adv/search:ftp2”权限
        const res = await searchPageApi.daibanList(searchParams);
        this.isBlBtn = true;
        this.results = res.data.list; // 假设返回的数据包含 results
        this.totalResultsCount = res.data.total;
        this.loading = false;
      } catch (error) {
        console.error("搜索失败:", error);
        this.loading = false;
      }
    },
    //判断admin使用接口
    performFTPSearchAdmin(){

    },
    // 获取普通列表
    async performFTPSearch() {
            console.log('1')
            this.queryParams.type = 1;
            this.loading = true;
              // 拼接查询参数
            const searchParams = {
              condition: 1,
              type: this.queryParams.type,
              keyword: '',
              metaId: this.queryParams.metaId,
              navigation: {
                batch_no: this.queryParams.navigation.batch_no,
                doc_lable: this.queryParams.navigation.doc_lable
              },
              sort:{
              },
              pageNo: this.queryParams.pageNo,
              pageSize: this.queryParams.pageSize,
              advField: this.queryParams.advField, // 搜索字段
              fieldType: this.queryParams.fieldType, // 字段类型
              connect: this.queryParams.connect, // 逻辑运算符
              advValue: this.queryParams.advValue, // 搜索值
              starttime: this.value1[0], // 开始时间
              endtime: this.value1[1], // 结束时间
            };
      // 发送请求到后端
      try {
        // 检查是否有“adv/search:ftp2”权限
        // console.log('2')
        // console.log(searchParams.starttime);
        // console.log(searchParams.endtime);
        // var dqDate = new Date(); 
        // if (searchParams.starttime == dqDate ){
        //   console.log(dqDate);
        //     searchParams.starttime = this.getTodayStartTime();
        //     searchParams.endtime = this.getTodayEndTime();
        //   }

        const res = this.hasFtp2Perm
          ? await searchPageApi.getSearchPageJUEM(searchParams)
          : await searchPageApi.getSearchPageJM(searchParams);
        // console.log('res1='+res.data.list);
        this.results = res.data.list; // 假设返回的数据包含 results
        this.totalResultsCount = res.data.total;
        // this.getBmList();
        this.loading = false;
        this.isFfBtn = true;
        this.isBlBtn = false;
        this.cancelForm();
      } catch (error) {
        console.error("搜索失败:", error);
        this.loading = false;
      }
    },
    // 获取时间
    handleDateChange(){
      console.log('value1='+this.value1[0]);
      console.log('value2='+this.value1[1]);
      this.hasDaibanAdmin ? this.performFTPSearch() : this.performSearch();
    },
    getTodayStartTime() {
      var myDate = new Date();
      myDate.setDate(myDate.getDate());
      // return myDate.toISOString().substring(0, 10) + ' 00:00:00';
      return myDate.toISOString().substring(0, 10);
    },
    getTodayEndTime() {
      var myDate = new Date();
      myDate.setDate(myDate.getDate());
      // return myDate.toISOString().substring(0, 10) + ' 23:59:59';
      return myDate.toISOString().substring(0, 10);
    },
    // 获取部门列表
    // async getBmList(){
    //   this.loading = true;
    //   // 拼接查询参数
    //   const searchParams = {
    //     userid: 114,
    //   };
    //   // 发送请求到后端
    //   try {
    //     const res = await searchPageApi.deptList(searchParams);
    //     console.log(JSON.stringify(res.data));
    //     this.selectedBmItems = JSON.stringify(res.data); // 假设返回的数据包含 results
    //     console.log(this.selectedBmItems);
    //     this.loading = false;
    //   } catch (error) {
    //     console.error("搜索失败:", error);
    //     this.loading = false;
    //   }
    // },
    //查看原文路径 
    open(file_path) {
        this.$notify.closeAll();
        this.$notify({
          title: '原文路径',
          message: file_path,
          duration: 0,
          offset: 200
        });
      },
      incrementTranslate(){
        this.isTranslate = !this.isTranslate
      },
    getactiveIndex(){
      if(this.hasDaibanAdmin){
        this.activeIndex = 0 ;
      }else{
        this.activeIndex = 3;
      }
    },
    
    goToPage(page) {
      if (page > 0 && page <= this.totalPages) {
        this.currentPage = page;
        this.queryParams.pageNo = page; // 更新分页参数
        this.performSearch(); // 重新请求数据
      }
    },
    handleCurrentChange(newPage) {
      this.currentPage = newPage;
      this.queryParams.pageNo = newPage; // 更新分页参数
      this.performSearch();
    },
    // 打开搜素页面
    openSearchPage(result) {
      localStorage.setItem('detailData', JSON.stringify(result));
      // 打开新标签页
      window.open('/#/search/');
    },
    // 打开收藏页面
        openCollectionPage(result) {
      // localStorage.setItem('detailData', JSON.stringify(result));
      // 打开新标签页
      window.open('/#/search/collection');
    },
    // 打开分析页面
    openAnalysisPage(result) {
      localStorage.setItem('detailData', JSON.stringify(result));
      // 打开新标签页
      window.open('/#/search/analysis');
    },
    // 打开详情页内容开始
    openDetailCont(result){
        this.backTop();
      this.table=true;
      localStorage.setItem('detailData', JSON.stringify(result));
      const storedData = localStorage.getItem('detailData');
      this.clickOne(JSON.parse(storedData).uid,JSON.parse(storedData).docid);
      if (storedData) {
        this.detailData = JSON.parse(storedData);
        // 清除已使用的数据
        // localStorage.removeItem('detailData');
        // console.log(this.detailData.file_path);
        if(this.detailData.file_path == "" || this.detailData.file_path == null ){
          this.downloadShow = false ;
        }
        if(this.detailData.language === '中文'){
          this.isTranslateZw = false ;
        }else{
          this.isTranslateZw = true ;
        }
      } else {
        this.$router.push('/'); // 数据未找到时跳转
      }
    },
    // html内容转换
    decodeHtmlEntity(encodedStr) {
      const doc = new DOMParser().parseFromString(encodedStr, "text/html");
      return doc.body.textContent || doc.body.innerText;
    },
    // 下载文件
    getDownload(){
      const storedData = localStorage.getItem('detailData');
      this.detailData = JSON.parse(storedData);
      const searchParams = {
        filePath: this.detailData.file_path,
        sourcename: this.detailData.sourcename,
      };
      searchPageApi.getDownload(searchParams)
      .then(response=> {
        const blob = new Blob([response], { type: 'application/octet-stream' });
        const url = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        const file_name = this.detailData.file_path.split('/').pop();// 截取文件名
        // console.log(file_name);
        a.style.display = 'none';
        a.href = url;
        a.download = file_name; // 设置下载的文件名
        document.body.appendChild(a);
        a.click();
        window.URL.revokeObjectURL(url);
        a.remove();
      })
      .catch(error => {
          console.error('文件下载失败！:', error);
      });

    },
    backTop() {
      let scrollTop =
        this.$refs.drawer.$refs.drawer.pageYOffset ||
        this.$refs.drawer.$refs.drawer.scrollTop ||
        this.$refs.drawer.$refs.drawer.offsetHeight;
        console.log('scrollTop' + scrollTop)
            // 滚动到顶部
      this.$nextTick(() => {
        const drawerContent = this.$el.querySelector('.el-drawer__body');
        if (drawerContent) {
          drawerContent.scrollTop = 0;
        }
      });
    },
    // 打开详情页内容结束
    // 关闭详情
    cancelForm() {
      this.table=false;
      this.$refs.drawer.close();
    },
        // 点赞量+1
    visitOne(uid,docid,sourcename){
      // const storedData = localStorage.getItem('detailData');
      // this.detailData = JSON.parse(detailData);
      // let colorSet = new Set(bakeColor);
      // console.log("detailData-"+detailData);
      const searchParams = {
        uid: uid,
        docid: docid,
        sourcename: sourcename,
      };
      console.log(searchParams);
      searchPageApi.visitOne(searchParams);
      this.$message({
        message: '点赞成功！',
        type: 'success'
      });
    },
    // 处理文档
    processed(result){
      if(this.hasDaibanAdmin){
        const searchParams = {
          uid: result.uid,
          isAdmin:1,
        };
        searchPageApi.dealdaiban(searchParams);
      }else{
        const searchParams = {
          uid: result.uid,
          docid: result.docid
        };
        searchPageApi.dealdaiban(searchParams);
      }
      this.$confirm('已处理文档！', '提示信息', {
        confirmButtonText: '确定',
        showCancelButton:false,
        showClose:false,
        // cancelButtonText: '取消',
        type: 'success'
      }).then(() => {
        this.performSearch(); // 调用其他方法
      })
    },
            // 访问量+1
    clickOne(uid,docid){
      const searchParams = {
        uid: uid,
        docid: docid,
      };
      console.log(searchParams);
      searchPageApi.clickOne(searchParams);
    },
    // 导出方法
    handleExportList(){
      this.handleExport()
    },
     /** 导出按钮操作 */
    async handleExport() {

    try {
      this.exportLoading = true;
        if(this.selectedItems.length > 0){
          await this.$modal.confirm('是否确认导出所有数据项?');
          let searchParams = '';
          for(var i=0 ;i < this.results.length; i++){
            if(this.results[i].index != this.selectedItems[i] ){
              // console.log("对"+this.selectedItems[i]);
              searchParams = searchParams +',' + this.results[i].docid  ;
            }
          }
          searchParams = searchParams.replace(/^,+/,"").replace(/,+$/,""); 
          console.log('searchParams='+searchParams);
          var param = {"userid":this.$store.state.user.id,"docid":searchParams};
          const res = await searchPageApi.exportExcelDaiBan(param);
          // this.$download.excel(res, this.$store.state.user.nickname+'-我的待办.xls');
          // 获取时间戳
          const time = this.getTimestamp();
          const times = this.formatDateTime(time);
          this.$download.excel(res, '我的待办-'+times+'-'+this.$store.state.user.nickname+'.xls');
          // 获取时间结束
          this.getList();
          this.selectedItems = [];
          this.cancelForm();
        }else{
          alert('请勾选内容！');
        }
      } catch {
      } finally {
        this.exportLoading = false;
      }
      
    },
    // 获取时间戳
    getTimestamp() {
      return new Date().getTime();
    },
    // 转换格式
    formatDateTime(value) { // 时间戳转换日期格式方法
          if (value == null) {
            return ''
          } else {
            const date = new Date(value)
            const y = date.getFullYear() // 年
            let MM = date.getMonth() + 1 // 月
            MM = MM < 10 ? ('0' + MM) : MM
            let d = date.getDate() // 日
            d = d < 10 ? ('0' + d) : d
            let h = date.getHours() // 时
            h = h < 10 ? ('0' + h) : h
            let m = date.getMinutes()// 分
            m = m < 10 ? ('0' + m) : m
            let s = date.getSeconds()// 秒
            s = s < 10 ? ('0' + s) : s
            return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
            }
          },
    async logout() {
      this.$modal.confirm('确定注销并退出系统吗？', '提示').then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = getPath('/index');
        })
      }).catch(() => { });
    }
  },
  mounted:function(){
    if(this.$route.query.gaoji==1){
      this.showAdvancedSearch=true;
    }
    if(this.$route.query.id){
      // console.log('id值：'+this.$route.query.id);
      this.queryParams.navigation.doc_lable=this.$route.query.name;
      this.setActive(this.$route.query.id);
      // this.activeIndex = this.$route.query.id;
      // this.performSearch();

    }

    this.queryParams.navigation.batch_no = [1];
    this.hasDaibanAdmin
      ? this.queryParams.navigation.batch_no = [1]
      : this.queryParams.navigation.batch_no = [2];
    this.getactiveIndex();
    this.performSearch();

    this.nickname = this.$store.state.user.nickname;
    
  }
};

// 关闭输入推荐框
$(document).mouseup(function(e){
    var _con=$('#search-form');//设置目标区域
    if(!_con.is(e.target)&&_con.has(e.target).length===0){
        $('#search-form').hide()
    }
});

</script>

<style scoped>
@import '../../assets/css/css.css';
@import '../../assets/css/index.css';
/* .search-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
} */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-bar input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
}
.search-bar button {
  padding: 8px 16px;
}
.advanced-search-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: #007bff;
  cursor: pointer;
}
.filters {
  display: flex;
  gap: 20px;
  margin-top: 10px;
}
.search-results {
  border-top: 1px solid #eee;
  padding-top: 20px;
}
.loading {
  text-align: center;
  padding: 20px;
  color: #666;
}
.pagination {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 20px;
}
.pagination button,
.pagination span {
  padding: 5px 10px;
  cursor: pointer;
}
.pagination .active {
  font-weight: bold;
  color: #007bff;
}

/* 隐藏原生单选框 */
.hidden-radio {
  display: none;
}

/* 默认样式 */
.custom-radio {
  font-weight: normal;
  cursor: pointer;
}

/* 选中时加粗 */
.hidden-radio:checked + .custom-radio {
  font-weight: bold;
}

.el-button-tk{
    margin-top: 26px;
    margin-bottom: 10px;
}
/* 输入推荐 */
.inputtj{
    /* width: 300px; */
    height: auto;
    background: #fff;
    box-shadow: 0 0 3px rgba(16,115,183,.2);
    /* border: 1px solid #ffffff; */
    border: none;
    position: absolute;
    top: 126px;

    /* left: 0; */
    z-index: 1000;
    padding-right: 20px;
    max-width: 1100px;
}
.inputtj ul{
    padding-left: 10px;
}
.inputtj li{
    cursor: pointer;
    font-size: 14px;
    line-height: 30px;
    color: #333;
    margin: 0;
    width: 100%;
}
.inputtj li:hover{
    color: #0f5de5
}
.app-container{
  padding: 0;
}
.left_nav .list_wrap_li_jyfl{
  margin: 0;
}

::v-deep .el-radio__input {
  display: none !important;
}

::v-deep .el-radio__label {
  font-size: 18px;
  padding: 0;
}
</style>
