information.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/information.less')
  10. const {
  11. post,
  12. throttle,
  13. imageUrlPrefix,
  14. config,
  15. getUrlArgObject,
  16. openNewWin
  17. } = require('./promise.js');
  18. const $ = require("jquery");
  19. let showName,noticeName,clinicalPathwayName
  20. function getInfomation() {
  21. var param = {
  22. "type": getUrlArgObject('type'),
  23. "name": getUrlArgObject('name'),
  24. "position": getUrlArgObject('position'),
  25. "contentTypes":[1,2,3]
  26. };
  27. const uname = getUrlArgObject('uname')
  28. showName = param.name
  29. // if (param.type == 5 || param.type == 51) {
  30. // param.type = 12;
  31. // param.name = uname;
  32. // }
  33. post(config.information, param).then((res) => {
  34. const data = res.data.data
  35. document.title = showName
  36. var str = '';
  37. var anchors = '';
  38. if (!data) {
  39. $("h1").html("暂时没有数据");
  40. $(".anchors").css("display", "none");
  41. return;
  42. }
  43. var detailList = data.details
  44. var staticKnowList = detailList['静态知识']
  45. var noticeInfo = detailList['注意事项']
  46. var clinicalPathwayInfo = detailList['临床路径']
  47. noticeName = data.noticeName || "注意事项"
  48. clinicalPathwayName = data.clinicalPathwayName || "临床路径"
  49. // $("h1").css({
  50. // "color": "#267FD7",
  51. // "borderBottom": "4px solid #E9E9E9",
  52. // "padding": "0px 60px 50px 0px"
  53. // });
  54. renderTab(detailList)
  55. staticKnowList&&renderContent(staticKnowList,'staticKnowledge')
  56. noticeInfo&&renderContent(noticeInfo,'notice')
  57. clinicalPathwayInfo&&renderContent(clinicalPathwayInfo,'clinicalPathway')
  58. $('.content img').bind('contextmenu', function(){
  59. return false
  60. })
  61. })
  62. }
  63. getInfomation();
  64. function renderContent(list, contentWrapClassName){
  65. for (var i = 0; i < list.length; i++) {
  66. var item = list[i];
  67. item.content = item.content&&item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  68. anchors = '<li><i></i><a href="#' + contentWrapClassName+i +
  69. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  70. str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> </span></div> <h2 class="titleH2" id="' + contentWrapClassName+i +
  71. '">'
  72. if (getUrlArgObject('type') == 8) {
  73. str += '【' + item.title + '】'
  74. } else {
  75. str += item.title
  76. }
  77. str += '</h2></div>' +
  78. '<div class="contentWrapper"><pre>' + item.content + '</pre><div></div>';
  79. str = `<div class="infoWrapper">${str}</div>`
  80. $(`.${contentWrapClassName} .infos`).append(str);
  81. $(`.${contentWrapClassName} .anchors ul`).append(anchors);
  82. }
  83. function addScrollEvent() {
  84. var scrollTop = $(`.${contentWrapClassName} .infos`).scrollTop()
  85. var divHeight = 0;
  86. for (var i = 0; i < list.length; i++) {
  87. divHeight = divHeight + parseInt($('#'+contentWrapClassName+i).css('height')) + parseInt($('#'+contentWrapClassName+i).parent().next().css('height')) + 20
  88. if (divHeight > scrollTop) {
  89. var anchor = 2 * i;
  90. $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
  91. return;
  92. }
  93. }
  94. }
  95. $(`.${contentWrapClassName} .infos`).scroll(throttle(addScrollEvent, 200));
  96. addLinkClickEvent(contentWrapClassName);
  97. adjustHeight();
  98. adjustWidth()
  99. }
  100. function addLinkClickEvent(contentWrapClassName) {
  101. $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
  102. $(`.${contentWrapClassName} .anchors li>a`).on("click", function () {
  103. const that = this
  104. setTimeout(function(){
  105. $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
  106. $(that).parent().addClass("active");
  107. },20)
  108. });
  109. }
  110. function renderTab(detailList){
  111. if(detailList['静态知识']){
  112. $(".tabList").append(`<span class="tab" data-module="staticKnowledge">静态知识</span>`)
  113. $(".staticKnowledge h1").html(showName);
  114. }
  115. if(detailList['临床路径']){
  116. $(".tabList").append(`<span class="tab" data-module="clinicalPathway">临床路径</span>`)
  117. $(".clinicalPathway h1").html(clinicalPathwayName);
  118. }
  119. if(detailList['注意事项']){
  120. $(".tabList").append(`<span class="tab" data-module="notice">注意事项</span>`)
  121. $(".notice h1").html(noticeName);
  122. }
  123. $(".tabList .tab").eq(0).addClass("activeTab")
  124. let defaultModuleName = $(".tabList .tab").eq(0).attr("data-module")
  125. $(`.${defaultModuleName}`).css("display","block")
  126. bindTabClick()
  127. }
  128. function bindTabClick(){
  129. $(".tabList .tab").on("click", function(){
  130. const moduleName = $(this).attr("data-module")
  131. const display = $(`.${moduleName}`).css("display")
  132. if(display == "none"){
  133. $(".activeTab").removeClass("activeTab")
  134. $(this).addClass("activeTab")
  135. $(".container").css("display","none")
  136. $(`.${moduleName}`).css("display","block")
  137. $(`.${moduleName} .infos`).scrollTop(0)
  138. }
  139. })
  140. $("#openWin").on("click",function(){
  141. const type= getUrlArgObject('type');
  142. const name= getUrlArgObject('name');
  143. const position= getUrlArgObject('position');
  144. openNewWin("information.html?name="+encodeURIComponent(name)+"&position="+encodeURIComponent(position)+"&type="+encodeURIComponent(type));
  145. })
  146. }
  147. function adjustHeight() {
  148. var ht = window.innerHeight || document.documentElement.clientHeight;
  149. $(".content").height(ht - 90 + "px");
  150. }
  151. function adjustWidth() {
  152. var wt = window.innerWidth || document.documentElement.clientWidth;
  153. $(".titleH2").width(wt- 0.2*wt -33 - 200 - 17 - 40 -15 + 'px')
  154. $("pre").width(wt- 0.2*wt - 200 + 'px')
  155. }
  156. $(window).on('resize', function(){
  157. adjustHeight()
  158. adjustWidth()
  159. })
  160. //如果是子窗口,隐藏网页查看按钮
  161. if(window.opener){
  162. $("#openWin").hide();
  163. }