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, codeType = 1, codeVal = 1;
searchType = getUrlArgObject('type') || 0
inputStr = getUrlArgObject('inputStr') || ''
codeType = getUrlArgObject('codeType') || 1
codeVal = getUrlArgObject('codeVal') || 1
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, '')
require('./../images/icon-down.png').replace(/^undefined/g, '')
const iconDown = require('./../images/icon-down.png').replace(/^undefined/g, '')
const iconUp = require('./../images/up-icon.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 .knowledge').html(str)
$('.staticTopTab .knowledge li[data-id=' + searchType + ']').addClass('tabFst').siblings().removeClass('tabFst')
$(".staticTopTab .knowledge li").click(function () {
searchType = $(this).attr('data-id')
$(this).addClass('tabFst').siblings().removeClass('tabFst')
})
}
//获取字典信息
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 url, param
if (codeVal == 1) {
url = config.staticSearch
param = {
size,
current: curPage,
types: [+searchType],
inputStr: vals
}
} else {
url = config.diseaseIndex
param = {
current: curPage,
size: size,
inputStr: vals,
type: codeType
}
}
$(".resultItemEmpty").hide();
post(url, 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 < tabList.length; i++) {
let item = tabList[i]
str += codeVal == 1 ? `
${item.typeName}
${item.name}
${item.code ? `医保版${item.name}${item.code}` : ''}
${(item.guoname || item.guocode) ? `国临版${item.guoname}${item.guocode}` : ''}
${item.retrievalName ? `
同义词:${item.retrievalName}
` : ''}
${item.abstractContent ? item.abstractContent : ''}
`: `
${item.code}
${item.name}
`
}
$(".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 .knowledge li').eq(searchType).addClass('tabFst').siblings().removeClass('tabFst')
}
if (codeType) {
$('.staticTopTab .code-list li[data-id=' + codeType + ']').addClass('code-active').siblings().removeClass('code-active')
}
if (codeVal) {
$('.selectItem .selc-list li[data-val=' + codeVal + ']').addClass('active').siblings().removeClass('active')
val = codeVal == 1 ? '医学静态知识' : 'ICD10编码查询'
$(".seleName").html(val)
if (codeVal == 1) {
$(".staticTopTab .knowledge").css('display', 'block')
$(".staticTopTab .code-list").css('display', 'none')
} else {
$(".staticTopTab .knowledge").css('display', 'none')
$(".staticTopTab .code-list").css('display', 'block')
}
}
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();
})
$(".selectItem").click(function (e) {
e.stopPropagation()
const showList = $(".selc-list ").css("display")
if (showList == "none" || !showList) {
$(".selc-list").css('display', 'block')
$(".selectItem .arrow").attr("src", iconUp)
} else {
$(".selc-list").css('display', 'none')
$(".selectItem .arrow").attr("src", iconDown)
}
})
$(".selc-list li").click(function (e) {
e.stopPropagation()
codeVal = $(this).attr('data-val')
codeType = 1
searchType = 0
$(".searchStr").val('')
$(this).addClass('active').siblings().removeClass('active');
$(".knowledge li").eq(0).addClass('tabFst').siblings().removeClass('tabFst')
$(".code-list li").eq(0).addClass('code-active').siblings().removeClass('code-active')
$(".seleName").html($(this).text())
$(".selc-list").css('display', 'none')
$(".selectItem .arrow").attr("src", iconDown)
if (codeVal == 1) {
$(".staticTopTab .code-list").css('display', 'none')
$(".staticTopTab .knowledge").css('display', 'block')
} else {
$(".staticTopTab .code-list").css('display', 'block')
$(".staticTopTab .knowledge").css('display', 'none')
}
$(".staticResult .loading").hide();
$(".resultItemWrap").html('');
$(".resultItemEmpty").css('display', 'block')
$('.pagination').html("")
})
$(".staticTopTab .code-list li").click(function () {
codeType = $(this).attr('data-id')
$(this).addClass('code-active').siblings().removeClass('code-active')
})
});
$(document).on("click", function () {
$(".selc-list").css('display', 'none')
$(".selectItem .arrow").attr("src", iconDown)
})