staticInfo.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. };
  33. showName = param.name
  34. $(".tabBox .title").html(showName);
  35. post(config.information, param).then((res) => {
  36. const data = res.data.data
  37. // const data = dataaaa.data
  38. document.title = showName
  39. var str = '';
  40. var anchors = '';
  41. if (!data) {
  42. $(".title").html("暂时没有数据");
  43. $(".anchors").css("display", "none");
  44. return;
  45. }
  46. var detailList = data.details
  47. var scale = data.scale
  48. var staticKnowList = detailList['静态知识']
  49. var noticeInfo = detailList['注意事项']
  50. var clinicalPathwayInfo = detailList['临床路径']
  51. var scaleInfo = data.scale ? data.scale.scaleDetails : ''
  52. var name = data.name
  53. noticeName = data.noticeName || "注意事项"
  54. clinicalPathwayName = data.clinicalPathwayName || "临床路径"
  55. renderTab(detailList, scale)
  56. staticKnowList && renderContent(staticKnowList, 'staticKnowledge')
  57. noticeInfo && renderContent(noticeInfo, 'notice')
  58. clinicalPathwayInfo && renderContent(clinicalPathwayInfo, 'clinicalPathway')
  59. scaleInfo && renderContentscale(scaleInfo, 'scale', name)
  60. $('.content img').bind('contextmenu', function () {
  61. return false
  62. })
  63. })
  64. }
  65. getInfomation();
  66. function renderContent(list, contentWrapClassName) {
  67. for (var i = 0; i < list.length; i++) {
  68. var item = list[i];
  69. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  70. anchors = '<li><i></i><a href="#' + contentWrapClassName + i +
  71. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  72. str = '<div class="infoBox"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  73. '">'
  74. /*if (getUrlArgObject('type') == 8) {
  75. str += '【' + item.title + '】'
  76. } else {*/
  77. str += item.title
  78. /*}*/
  79. str += '</h2></div>' +
  80. '<div class="contentWrapper"><pre>' + item.content + '</pre><div></div>';
  81. str = `<div class="infoWrapper">${str}</div>`
  82. $(`.${contentWrapClassName} .infos`).append(str);
  83. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  84. }
  85. function addScrollEvent() {
  86. var scrollTop = $(`.${contentWrapClassName} .infos`).scrollTop()
  87. var divHeight = 0;
  88. for (var i = 0; i < list.length; i++) {
  89. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  90. if (divHeight > scrollTop) {
  91. var anchor = 2 * i;
  92. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  93. return;
  94. }
  95. }
  96. }
  97. $(`.${contentWrapClassName} .infos`).scroll(throttle(addScrollEvent, 200));
  98. addLinkClickEvent(contentWrapClassName);
  99. adjustHeight();
  100. adjustWidth()
  101. }
  102. function renderContentscale(list, contentWrapClassName, name) {
  103. var pushInfo=[]
  104. anchors = '<li><i></i><a href="#' + contentWrapClassName +
  105. '">' + name + '</a></li><li class="anchor-line"></li>';
  106. str = '<p class="scaletitle">' + name + '</p>'
  107. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  108. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  109. for (var i = 0; i < list[0].detailList.length; i++) {
  110. var item = list[0].detailList[i];
  111. if (item.textType == 11) {
  112. item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  113. str = '<div class="infoBox scaleBox" data-id="' + item.id + '"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
  114. '">'
  115. str += item.content
  116. str += '</h2></div>'
  117. str = `<div class="infoWrapper">${str}</div>`
  118. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  119. for (var j = 0; j < item.subList.length; j++) {
  120. var items = item.subList[j];
  121. for (var k = 0; k < items.detailList.length; k++) {
  122. var it = items.detailList[k];
  123. it.content = it.content && it.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  124. str = '<div class="contentList" data-id="' + it.parentId + '"><div class="item-list">';
  125. str += '<p class="item-title">' + it.content + '</p>'
  126. str += '<div class="item-content" data-id="' + it.id + '">'
  127. str += '</div></div></div>'
  128. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
  129. for (var l = 0; l < it.subList[0].detailList.length; l++) {
  130. var its = it.subList[0].detailList[l];
  131. console.log(its.parentId)
  132. its.content = its.content && its.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  133. str = '<div class="radio" name="scale' + its.parentId + '" value="' + its.score + '">';
  134. str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.score + '" />'
  135. str += its.content
  136. str += '<span class="num">' + '(' + its.score + ')' + '</span>'
  137. str += '</label>'
  138. str += `${item.match ? `<img class="recommend" src=${recommend} />` : `` }</div>`
  139. $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "] .contentList .item-content[data-id=" + its.parentId + "]").append(str);
  140. }
  141. }
  142. }
  143. }
  144. if (item.textType == 13){
  145. for (var m = 0; m < item.subList[0].detailList[0].subList[0].detailList.length; m++ ){
  146. var itl = item.subList[0].detailList[0].subList[0].detailList[m]
  147. let arr = {
  148. content: JSON.parse(itl.content),
  149. result: itl.result,
  150. pushInfo: itl.pushInfo
  151. }
  152. pushInfo.push(arr)
  153. }
  154. }
  155. }
  156. str = '<div class="scalebot">'
  157. str += '<p class="score"></p>'
  158. str += '<button class="but">结果</button></div>'
  159. 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>'
  160. str += `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  161. $(`.${contentWrapClassName} .infos .infos-box`).append(str);
  162. // str = `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
  163. // $(`.${contentWrapClassName} .infos`).after(str);
  164. function addScrollEvent() {
  165. var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
  166. var divHeight = 0;
  167. for (var i = 0; i < list.length; i++) {
  168. divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
  169. if (divHeight > scrollTop) {
  170. var anchor = 2 * i;
  171. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  172. return;
  173. }
  174. }
  175. }
  176. $(`.${contentWrapClassName} .infos .infos-box`).scroll(throttle(addScrollEvent, 200));
  177. addLinkClickEvent(contentWrapClassName);
  178. adjustHeight();
  179. adjustWidth()
  180. getcheck()
  181. getResult(pushInfo)
  182. copy()
  183. getprinting()
  184. }
  185. function getprinting() {
  186. $('.printing').click(function () {
  187. $('.foot').hide()
  188. $('.hel').hide()
  189. $('#Print').css({
  190. 'height': 'auto', //高度自动
  191. }).jqprint();
  192. $('.foot').show()
  193. $('.hel').show()
  194. })
  195. }
  196. function getcheck() {
  197. $('input:radio').click(function () {
  198. var domName = $(this).attr('name');
  199. var $radio = $(this);
  200. if ($radio.data('waschecked') == true) {
  201. $radio.prop('checked', false);
  202. $("input:radio[name='" + domName + "']").data('waschecked', false);
  203. } else {
  204. $radio.prop('checked', true);
  205. $("input:radio[name='" + domName + "']").data('waschecked', false);
  206. $radio.data('waschecked', true);
  207. }
  208. console.log("选中状态:", $(this).prop("checked"));
  209. console.log($("input:radio[name='" + domName + "']:checked").val());
  210. });
  211. }
  212. function copy() {
  213. $(".copy").click(function () {
  214. var texts = document.getElementById("result_title").innerText;
  215. var inputs = document.getElementById("inputs");
  216. inputs.value = texts; // 修改文本框的内容(赋值内容)
  217. inputs.select(); // 选中文本
  218. document.execCommand("copy"); // 执行浏览器复制命令
  219. Toast('复制成功', 500)
  220. setTimeout(()=>{
  221. window.close()
  222. },500)
  223. })
  224. }
  225. function getResult(pushInfo) {
  226. $(".but").click(function () {
  227. let arr = [];
  228. let num = 0
  229. $(".contentList").each(function (i) {
  230. if (Number(parseFloat($(this).find('input[type="radio"]:checked').val()))) {
  231. num += parseFloat($(this).find('input[type="radio"]:checked').val())
  232. }
  233. })
  234. for (var i = 0; i < pushInfo.length; i++) {
  235. console.log(pushInfo[i])
  236. if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
  237. $(".result_title").attr({
  238. "title": pushInfo[i].result
  239. });
  240. $(".hel").attr({
  241. "title": pushInfo[i].pushInfo
  242. });
  243. $(".result_title").html(pushInfo[i].result);
  244. }
  245. }
  246. $(".score").html('总分:' + num + '分');
  247. $(".score").css('display', 'block')
  248. $(".result").css('display', 'block')
  249. $(".foot").css('display', 'block')
  250. })
  251. $(".printing").hover(
  252. function () {
  253. $(".slideImg").attr("src", printing2);
  254. }, function () {
  255. $(".slideImg").attr("src", printing);
  256. });
  257. }
  258. function addLinkClickEvent(contentWrapClassName) {
  259. $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
  260. $(`.${contentWrapClassName} .anchors li>a`).on("click", function () {
  261. const that = this
  262. setTimeout(function () {
  263. $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
  264. $(that).parent().addClass("active");
  265. }, 20)
  266. });
  267. }
  268. function renderTab(detailList, scale) {
  269. if (detailList['静态知识']) {
  270. $(".tabList").append(`<span class="tab" data-module="staticKnowledge" data-title="` + showName + `">静态知识</span>`)
  271. }
  272. if (detailList['临床路径']) {
  273. $(".tabList").append(`<span class="tab" data-module="clinicalPathway" data-title="` + clinicalPathwayName + `">临床路径</span>`)
  274. //$(".tabBox .title").html(clinicalPathwayName);
  275. }
  276. if (detailList['注意事项']) {
  277. $(".tabList").append(`<span class="tab" data-module="notice" data-title="` + noticeName + `">注意事项</span>`)
  278. //$(".tabBox .title").html(noticeName);
  279. }
  280. if (scale) {
  281. $(".tabList").append(`<span class="tab" data-module="scale" data-title="` + showName + `">评估内容</span>`)
  282. //$(".tabBox .title").html(noticeName);
  283. }
  284. let defaultModuleName
  285. if (getUrlArgObject('page') && getUrlArgObject('page') == 1 && scale){
  286. $(".tabList .tab").eq(1).addClass("activeTab")
  287. defaultModuleName = $(".tabList .tab").eq(1).attr("data-module")
  288. }else{
  289. $(".tabList .tab").eq(0).addClass("activeTab")
  290. defaultModuleName = $(".tabList .tab").eq(0).attr("data-module")
  291. }
  292. $(`.${defaultModuleName}`).css("display", "block")
  293. bindTabClick()
  294. }
  295. function bindTabClick() {
  296. $(".tabList .tab").on("click", function () {
  297. const moduleName = $(this).attr("data-module")
  298. const display = $(`.${moduleName}`).css("display")
  299. $(".tabBox .title").html($(this).attr('data-title'));
  300. if (display == "none") {
  301. $(".activeTab").removeClass("activeTab")
  302. $(this).addClass("activeTab")
  303. $(".container").css("display", "none")
  304. $(`.${moduleName}`).css("display", "block")
  305. $(`.${moduleName} .infos`).scrollTop(0)
  306. }
  307. })
  308. $("#openWin").on("click", function () {
  309. const type = getUrlArgObject('type');
  310. const name = getUrlArgObject('name');
  311. const position = getUrlArgObject('position');
  312. openNewWin("staticInfo.html?name=" + encodeURIComponent(name) + "&position=" + encodeURIComponent(position) + "&type=" + encodeURIComponent(type));
  313. })
  314. }
  315. function adjustHeight() {
  316. var ht = window.innerHeight || document.documentElement.clientHeight;
  317. $(".content,.content .infos").height(ht - 162 + "px");
  318. }
  319. function adjustWidth() {
  320. var wt = window.innerWidth || document.documentElement.clientWidth;
  321. $(".titleH2").width(wt - 0.2 * wt - 33 - 200 - 17 - 40 - 15 + 'px')
  322. //$("pre").width(wt- 0.2*wt - 240 + 'px')
  323. }
  324. $(window).on('resize', function () {
  325. adjustHeight()
  326. adjustWidth()
  327. })
  328. //如果是子窗口,隐藏网页查看按钮
  329. if (window.opener) {
  330. $("#openWin").hide();
  331. }