staticInfo.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 showName, noticeName, clinicalPathwayName
  26. function getInfomation() {
  27. var param = {
  28. "type": getUrlArgObject('type'),
  29. "name": getUrlArgObject('name'),
  30. "position": getUrlArgObject('position'),
  31. "contentTypes": [1, 2, 3],
  32. "mrId": getUrlArgObject('mrId')
  33. };
  34. showName = param.name
  35. $(".tabBox .title").html(showName);
  36. post(config.information, param).then((res) => {
  37. const data = res.data.data
  38. // const data = dataaaa.data
  39. document.title = showName
  40. var str = '';
  41. var anchors = '';
  42. if (!data) {
  43. $(".title").html("暂时没有数据");
  44. $(".anchors").css("display", "none");
  45. return;
  46. }
  47. var detailList = data.details
  48. var scale = data.scale
  49. var staticKnowList = detailList['静态知识']
  50. var noticeInfo = detailList['注意事项']
  51. var clinicalPathwayInfo = detailList['临床路径']
  52. var scaleInfo = data.scale ? data.scale.scaleDetails : ''
  53. var name = data.name
  54. noticeName = data.noticeName || "注意事项"
  55. clinicalPathwayName = data.clinicalPathwayName || "临床路径"
  56. renderTab(detailList, scale)
  57. staticKnowList && renderContent(staticKnowList, 'staticKnowledge')
  58. noticeInfo && renderContent(noticeInfo, 'notice')
  59. clinicalPathwayInfo && renderContent(clinicalPathwayInfo, 'clinicalPathway')
  60. scaleInfo && renderContentscale(scaleInfo, 'scale', name)
  61. $('.content img').bind('contextmenu', function () {
  62. return false
  63. })
  64. })
  65. }
  66. getInfomation();
  67. function renderContent(list, contentWrapClassName) {
  68. for (var i = 0; i < list.length; i++) {
  69. var item = list[i];
  70. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  71. anchors = '<li><i></i><a href="#' + contentWrapClassName + i +
  72. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  73. str = '<div class="infoBox"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  74. '">'
  75. /*if (getUrlArgObject('type') == 8) {
  76. str += '【' + item.title + '】'
  77. } else {*/
  78. str += item.title
  79. /*}*/
  80. str += '</h2></div>' +
  81. '<div class="contentWrapper"><pre>' + item.content + '</pre><div></div>';
  82. str = `<div class="infoWrapper">${str}</div>`
  83. $(`.${contentWrapClassName} .infos`).append(str);
  84. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  85. }
  86. function addScrollEvent() {
  87. var scrollTop = $(`.${contentWrapClassName} .infos`).scrollTop()
  88. var divHeight = 0;
  89. for (var i = 0; i < list.length; i++) {
  90. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  91. if (divHeight > scrollTop) {
  92. var anchor = 2 * i;
  93. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  94. return;
  95. }
  96. }
  97. }
  98. $(`.${contentWrapClassName} .infos`).scroll(throttle(addScrollEvent, 200));
  99. addLinkClickEvent(contentWrapClassName);
  100. adjustHeight();
  101. adjustWidth()
  102. }
  103. function renderContentscale(list, contentWrapClassName, name) {
  104. var pushInfo = []
  105. var textType = []
  106. // anchors = '<li><i></i><a href="#' + contentWrapClassName +
  107. // '">' + name + '</a></li><li class="anchor-line"></li>';
  108. // str = '<p class="scaletitle">' + name + '</p>'
  109. // $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  110. // $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  111. for (var i = 0; i < list[0].detailList.length; i++) {
  112. var item = list[0].detailList[i];
  113. console.log(item.resultType)
  114. textType.push(item.textType)
  115. if (item.textType == 11) {
  116. anchors = '<li><i></i><a href="#' + contentWrapClassName + i +
  117. '">' + item.content + '</a></li><li class="anchor-line"></li>';
  118. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  119. str = '<div class="infoBox scaleBox" data-id="' + item.id + '"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  120. '">'
  121. str += item.content
  122. str += '</h2></div>'
  123. str = `<div class="infoWrapper">${str}</div>`
  124. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  125. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  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 + '"><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' + it.parentId + '" value="' + its.score + '"/>'
  146. } else if (it.selectType == 22 && item.resultType == 1) {
  147. str += '<label><input class="radio_type" name="scale' + it.parentId + '" type="checkbox" value="' + its.score + '" />'
  148. } else if (it.selectType == 21 && item.resultType == 2) {
  149. str += '<label><input class="radio_type" name="scale' + it.parentId + '" type="radio" value="' + its.result + '" data_obj="' + its.result + '"/>'
  150. } else if (it.selectType == 22 && item.resultType == 2) {
  151. str += '<label><input class="radio_type" name="scale' + it.parentId + '" type="checkbox" value="' + its.result + '" data_obj="' + its.result + '"/>'
  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=${recommend} />` : ``}</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 += '<p class="score"></p>'
  178. str += '<button class="but">结果</button></div>'
  179. str += '<div class="result"><div class="result_box"><p class="hel">?</p><span>结果:</span><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=${printing} 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. addLinkClickEvent(contentWrapClassName);
  198. adjustHeight();
  199. adjustWidth()
  200. getcheck()
  201. getResult(pushInfo, textType)
  202. copy(name)
  203. getprinting()
  204. }
  205. function getprinting() {
  206. $('.printing').click(function () {
  207. $('.foot').hide()
  208. $('.hel').hide()
  209. $('#Print').css({
  210. 'height': 'auto', //高度自动
  211. }).jqprint();
  212. $('.foot').show()
  213. $('.hel').show()
  214. })
  215. }
  216. function getcheck() {
  217. $('input:radio').click(function () {
  218. const domName = $(this).attr('name');
  219. const $radio = $(this);
  220. const id = $(this).parents('.contentList').data("id");
  221. if ($radio.data('waschecked') == true) {
  222. $radio.prop('checked', false);
  223. $("input:radio[name='" + domName + "']").data('waschecked', false);
  224. // $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", false);
  225. } else {
  226. $radio.prop('checked', true);
  227. $("input:radio[name='" + domName + "']").data('waschecked', false);
  228. $radio.data('waschecked', true);
  229. // $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", true);
  230. }
  231. });
  232. // $('input:checkbox').click(function () {
  233. // const domName = $(this).attr('name');
  234. // const $radio = $(this);
  235. // const id = $(this).parents('.contentList').data("id");
  236. // if ($radio.data('waschecked') == true) {
  237. // $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", false);
  238. // } else {
  239. // $radio.parents('.contentList').siblings(".contentList[data-id='" + id + "']").find('.radio_type').attr("disabled", true);
  240. // }
  241. // });
  242. }
  243. function copy(name) {
  244. $(".copy").click(function () {
  245. var texts = document.getElementById("result_title").innerText;
  246. if (texts == '') {
  247. return
  248. }
  249. var inputs = document.getElementById("inputs");
  250. inputs.value = name + '量表结果为:' + texts; // 修改文本框的内容(赋值内容)
  251. console.log(inputs.value)
  252. inputs.select(); // 选中文本
  253. document.execCommand("copy"); // 执行浏览器复制命令
  254. Toast('复制成功', 500)
  255. setTimeout(() => {
  256. window.close()
  257. }, 500)
  258. })
  259. }
  260. function getResult(pushInfo, textType) {
  261. $(".but").click(function () {
  262. let arr = [];
  263. let num = 0
  264. let result
  265. let key = false
  266. $(".contentList").each(function (i) {
  267. if ($(this).find('input[type="radio"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  268. $(this).find(".item-title").addClass('chColor');
  269. } else {
  270. $(this).find(".item-title").removeClass('chColor');
  271. }
  272. if ($(this).find('input[type="checkbox"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
  273. $(this).find(".item-titles").addClass('chColor');
  274. } else {
  275. $(this).find(".item-titles").removeClass('chColor');
  276. }
  277. });
  278. if (!$(".contentList").find(".item-title").hasClass('chColor') && !$(".contentList").find(".item-titles").hasClass('chColor')) {
  279. $('input[type="radio"]:checked').each(function () {
  280. if (Number($(this).val())) {
  281. num += parseFloat($(this).val())
  282. } else {
  283. arr.push($(this).attr("data_obj"))
  284. }
  285. });
  286. $('input[type="checkbox"]:checkbox:checked').each(function () {
  287. if (Number($(this).val())) {
  288. num += parseFloat($(this).val())
  289. } else {
  290. arr.push($(this).attr("data_obj"))
  291. }
  292. });
  293. tmp = arr.join(",");
  294. if (pushInfo.length > 0) {
  295. for (var i = 0; i < pushInfo.length; i++) {
  296. if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
  297. if (tmp) {
  298. result = pushInfo[i].result + '(' + num + ')' + ';' + tmp
  299. } else {
  300. result = pushInfo[i].result + '(' + num + ')'
  301. }
  302. }
  303. }
  304. } else {
  305. result = tmp
  306. }
  307. $(".result_title").attr({
  308. "title": result
  309. });
  310. $(".hel").attr({
  311. "title": result
  312. });
  313. $(".result_title").html(result);
  314. if ($.inArray(13, textType) > 0) {
  315. $(".score").html('总分:' + num + '分');
  316. }
  317. $(".score").css('display', 'block')
  318. $(".result").css('display', 'block')
  319. $(".foot").css('display', 'block')
  320. } else {
  321. Toast('温馨提示:必填选项不能为空~', 500)
  322. }
  323. })
  324. $(".printing").hover(
  325. function () {
  326. $(".slideImg").attr("src", printing2);
  327. }, function () {
  328. $(".slideImg").attr("src", printing);
  329. });
  330. }
  331. function addLinkClickEvent(contentWrapClassName) {
  332. $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
  333. $(`.${contentWrapClassName} .anchors li>a`).on("click", function () {
  334. const that = this
  335. setTimeout(function () {
  336. $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
  337. $(that).parent().addClass("active");
  338. }, 20)
  339. });
  340. }
  341. function renderTab(detailList, scale) {
  342. if (detailList['静态知识']) {
  343. $(".tabList").append(`<span class="tab" data-module="staticKnowledge" data-title="` + showName + `">静态知识</span>`)
  344. }
  345. if (detailList['临床路径']) {
  346. $(".tabList").append(`<span class="tab" data-module="clinicalPathway" data-title="` + clinicalPathwayName + `">临床路径</span>`)
  347. //$(".tabBox .title").html(clinicalPathwayName);
  348. }
  349. if (detailList['注意事项']) {
  350. $(".tabList").append(`<span class="tab" data-module="notice" data-title="` + noticeName + `">注意事项</span>`)
  351. //$(".tabBox .title").html(noticeName);
  352. }
  353. if (scale) {
  354. $(".tabList").append(`<span class="tab" data-module="scale" data-title="` + showName + `">评估内容</span>`)
  355. //$(".tabBox .title").html(noticeName);
  356. }
  357. let defaultModuleName
  358. if (getUrlArgObject('page') && getUrlArgObject('page') == 1 && scale) {
  359. $(".tabList .tab").eq(1).addClass("activeTab")
  360. defaultModuleName = $(".tabList .tab").eq(1).attr("data-module")
  361. } else {
  362. $(".tabList .tab").eq(0).addClass("activeTab")
  363. defaultModuleName = $(".tabList .tab").eq(0).attr("data-module")
  364. }
  365. $(`.${defaultModuleName}`).css("display", "block")
  366. bindTabClick()
  367. }
  368. function bindTabClick() {
  369. $(".tabList .tab").on("click", function () {
  370. const moduleName = $(this).attr("data-module")
  371. const display = $(`.${moduleName}`).css("display")
  372. $(".tabBox .title").html($(this).attr('data-title'));
  373. if (display == "none") {
  374. $(".activeTab").removeClass("activeTab")
  375. $(this).addClass("activeTab")
  376. $(".container").css("display", "none")
  377. $(`.${moduleName}`).css("display", "block")
  378. $(`.${moduleName} .infos`).scrollTop(0)
  379. }
  380. })
  381. $("#openWin").on("click", function () {
  382. const type = getUrlArgObject('type');
  383. const name = getUrlArgObject('name');
  384. const position = getUrlArgObject('position');
  385. openNewWin("staticInfo.html?name=" + encodeURIComponent(name) + "&position=" + encodeURIComponent(position) + "&type=" + encodeURIComponent(type));
  386. })
  387. }
  388. function adjustHeight() {
  389. var ht = window.innerHeight || document.documentElement.clientHeight;
  390. $(".content,.content .infos").height(ht - 162 + "px");
  391. }
  392. function adjustWidth() {
  393. var wt = window.innerWidth || document.documentElement.clientWidth;
  394. $(".titleH2").width(wt - 0.2 * wt - 33 - 200 - 17 - 40 - 15 + 'px')
  395. //$("pre").width(wt- 0.2*wt - 240 + 'px')
  396. }
  397. $(window).on('resize', function () {
  398. adjustHeight()
  399. adjustWidth()
  400. })
  401. //如果是子窗口,隐藏网页查看按钮
  402. if (window.opener) {
  403. $("#openWin").hide();
  404. }