staticInfo.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. console.log(it)
  133. if (it.selectType == 21) {
  134. str += '<p class="item-title">' + it.content + '</p>'
  135. } else if (it.selectType == 22) {
  136. str += '<p class="item-titles">' + it.content + '</p>'
  137. }
  138. str += '<div class="item-content" data-id="' + it.id + '">'
  139. str += '</div></div></div>'
  140. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
  141. for (var l = 0; l < it.subList[0].detailList.length; l++) {
  142. var its = it.subList[0].detailList[l];
  143. its.content = its.content && its.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  144. str = '<div class="radio" name="scale' + its.parentId + '" value="' + its.score + '">';
  145. if (it.selectType == 21 && item.resultType == 1) {
  146. str += '<label><input class="radio_type" type="radio" name="scale' + its.parentId + '" value="' + its.score + '"/>'
  147. } else if (it.selectType == 22 && item.resultType == 1) {
  148. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + its.score + '" />'
  149. } else if (it.selectType == 21 && item.resultType == 2) {
  150. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.result + '" data_obj="' + its.result + '"/>'
  151. } else if (it.selectType == 22 && item.resultType == 2) {
  152. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + its.result + '" data_obj="' + its.result + '"/>'
  153. }
  154. str += its.content
  155. if (item.resultType == 1) {
  156. str += '<span class="num">' + '(' + its.score + ')' + '</span>'
  157. }
  158. str += '</label>'
  159. str += `${its.match == 1 ? `<img class="recommend" src=${recommend} />` : ``}</div>`
  160. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "] .contentList .item-content[data-id=" + its.parentId + "]").append(str);
  161. }
  162. }
  163. }
  164. }
  165. if (item.textType == 13) {
  166. for (var m = 0; m < item.subList[0].detailList[0].subList[0].detailList.length; m++) {
  167. var itl = item.subList[0].detailList[0].subList[0].detailList[m]
  168. let arr = {
  169. content: JSON.parse(itl.content),
  170. result: itl.result,
  171. pushInfo: itl.pushInfo
  172. }
  173. pushInfo.push(arr)
  174. }
  175. }
  176. }
  177. str = '<div class="scalebot">'
  178. str += '<p class="score"></p>'
  179. str += '<button class="but">结果</button></div>'
  180. 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>'
  181. str += `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  182. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  183. // str = `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  184. // $(`.${contentWrapClassName} .infos`).after(str);
  185. function addScrollEvent() {
  186. var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
  187. var divHeight = 0;
  188. for (var i = 0; i < list.length; i++) {
  189. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  190. if (divHeight > scrollTop) {
  191. var anchor = 2 * i;
  192. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  193. return;
  194. }
  195. }
  196. }
  197. $(`.${contentWrapClassName} .infos .infos-box`).scroll(throttle(addScrollEvent, 200));
  198. addLinkClickEvent(contentWrapClassName);
  199. adjustHeight();
  200. adjustWidth()
  201. getcheck()
  202. getResult(pushInfo, textType)
  203. copy(name)
  204. getprinting()
  205. }
  206. function getprinting() {
  207. $('.printing').click(function () {
  208. $('.foot').hide()
  209. $('.hel').hide()
  210. $('#Print').css({
  211. 'height': 'auto', //高度自动
  212. }).jqprint();
  213. $('.foot').show()
  214. $('.hel').show()
  215. })
  216. }
  217. function getcheck() {
  218. $('input:radio').click(function () {
  219. const domName = $(this).attr('name');
  220. const $radio = $(this);
  221. if ($radio.data('waschecked') == true) {
  222. $radio.prop('checked', false);
  223. $("input:radio[name='" + domName + "']").data('waschecked', false);
  224. } else {
  225. $radio.prop('checked', true);
  226. $("input:radio[name='" + domName + "']").data('waschecked', false);
  227. $radio.data('waschecked', true);
  228. }
  229. });
  230. $('input:checkbox').click(function () {
  231. const domName = $(this).attr('name');
  232. const $radio = $(this);
  233. if ($radio.data('waschecked') == true) {
  234. $radio.prop('checked', false);
  235. $("input:checkbox[name='" + domName + "']").data('waschecked', false);
  236. } else {
  237. $radio.prop('checked', true);
  238. $("input:checkbox[name='" + domName + "']").data('waschecked', false);
  239. $radio.data('waschecked', 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) {
  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) {
  273. $(this).find(".item-titles").addClass('chColor');
  274. } else {
  275. $(this).find(".item-titles").removeClass('chColor');
  276. }
  277. });
  278. console.log(!$(".contentList").find(".item-title").hasClass('chColor'))
  279. if (!$(".contentList").find(".item-title").hasClass('chColor')) {
  280. $('input[type="radio"]:checked').each(function () {
  281. if (Number($(this).val())) {
  282. num += parseFloat($(this).val())
  283. } else {
  284. arr.push($(this).attr("data_obj"))
  285. }
  286. });
  287. $('input[type="checkbox"]:checkbox:checked').each(function () {
  288. if (Number($(this).val())) {
  289. num += parseFloat($(this).val())
  290. } else {
  291. arr.push($(this).attr("data_obj"))
  292. }
  293. });
  294. tmp = arr.join(",");
  295. if (pushInfo.length > 0) {
  296. for (var i = 0; i < pushInfo.length; i++) {
  297. if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
  298. if (tmp) {
  299. result = pushInfo[i].result + ';' + tmp
  300. } else {
  301. result = pushInfo[i].result
  302. }
  303. }
  304. }
  305. } else {
  306. result = tmp
  307. }
  308. $(".result_title").attr({
  309. "title": result
  310. });
  311. $(".hel").attr({
  312. "title": result
  313. });
  314. $(".result_title").html(result +'('+ num +')');
  315. if ($.inArray(13, textType)>0){
  316. $(".score").html('总分:' + num + '分');
  317. }
  318. $(".score").css('display', 'block')
  319. $(".result").css('display', 'block')
  320. $(".foot").css('display', 'block')
  321. } else {
  322. Toast('温馨提示:必填选项不能为空~', 500)
  323. }
  324. })
  325. $(".printing").hover(
  326. function () {
  327. $(".slideImg").attr("src", printing2);
  328. }, function () {
  329. $(".slideImg").attr("src", printing);
  330. });
  331. }
  332. function addLinkClickEvent(contentWrapClassName) {
  333. $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
  334. $(`.${contentWrapClassName} .anchors li>a`).on("click", function () {
  335. const that = this
  336. setTimeout(function () {
  337. $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
  338. $(that).parent().addClass("active");
  339. }, 20)
  340. });
  341. }
  342. function renderTab(detailList, scale) {
  343. if (detailList['静态知识']) {
  344. $(".tabList").append(`<span class="tab" data-module="staticKnowledge" data-title="` + showName + `">静态知识</span>`)
  345. }
  346. if (detailList['临床路径']) {
  347. $(".tabList").append(`<span class="tab" data-module="clinicalPathway" data-title="` + clinicalPathwayName + `">临床路径</span>`)
  348. //$(".tabBox .title").html(clinicalPathwayName);
  349. }
  350. if (detailList['注意事项']) {
  351. $(".tabList").append(`<span class="tab" data-module="notice" data-title="` + noticeName + `">注意事项</span>`)
  352. //$(".tabBox .title").html(noticeName);
  353. }
  354. if (scale) {
  355. $(".tabList").append(`<span class="tab" data-module="scale" data-title="` + showName + `">评估内容</span>`)
  356. //$(".tabBox .title").html(noticeName);
  357. }
  358. let defaultModuleName
  359. if (getUrlArgObject('page') && getUrlArgObject('page') == 1 && scale) {
  360. $(".tabList .tab").eq(1).addClass("activeTab")
  361. defaultModuleName = $(".tabList .tab").eq(1).attr("data-module")
  362. } else {
  363. $(".tabList .tab").eq(0).addClass("activeTab")
  364. defaultModuleName = $(".tabList .tab").eq(0).attr("data-module")
  365. }
  366. $(`.${defaultModuleName}`).css("display", "block")
  367. bindTabClick()
  368. }
  369. function bindTabClick() {
  370. $(".tabList .tab").on("click", function () {
  371. const moduleName = $(this).attr("data-module")
  372. const display = $(`.${moduleName}`).css("display")
  373. $(".tabBox .title").html($(this).attr('data-title'));
  374. if (display == "none") {
  375. $(".activeTab").removeClass("activeTab")
  376. $(this).addClass("activeTab")
  377. $(".container").css("display", "none")
  378. $(`.${moduleName}`).css("display", "block")
  379. $(`.${moduleName} .infos`).scrollTop(0)
  380. }
  381. })
  382. $("#openWin").on("click", function () {
  383. const type = getUrlArgObject('type');
  384. const name = getUrlArgObject('name');
  385. const position = getUrlArgObject('position');
  386. openNewWin("staticInfo.html?name=" + encodeURIComponent(name) + "&position=" + encodeURIComponent(position) + "&type=" + encodeURIComponent(type));
  387. })
  388. }
  389. function adjustHeight() {
  390. var ht = window.innerHeight || document.documentElement.clientHeight;
  391. $(".content,.content .infos").height(ht - 162 + "px");
  392. }
  393. function adjustWidth() {
  394. var wt = window.innerWidth || document.documentElement.clientWidth;
  395. $(".titleH2").width(wt - 0.2 * wt - 33 - 200 - 17 - 40 - 15 + 'px')
  396. //$("pre").width(wt- 0.2*wt - 240 + 'px')
  397. }
  398. $(window).on('resize', function () {
  399. adjustHeight()
  400. adjustWidth()
  401. })
  402. //如果是子窗口,隐藏网页查看按钮
  403. if (window.opener) {
  404. $("#openWin").hide();
  405. }