staticInfo.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. if (!Promise) {
  2. var Promise = require("bluebird");
  3. // Configure
  4. Promise.config({
  5. longStackTraces: true,
  6. warnings: true // note, run node with --trace-warnings to see full stack traces for warnings
  7. })
  8. }
  9. require('../css/staticInfo.less')
  10. const {
  11. post,
  12. throttle,
  13. imageUrlPrefix,
  14. config,
  15. getUrlArgObject,
  16. openNewWin,
  17. Toast
  18. } = require('./promise.js');
  19. const $ = require("jquery");
  20. require("./jquery-migrate");
  21. const jqprint = require("../js/jquery.PrintArea")
  22. let printing = require('./../images/printing.png');
  23. let printing2 = require('./../images/printing2.png');
  24. let recommend = require('./../images/recommend.png');
  25. let hel = require('./../images/icon-hel.png');
  26. let showName, noticeName, clinicalPathwayName, isclick
  27. function myBrowser() {
  28. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  29. var isOpera = userAgent.indexOf("Opera") > -1;
  30. if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
  31. return "IE";
  32. }; //判断是否IE浏览器
  33. }
  34. function getInfomation() {
  35. var param = {
  36. "type": getUrlArgObject('type'),
  37. "name": getUrlArgObject('name'),
  38. "position": getUrlArgObject('position'),
  39. "contentTypes": [1, 2, 3],
  40. "mrId": getUrlArgObject('mrId')
  41. };
  42. showName = param.name
  43. $(".tabBox .title").html(showName);
  44. post(config.information, param).then((res) => {
  45. const data = res.data.data
  46. // const data = dataaaa.data
  47. document.title = showName
  48. var str = '';
  49. var anchors = '';
  50. if (!data) {
  51. $(".title").html("暂时没有数据");
  52. $(".anchors").css("display", "none");
  53. return;
  54. }
  55. var detailList = data.details
  56. var scale = data.scale
  57. var staticKnowList = detailList['静态知识']
  58. var noticeInfo = detailList['注意事项']
  59. var clinicalPathwayInfo = detailList['临床路径']
  60. var scaleInfo = data.scale ? data.scale.scaleDetails : ''
  61. var name = data.name
  62. noticeName = data.noticeName || "注意事项"
  63. clinicalPathwayName = data.clinicalPathwayName || "临床路径"
  64. renderTab(detailList, scale)
  65. staticKnowList && renderContent(staticKnowList, 'staticKnowledge')
  66. noticeInfo && renderContent(noticeInfo, 'notice')
  67. clinicalPathwayInfo && renderContent(clinicalPathwayInfo, 'clinicalPathway')
  68. scaleInfo && renderContentscale(scaleInfo, 'scale', name)
  69. $('.content img').bind('contextmenu', function () {
  70. return false
  71. })
  72. })
  73. }
  74. getInfomation();
  75. function renderContent(list, contentWrapClassName) {
  76. for (var i = 0; i < list.length; i++) {
  77. var item = list[i];
  78. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  79. anchors = '<li><i></i><a href="#' + contentWrapClassName + i +
  80. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  81. str = '<div class="infoBox"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  82. '">'
  83. /*if (getUrlArgObject('type') == 8) {
  84. str += '【' + item.title + '】'
  85. } else {*/
  86. str += item.title
  87. /*}*/
  88. str += '</h2></div>' +
  89. '<div class="contentWrapper"><pre>' + item.content + '</pre><div></div>';
  90. str = `<div class="infoWrapper">${str}</div>`
  91. $(`.${contentWrapClassName} .infos`).append(str);
  92. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  93. }
  94. function addScrollEvent() {
  95. var scrollTop = $(`.${contentWrapClassName} .infos`).scrollTop()
  96. var divHeight = 0;
  97. for (var i = 0; i < list.length; i++) {
  98. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  99. if (divHeight > scrollTop) {
  100. var anchor = 2 * i;
  101. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  102. return;
  103. }
  104. }
  105. }
  106. $(`.${contentWrapClassName} .infos`).scroll(throttle(addScrollEvent, 200));
  107. addLinkClickEvent(contentWrapClassName);
  108. adjustHeight();
  109. adjustWidth()
  110. }
  111. function renderContentscale(list, contentWrapClassName, name) {
  112. var pushInfo = []
  113. var textType = []
  114. for (var i = 0; i < list[0].detailList.length; i++) {
  115. var item = list[0].detailList[i];
  116. console.log(item.resultType)
  117. textType.push(item.textType)
  118. if (item.textType == 11) {
  119. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  120. str = '<div class="infoBox scaleBox" data-id="' + item.id + '"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  121. '">'
  122. str += item.content
  123. str += '</h2></div>'
  124. str = `<div class="infoWrapper">${str}</div>`
  125. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  126. for (var j = 0; j < item.subList.length; j++) {
  127. var items = item.subList[j];
  128. for (var k = 0; k < items.detailList.length; k++) {
  129. var it = items.detailList[k];
  130. it.content = it.content && it.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  131. str = '<div class="contentList" data-id="' + it.parentId + '-' + it.groupNum + '"><div class="item-list">';
  132. if (it.selectType == 21) {
  133. str += '<p class="item-title">' + it.content + '</p>'
  134. } else if (it.selectType == 22) {
  135. str += '<p class="item-titles">' + it.content + '</p>'
  136. }
  137. str += '<div class="item-content" data-id="' + it.id + '">'
  138. str += '</div></div></div>'
  139. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
  140. for (var l = 0; l < it.subList[0].detailList.length; l++) {
  141. var its = it.subList[0].detailList[l];
  142. its.content = its.content && its.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  143. str = '<div class="radio" name="scale' + its.parentId + '" value="' + its.score + '">';
  144. if (it.selectType == 21 && item.resultType == 1) {
  145. str += '<label><input class="radio_type" type="radio" name="scale' + its.parentId + '" value="' + parseFloat(((its.score * it.factor + it.constant) * item.factor + item.constant)) + '"/>'
  146. } else if (it.selectType == 22 && item.resultType == 1) {
  147. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + parseFloat(((its.score * it.factor + it.constant) * item.factor + item.constant)) + '"/>'
  148. } else if (it.selectType == 21 && item.resultType == 2) {
  149. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.result + '" data_obj="' + it.content + '' + its.result + '" proposal="' + its.pushInfo +'"/>'
  150. } else if (it.selectType == 22 && item.resultType == 2) {
  151. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + its.result + '" data_obj="' + it.content + '' + its.result + '" proposal="' + its.pushInfo +'"/>'
  152. }
  153. str += its.content
  154. if (item.resultType == 1) {
  155. str += '<span class="num">' + its.score + '</span>'
  156. }
  157. str += '</label>'
  158. str += `${its.match == 1 ? `<img class="recommend" src="./../images/recommend.png" />` : ``}</div>`
  159. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "] .contentList .item-content[data-id=" + its.parentId + "]").append(str);
  160. }
  161. }
  162. }
  163. }
  164. if (item.textType == 13) {
  165. for (var m = 0; m < item.subList[0].detailList[0].subList[0].detailList.length; m++) {
  166. var itl = item.subList[0].detailList[0].subList[0].detailList[m]
  167. let arr = {
  168. content: JSON.parse(itl.content),
  169. result: itl.result,
  170. pushInfo: itl.pushInfo
  171. }
  172. pushInfo.push(arr)
  173. }
  174. }
  175. }
  176. str = '<div class="scalebot">'
  177. str += '<button class="but">结果</button><p class="score"></p>'
  178. str += '</div>'
  179. str += `<div class="result"><div class="result_box"><div class="result_left"><img src="./../images/icon-hel.png" class="hel"/><span>结果:</span></div><p id="result_title" class="result_title"></p><textarea id="inputs"></textarea></div></div>`
  180. str += `<div class="foot"><div class="foot_box"><div class="printing"><img src="./../images/printing.png" class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  181. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  182. // str = `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  183. // $(`.${contentWrapClassName} .infos`).after(str);
  184. function addScrollEvent() {
  185. var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
  186. var divHeight = 0;
  187. for (var i = 0; i < list.length; i++) {
  188. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  189. if (divHeight > scrollTop) {
  190. var anchor = 2 * i;
  191. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  192. return;
  193. }
  194. }
  195. }
  196. $(`.${contentWrapClassName} .infos .infos-box`).scroll(throttle(addScrollEvent, 200));
  197. var mb = myBrowser();
  198. if ("IE" == mb) {
  199. $('.result_left').css({
  200. 'position': 'relative', //高度自动
  201. })
  202. $('.result_title').css({
  203. 'margin-left': '0', //高度自动
  204. })
  205. }
  206. addLinkClickEvent(contentWrapClassName);
  207. adjustHeight();
  208. adjustWidth()
  209. getcheck()
  210. getResult(pushInfo, textType)
  211. copy(name)
  212. getprinting()
  213. }
  214. function getprinting() {
  215. $('.printing').click(function () {
  216. $('.foot').hide()
  217. // $('.hel').hide()
  218. $('#Print').css({
  219. 'height': 'auto', //高度自动
  220. }).jqprint();
  221. $('.foot').show()
  222. // $('.hel').show()
  223. $('#Print').css({
  224. 'height': '100%', //高度自动
  225. });
  226. })
  227. }
  228. function getcheck() {
  229. $('input:radio').click(function () {
  230. const domName = $(this).attr('name');
  231. const $radio = $(this);
  232. const id = $(this).parents('.contentList').data("id");
  233. if ($radio.data('waschecked') == true) {
  234. $radio.prop('checked', false);
  235. $("input:radio[name='" + domName + "']").data('waschecked', false);
  236. $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", false);
  237. if (isclick) {
  238. getchecks()
  239. $(".score").html('');
  240. $(".result_title").html('');
  241. $(".result").css('display', 'none')
  242. $(".foot").css('display', 'none')
  243. }
  244. } else {
  245. $radio.prop('checked', true);
  246. $("input:radio[name='" + domName + "']").data('waschecked', false);
  247. $radio.data('waschecked', true);
  248. $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", true);
  249. if (isclick) {
  250. getchecks()
  251. $(".score").html('');
  252. $(".result_title").html('');
  253. $(".result").css('display', 'none')
  254. $(".foot").css('display', 'none')
  255. }
  256. }
  257. });
  258. $('input:checkbox').click(function () {
  259. const domName = $(this).attr('name');
  260. const $radio = $(this);
  261. const id = $(this).parents('.contentList').data("id");
  262. $radio.parents('.contentList').each(function (i) {
  263. if ($(this).find('input[type="checkbox"]:checked').val() == undefined) {
  264. $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", false);
  265. if (isclick) {
  266. getchecks()
  267. $(".score").html('');
  268. $(".result_title").html('');
  269. $(".result").css('display', 'none')
  270. $(".foot").css('display', 'none')
  271. }
  272. } else {
  273. $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", true);
  274. if (isclick) {
  275. getchecks()
  276. $(".score").html('');
  277. $(".result_title").html('');
  278. $(".result").css('display', 'none')
  279. $(".foot").css('display', 'none')
  280. }
  281. }
  282. })
  283. });
  284. }
  285. function copy(name) {
  286. $(".copy").click(function () {
  287. var texts = document.getElementById("result_title").innerText;
  288. if (texts == '') {
  289. Toast('结果为空,无法复制', 500, 'warn')
  290. return
  291. }
  292. var inputs = document.getElementById("inputs");
  293. inputs.value = name + '结果为:' + texts; // 修改文本框的内容(赋值内容)
  294. console.log(inputs.value)
  295. inputs.select(); // 选中文本
  296. document.execCommand("copy"); // 执行浏览器复制命令
  297. Toast('复制成功', 500, 'success')
  298. })
  299. }
  300. function getchecks() {
  301. $(".contentList").each(function (i) {
  302. if ($(this).find('input[type="radio"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  303. $(this).find(".item-title").addClass('chColor');
  304. } else {
  305. $(this).find(".item-title").removeClass('chColor');
  306. }
  307. if ($(this).find('input[type="checkbox"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  308. $(this).find(".item-titles").addClass('chColor');
  309. } else {
  310. $(this).find(".item-titles").removeClass('chColor');
  311. }
  312. });
  313. }
  314. function getResult(pushInfo, textType) {
  315. $(".but").click(function () {
  316. let arr = [];
  317. let multarr = []
  318. let multname
  319. let num = 0
  320. let result
  321. let key = false
  322. let proposal = ''
  323. let proposals = []
  324. isclick = true
  325. $(".contentList").each(function (i) {
  326. if ($(this).find('input[type="radio"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  327. $(this).find(".item-title").addClass('chColor');
  328. } else {
  329. $(this).find(".item-title").removeClass('chColor');
  330. }
  331. if ($(this).find('input[type="checkbox"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  332. $(this).find(".item-titles").addClass('chColor');
  333. } else {
  334. $(this).find(".item-titles").removeClass('chColor');
  335. }
  336. });
  337. if (!$(".contentList").find(".item-title").hasClass('chColor') && !$(".contentList").find(".item-titles").hasClass('chColor')) {
  338. $('input[type="radio"]:checked').each(function () {
  339. if (!isNaN($(this).val())) {
  340. num += parseFloat($(this).val())
  341. } else {
  342. arr.push($(this).attr("data_obj"))
  343. proposals.push($(this).attr("proposal"))
  344. }
  345. });
  346. $('input[type="checkbox"]:checkbox:checked').each(function () {
  347. if (!isNaN($(this).val())) {
  348. num += parseFloat($(this).val())
  349. } else {
  350. arr.push($(this).attr("data_obj"))
  351. proposals.push($(this).attr("proposal"))
  352. }
  353. });
  354. tmp = arr.join(";");
  355. if (pushInfo.length > 0) {
  356. for (var i = 0; i < pushInfo.length; i++) {
  357. if (pushInfo[i].content.max >= num && num >= pushInfo[i].content.min && !tmp) {
  358. result = pushInfo[i].result + '(' + num + '分' + ')'
  359. proposal = pushInfo[i].pushInfo
  360. break
  361. } else if (pushInfo[i].content.max >= num && num >= pushInfo[i].content.min && tmp) {
  362. result = pushInfo[i].result + '(' + num + '分' + ')' + ';' + tmp
  363. proposal = pushInfo[i].pushInfo
  364. break
  365. } else {
  366. result = tmp
  367. }
  368. }
  369. } else {
  370. result = tmp
  371. proposal = proposals.join(";");
  372. }
  373. if (result == undefined) {
  374. if ($.inArray(13, textType) > 0) {
  375. $(".score").html('总分:' + num + '分');
  376. }
  377. $(".score").css('display', 'block')
  378. $(".copy").css('display', 'none')
  379. $(".foot").css('display', 'block')
  380. } else {
  381. $(".hel").attr({
  382. "title": proposal
  383. });
  384. $(".result_title").html(result);
  385. if ($.inArray(13, textType) > 0) {
  386. $(".score").html('总分:' + num + '分');
  387. }
  388. $(".result").css('display', 'block')
  389. $(".score").css('display', 'block')
  390. $(".copy").css('display', 'block')
  391. $(".foot").css('display', 'block')
  392. }
  393. } else {
  394. Toast('温馨提示:必填选项不能为空~', 500000, 'warn')
  395. }
  396. })
  397. $(".printing").hover(
  398. function () {
  399. $(".slideImg").attr("src", "./../images/printing2.png");
  400. }, function () {
  401. $(".slideImg").attr("src", "./../images/printing.png");
  402. });
  403. }
  404. function addLinkClickEvent(contentWrapClassName) {
  405. $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
  406. $(`.${contentWrapClassName} .anchors li>a`).on("click", function () {
  407. const that = this
  408. setTimeout(function () {
  409. $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
  410. $(that).parent().addClass("active");
  411. }, 20)
  412. });
  413. }
  414. function renderTab(detailList, scale) {
  415. if (detailList['静态知识']) {
  416. $(".tabList").append(`<span class="tab" data-module="staticKnowledge" data-title="` + showName + `">静态知识</span>`)
  417. }
  418. if (detailList['临床路径']) {
  419. $(".tabList").append(`<span class="tab" data-module="clinicalPathway" data-title="` + clinicalPathwayName + `">临床路径</span>`)
  420. //$(".tabBox .title").html(clinicalPathwayName);
  421. }
  422. if (detailList['注意事项']) {
  423. $(".tabList").append(`<span class="tab" data-module="notice" data-title="` + noticeName + `">注意事项</span>`)
  424. //$(".tabBox .title").html(noticeName);
  425. }
  426. if (scale || getUrlArgObject('gauge') == 'gauge' || getUrlArgObject('type') == 8) {
  427. $(".tabList").append(`<span class="tab" data-module="scale" data-title="` + showName + `">评估内容</span>`)
  428. //$(".tabBox .title").html(noticeName);
  429. }
  430. let defaultModuleName
  431. if (getUrlArgObject('page') && getUrlArgObject('page') == 1 && scale && detailList['静态知识']) {
  432. $(".tabList .tab").eq(1).addClass("activeTab")
  433. defaultModuleName = $(".tabList .tab").eq(1).attr("data-module")
  434. } else {
  435. $(".tabList .tab").eq(0).addClass("activeTab")
  436. defaultModuleName = $(".tabList .tab").eq(0).attr("data-module")
  437. }
  438. $(`.${defaultModuleName}`).css("display", "block")
  439. bindTabClick()
  440. }
  441. function bindTabClick() {
  442. $(".tabList .tab").on("click", function () {
  443. const moduleName = $(this).attr("data-module")
  444. const display = $(`.${moduleName}`).css("display")
  445. $(".tabBox .title").html($(this).attr('data-title'));
  446. if (display == "none") {
  447. $(".activeTab").removeClass("activeTab")
  448. $(this).addClass("activeTab")
  449. $(".container").css("display", "none")
  450. $(`.${moduleName}`).css("display", "block")
  451. $(`.${moduleName} .infos`).scrollTop(0)
  452. }
  453. })
  454. $("#openWin").on("click", function () {
  455. const type = getUrlArgObject('type');
  456. const name = getUrlArgObject('name');
  457. const position = getUrlArgObject('position');
  458. openNewWin("staticInfo.html?name=" + encodeURIComponent(name) + "&position=" + encodeURIComponent(position) + "&type=" + encodeURIComponent(type));
  459. })
  460. }
  461. function adjustHeight() {
  462. var ht = window.innerHeight || document.documentElement.clientHeight;
  463. $(".content,.content .infos").height(ht - 162 + "px");
  464. }
  465. function adjustWidth() {
  466. var wt = window.innerWidth || document.documentElement.clientWidth;
  467. $(".titleH2").width(wt - 0.2 * wt - 33 - 200 - 17 - 40 - 15 + 'px')
  468. $(".content .infos").width(wt- 210 + 'px');
  469. //$("pre").width(wt- 0.2*wt - 240 + 'px')
  470. }
  471. $(window).on('resize', function () {
  472. adjustHeight()
  473. adjustWidth()
  474. })
  475. //如果是子窗口,隐藏网页查看按钮
  476. if (window.opener) {
  477. $("#openWin").hide();
  478. }