staticInfo.js 19 KB

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