const $ = require("jquery");
const { openNewWin, imageUrlPrefix, isIe8 } = require('./promise.js');
const { bindTipsEvent } = require('./popupEdit.js');
let showImg = require('./../images/show.png')
let collapseImg = require('./../images/collapse.png')
const is8Ie = isIe8() //判断是否为IE8
if(is8Ie) {
let reg = /undefined/g
showImg = showImg.replace(reg, '')
collapseImg = collapseImg.replace(reg, '')
}
//推荐诊断等单种类型的
function renderRecommendInfo(showNum, icon, className,title,data, hasInfo, type, position) {
let showNumCopy = showNum || 5
const dataLen = data.length
const str = `
${title}:
`
$('.push').append(str)
let dataShort
if(showNumCopy&& dataLen > showNumCopy) {
dataShort = data.slice(0, showNumCopy)
} else {
dataShort = data
}
let childrenNodeStrShort = ''
let childrenNodeStrLong = ''
if(hasInfo) {
for (let i = 0; i < dataShort.length; i++) {
childrenNodeStrShort += `
${data[i].name}
`
}
for (let i = 0; i < data.length; i++) {
childrenNodeStrLong += `
${data[i].name}
`
}
} else {
for (let i = 0; i < dataShort.length; i++) {
childrenNodeStrShort += `
${data[i].name}
`
}
for (let i = 0; i < data.length; i++) {
childrenNodeStrLong += `
${data[i].name}
`
}
}
if(!childrenNodeStrShort) {
childrenNodeStrShort = '暂无推荐'
}
$('.'+className + 'box').append(childrenNodeStrShort)
let childrenNodeStrAll = `
${title}:
${childrenNodeStrLong}
`
$('.push').append(childrenNodeStrAll)
$('.'+className + 'box' +' .infoMsg').on('click', function(){
const infoMsgName = $(this).attr('data-name')
openNewWin(`information.html?type=${type}&position=${position}&name=${infoMsgName}`)
})
$('.'+className + 'boxAll' +' .infoMsg').on('click', function(){
const infoMsgName = $(this).attr('data-name')
openNewWin(`information.html?type=${type}&position=${position}&name=${infoMsgName}`)
})
slideToggle("."+className+"box", showNumCopy, dataLen)
}
//化验和辅检等多种类型
function renderMultRecommendInfo(labsAndPacMode,icon, className,title,data, hasInfo, type, position) {
console.log(labsAndPacMode)
const str = `
${title}:
`
$('.push').append(str)
for(let i = 0; i < data.length; i++) {
const showNum = data[i].showNum || 5
const dataLen = data[i].data.length
let childrenNodeBoxStr = ``
let childrenNodeStr = `${data[i].title}`
let childrenNodeItemStrAll = '' //更多展开框中的字符串
let dataShort
if(showNum&& dataLen > showNum) {
dataShort = data[i].data.slice(0, showNum)
} else {
dataShort = data[i].data
}
for(let j = 0; j < dataShort.length; j++) {
childrenNodeStr += `${dataShort[j].name}`
}
for(let j = 0; j < data[i].data.length; j++) {
childrenNodeItemStrAll += `${data[i].data[j].name}`
}
if(data[i].data.length == 0) {
childrenNodeStr +='暂无推荐'
}
$('.'+className + 'box').append(childrenNodeBoxStr)
$('.'+data[i].className+'box').append(childrenNodeStr)
let childrenNodeStrAll = `
${data[i].title}:
${childrenNodeItemStrAll}
`
$('.push').append(childrenNodeStrAll)
slideToggle("."+data[i].className+"box", showNum, dataLen)
}
}
function renderTreat(icon, className,title, data) {
$('.infoTabBox').append(`${title}`)
const str = ``
$('.infomationBox').append(str)
const commonTreatmentInfo = data.commonTreatment&&data.commonTreatment.content || ""
const treatmentList = data.treatment || []
renderTreatText('commonTreatment', '一般治疗', commonTreatmentInfo, className+'box')
renderTreatDrug('drugTreatment', '药物治疗', treatmentList, className+'box')
}
function renderKnowledgeInfo(icon, className,title, data) {
$('.infoTabBox').append(`${title}`)
const str = ``
$('.infomationBox').append(str)
$('.'+className+'.staticWin' ).on('click', function(){
openNewWin(`staticSearch.html?type=1`)
})
}
function renderScaleInfo(icon, className,title, data) {
$('.infoTabBox').append(`${title}`)
const str = ``
$('.infomationBox').append(str)
$('.'+className+'.staticWin' ).on('click', function(){
openNewWin(`staticSearch.html?type=2&msg=${encodeURIComponent(JSON.stringify(msg))}`)
})
}
function renderTreatText(className,title,data, parentNode) {
const childrenNodeBoxStr = `
`
$('.' + parentNode).append(childrenNodeBoxStr)
if(!data) {
data = '暂无推荐'
}
$('.' + className+'Info').html(data)
var commonTreatHeight = $(".commonTreatmentInfo").height()
if(commonTreatHeight > 75){
$(".treatTextBox").append('更多')
}
$(".infomationBox .treatTextBox").on('click',".more",function(){
openNewWin(`treatplan.html?msg=${encodeURIComponent(JSON.stringify(msg))}`)
})
}
function renderTreatDrug(className,title,data, parentNode) {
const childrenNodeBoxStr = `
`
$('.' + parentNode).append(childrenNodeBoxStr)
if(data.length ==0) {
$('.' + className+'Info').append('暂无推荐')
}
for(let i = 0; i < data.length; i++) {
let childrenNodeStr = `
${i+1}.${data[i].bigdrugsName}${data[i].subdrugsName&&"("+data[i].subdrugsName+")"}:`
for (let j = 0; j < data[i].medicitionsList.length; j++) {
childrenNodeStr += `${data[i].medicitionsList[j].medicitionName}`
if(data[i].medicitionsList[j].forbidden == '1') {
childrenNodeStr += `慎用`
} else if(data[i].medicitionsList[j].forbidden == '2') {
childrenNodeStr += `禁用`
}
childrenNodeStr += ``
if(j !== data[i].medicitionsList.length-1) {
childrenNodeStr += ','
}
childrenNodeStr += ''
// childrenNodeStr += `使用率${data[i].medicitionsList[j].rate}`
// if(j === data[i].medicitionsList.length-1) {
// childrenNodeStr += ';'
// } else {
// childrenNodeStr += ','
// }
}
childrenNodeStr += `
`
$('.' + className+'Info').append(childrenNodeStr)
}
$('.' + className+'Info'+ ' .infoMsg').on('click', function(){
const infoMsgName = $(this).attr('data-name')
openNewWin(`information.html?type=8&position=5&name=${infoMsgName}`)
})
var drugTreatmentHeight = $(".drugTreatmentInfo").height()
if(drugTreatmentHeight > 75){
$(".treatDrugBox").append('更多')
} else if(drugTreatmentHeight > 30) {
$(".drugTreatmentInfo").append('更多')
}
$(".infomationBox .drugTreatmentbox").on('click',".more",function(){
openNewWin(`treatplan.html?msg=${encodeURIComponent(JSON.stringify(msg))}`)
// openNewWin(`treatplan.html?age=${msg.age}&sex=${msg.sex}&symptomJson=${msg.symptom}&vitalJson=${msg.vital}&lisJson=${msg.lis}&pacsJson=${msg.pacs}&diseaseName=${msg.diseaseName}&diagJson=${msg.diag}&otherJson=${msg.other}&hospitalCode=${msg.hosCode}`)
})
var treatList = $(".drugTreatmentInfo").find(".drugTreatmentInfoItemBox")
// for(var h = 0;h < treatList.length;h++){
// if($(treatList[h]).height() > 25){
// $(treatList[h]).addClass('recommendInfoItemBoxLimit').append('更多 ')
// }
// $(".drugTreatmentInfo").on('click',".slideDown",function(){
// $(this).parents(".drugTreatmentInfoItemBox ").removeClass("recommendInfoItemBoxLimit").append('收起 ')
// $(this).remove()
// })
// $(".drugTreatmentInfo").on('click',".slideup",function(){
// $(this).parents(".drugTreatmentInfoItemBox ").addClass("recommendInfoItemBoxLimit").append('更多 ')
// $(this).remove()
// })
// }
}
function renderTipsInfo(icon, className,title,data) {
$('.infoTabBox').append(`${title}`)
let str
if(data.length === 0) {
str = ``
} else {
str = ``
}
$('.infomationBox').append(str)
for(let i = 0; i < data.length; i++) {
renderTipsInfoText('','诊断依据',data[i],className + 'box')
}
// if(data.name) {
// renderTipsInfoText('','诊断依据',data.details,className + 'box')
// }
if(data.length > 1) {
$('.tipsInfoItem').each(function(i, obj){
var lineHeight = parseInt($(this).css("line-height"));
var height = parseInt($(this).height());
if((height / lineHeight) >3 ){
$(this).addClass("hasMore")
$(this).css("height","60px");
}else{
$(this).removeClass("hasMore");
}
});
}
}
function renderTipsInfoText(className,title,data, parentNode) {
let childrenNodeBoxStr = `${data.name} 详情
`
if(data.details.length === 0) {
childrenNodeBoxStr += `暂无数据
`
} else {
for(let i = 0; i < data.details.length; i++) {
childrenNodeBoxStr += `
${data.details[i].title}
${data.details[i].content.replace(/{imageUrlPrefix}/g, imageUrlPrefix)}
`
}
}
$('.' + parentNode).append(childrenNodeBoxStr)
}
function renderRecommendConditTips(icon, className,title,data) {
const str = `
${title}:
`
$('.push').append(str)
if(data.length == 0) {
$("."+className+"box").append('暂无推荐')
}
/*let names = [];*/
for(var k = 0;k < data.length;k++){
var tmpBq = data[k];
let hasSritical = false
let tmpBqStr;
if(tmpBq.details) {
for(let i = 0; i < tmpBq.details.length; i++) {
if(tmpBq.details[i].type == 4) {
hasSritical= true
}
}
}
if(hasSritical) {
/*if(names.includes(tmpBq.name)){ //name相同去重
tmpBqStr='';
}else{
names.push(tmpBq.name);*/
tmpBqStr = `
${tmpBq.name}
`
// }
} else {
tmpBqStr = `
患者可能有 ${tmpBq.name}:
`
}
var tmpBqDetailStr = ''
for(var m = 0;m < tmpBq.details.length;m++){
var tmpBqDetail = tmpBq.details[m]
if(tmpBqDetail.type == 1){
tmpBqDetailStr+=`【${tmpBqDetail.content.name}】`
}
if(tmpBqDetail.type == 4){
// tmpBqDetailStr+=` ${tmpBqDetail.content.name}(诊断要点)`
}
}
/*if(tmpBqStr){*/
$("."+className+"box").append(''+tmpBqStr+'
'+tmpBqDetailStr+'
更多 ')
//}
//$("."+className+"box").append(''+tmpBqStr+'
'+tmpBqDetailStr+'
更多 ')
}
$('.mayIllness .infoMsg').on('click', function(){
const infoMsgName = $(this).attr('data-name')
openNewWin(`information.html?type=22&position=2&name=${infoMsgName}`)
})
$('.alertModal .illnessTable').on('click', function(){
const infoMsgUrl = $(this).attr('data-url')
openNewWin(infoMsgUrl)
})
$(".conditTipsbox").on('click',".more",function(){
// openNewWin(`illness.html?age=${msg.age}&sex=${msg.sex}&symptomJson=${msg.symptom}&vitalJson=${msg.vital}&lisJson=${JSON.stringify(msg.lis)}&pacsJson=${msg.pacs}&diagJson=${msg.diag}&diseaseName=${msg.diseaseName}&otherJson=${msg.other}&hospitalCode=${msg.hosCode}&msg=${JSON.stringify(msg)}`)
openNewWin(`illness.html?msg=${encodeURIComponent(JSON.stringify(msg))}`)
})
bindTipsEvent()
}
function slideToggle(className, showNum, dataLen){//展开收起
const domName = $(className)
const domNameBoxAll = $(className+'All')
setTimeout(() => {
if(showNum < dataLen){
domName.append(`
`)
}
});
domName.on('click',".slideDown",function(){
$(".itemAllBox").css('display', 'none')
$(domNameBoxAll).css('display', 'block')
})
domNameBoxAll.on('click',".slideup",function(){
$(domNameBoxAll).css('display', 'none')
})
}
//打开免责申明
$(".disclaimer .logo").on("click",function() {
openNewWin("disclaimer.html");
});
module.exports = {
renderRecommendInfo,
renderMultRecommendInfo,
renderTreat,
renderRecommendConditTips,
renderTipsInfo,
renderKnowledgeInfo,
renderScaleInfo
}