require('./../css/searchStaticList.less'); const $ = require("jquery"); const { post,config,getUrlArgObject,openNewWin } = require('./promise.js'); const {toggleWarnBox} = require('./util.js'); let searchType = 0, inputStr = '', curPage = 1, size = 10, totalPage = 1; searchType = getUrlArgObject('type') || 0 inputStr = getUrlArgObject('inputStr') || '' let arrowLeft = require('./../images/leftpage.png').replace(/^undefined/g, '') let arrowRight = require('./../images/rightpage.png').replace(/^undefined/g, '') require('./../images/staticBgS.png').replace(/^undefined/g, '') require('./../images/staticLogo.png').replace(/^undefined/g, '') require('./../images/staticBg.png').replace(/^undefined/g, '') require('./../images/nolis.png').replace(/^undefined/g, '') require('./../images/warn.png').replace(/^undefined/g, '') $(function(){ initData() getAllTypes() getSearchList() getTabData() }); //tab function renderTab(data){ let str = ''; for (let i = 0; i < data.length; i++) { const element = data[i]; str += `
  • ${element.name}
  • ` } $('.staticTopTab ul').html(str) $('.staticTopTab li[data-id='+searchType+']').css({color:'#2A9BD5'}).siblings().css({color:'#333'}); $(".staticTopTab li").click(function(){ searchType = $(this).attr('data-id') $(this).css({color:'#2A9BD5'}).siblings().css({color:'#333'}) }) } //获取字典信息 function getAllTypes(){ /*const allTypes = localStorage.getItem('allTypes')&&JSON.parse(localStorage.getItem('allTypes'))||[]; if(allTypes.length>0){ renderTab(allTypes) return }*/ post(config.dictionaryInfo, {}).then((res) => { const result = res.data if(result.code==='0'){ const data = result.data[7]||[]; //localStorage.setItem('allTypes',JSON.stringify(data)) renderTab(data) } }) } function getSearchList(){ $(".searchBtn").click(function(){ $(".resultItemWrap,.pagination").html(""); $(".staticResult .loading").show(); curPage=1; getTabData() }) } function getTabData(){ let vals = $('.searchStr').val().trim(); if (!vals) { $(".staticResult .loading").hide(); toggleWarnBox('检索词不能为空!'); return; } let param = { size, current:curPage, types:[+searchType], inputStr:vals } $(".resultItemEmpty").hide(); post(config.staticSearch,param).then((res) => { const result = res.data if(result.code == 0) { const data = result.data; tabList = data.records; totalPage = data.pages; const totalNum = data.total; renderList(tabList); if(totalNum > 0){ renderPagination(totalPage,Number(curPage),totalNum) } else{ $('.pagination').html("") } } }) } function renderList(tabList){ $(".staticResult .loading").hide(); if(tabList.length == 0){ $('.pagination').html('') $(".resultItemWrap").html(''); $(".resultItemEmpty").css({display:'block'}); return } let str = '' for(let i = 0;i
    ${item.typeName} ${item.name} ${item.code ?`${item.code}`:''}
    ${item.retrievalName?`
    同义词:${item.retrievalName}
    `:''}

    ${item.abstractContent ? item.abstractContent : ''}

    ` } $(".resultItemWrap").html(str); $('.resultItem').click(function(){ let name = $(this).attr('data-name') let type = $(this).attr('data-type') if(window.opener){ openNewWin(`./staticInfo.html?name=${name}&type=${type}`); }else{ window.open(`./staticInfo.html?name=${name}&type=${type}`); } }) window.scrollTo(0, 0); } function initData(){ if(searchType){ $('.staticTopTab li').eq(searchType).css({color:'#2A9BD5'}).siblings().css({color:'#333'}) } if(inputStr){ $(".searchStr").val(inputStr) } } // 分页 function renderPagination(totalPage,activePage,totalNum){ let str = `共${totalNum}条 ` if(totalPage <= 6){ for(let i = 1; i <= totalPage; i++){ str += `${i}` } }else{ if(activePage <= 3){ //选中页数小于4 for(let i = 1; i <= 4; i++){ str += `${i}` } str += `...` str += `${totalPage}` } else if(activePage > totalPage -3){ str += `1` str += `...` str += `${totalPage -3}` str += `${totalPage -2}` str += `${totalPage -1}` str += `${totalPage}` } else { str += `1` str += `...` str += `${activePage -1}` str += `${activePage}` str += `${activePage +1}` str += `...` str += `${totalPage}` } } str += ` 前往 ` $('.pagination').html(str) $('.page' + activePage).addClass('activePage') $(".pageNum").on("click", function(e){ //console.log($(this)[0]) const activePageNow = Number($(this).attr('data-page')) curPage = activePageNow getTabData() }) $(".prePage").on("click", function(e){ let activePageNow = Number($(".activePage").attr('data-page')) if(activePageNow > 1){ curPage = --activePageNow getTabData() } }) $(".nextPage").on("click", function(e){ let activePageNow = Number($(".activePage").attr('data-page')) if(activePageNow < totalPage){ curPage = ++activePageNow getTabData() } }) $('.select').change(function(){ size = $(this).val(); curPage=1; getTabData() }) $('.goNum input').change(function(){ const n = $(this).val() if (totalPage < n || n < 1) { toggleWarnBox("请输入1-" + totalPage + "范围内的整数"); return; } curPage = n; getTabData() }) } $(function () { $(".warning-box .confirm,.warning-box .close").click(function () { toggleWarnBox(); }) });