jiuzhenxiangqing.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $time = $('#time'),
  6. $type = $('#type'),
  7. $deptDoctor = $('#dept_doctor'),
  8. $org = $('#org'),
  9. $diagnosis = $('#diagnosis');
  10. var gallery = null;
  11. // 获取基本信息(包括userAgent、上个页面传递的数据)
  12. var getBaseInfo = function() {
  13. // 登录的相关信息
  14. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  15. return {
  16. userAgent: userAgent,
  17. eventInfo: baseEnv.webview.eventInfo,
  18. patiInfo: baseEnv.webview.patiInfo
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. var env = {
  24. webview: plus&&plus.webview.currentWebview()
  25. };
  26. return Promise.resolve().then(function(res) {
  27. return env;
  28. });
  29. },
  30. getDetailPromise = function() {
  31. return getReqPromise('doctor/archives/event/detail',{event:baseInfo.eventInfo.id},'GET')
  32. .then(function(res) {
  33. var data = {},
  34. imgsMap = {};
  35. if(res.status==200) {
  36. data = res.data;
  37. var eventName = getEventTypeName(data.eventType);
  38. $type.text(eventName);
  39. showDeptDoctor(data.deptName,data.doctorName);
  40. $time.text(data.eventDate.substr(0,10));
  41. if(data.orgName) {
  42. $org.text(data.orgName);
  43. $org.parent().show();
  44. }
  45. $diagnosis.text(data.dianosis);
  46. imgsMap = _.groupBy(data.eventImg, function(v) {
  47. return v.imgType;
  48. });
  49. _.mapObject(imgsMap,function(val, key) {
  50. var catalog = key? key: "未分类";
  51. var $wrap = $('div[data-type="'+catalog+'"]'),
  52. $ul = $wrap.find('.img-list').eq(0);
  53. html = template('li_tmpl',{list: val});
  54. $ul.html(html);
  55. $wrap.show();
  56. });
  57. }
  58. })
  59. .then(function() {
  60. var $imgs = $('img.preview-img');
  61. $imgs.on('click',function() {
  62. var idx = $imgs.index(this);
  63. var length = $imgs.length;
  64. updateCatalogNameTip(this);
  65. $('#page_counter').text('('+(idx+1)+'/'+length+')')
  66. previewImage(idx);
  67. gallery.listen('afterChange', function() {
  68. var imgIdx = gallery.getCurrentIndex();
  69. var $img = $imgs.eq(imgIdx);
  70. updateCatalogNameTip($img);
  71. $('#page_counter').text('('+(imgIdx+1)+'/'+length+')')
  72. updateCatalog($img);
  73. });
  74. updateCatalog(this);
  75. });
  76. })
  77. };
  78. function getEventTypeName(type) {
  79. if(type=="1") {
  80. return "门诊";
  81. } else if(type=="2"){
  82. return "住院";
  83. } else if(type == "3"){
  84. return "体检";
  85. }
  86. }
  87. function showDeptDoctor(dept,doctor) {
  88. if(!dept&&!doctor) {
  89. return ;
  90. } else if(dept&& doctor) {
  91. $deptDoctor.html('<label>科室/医生:</label>'+dept+'/'+doctor);
  92. } else if(dept) {
  93. $deptDoctor.html('<label>科室:</label>'+dept);
  94. } else if(doctor) {
  95. $deptDoctor.html('<label>医生:</label>'+doctor);
  96. }
  97. $deptDoctor.show();
  98. }
  99. function updateCatalogNameTip(img) {
  100. var catalog = $(img).attr('data-catalog')||"";
  101. var subCatalog = $(img).attr('data-sub-catalog')||"";
  102. var catalogName = catalog;
  103. if(subCatalog) {
  104. catalogName = catalogName + '_' + subCatalog;
  105. }
  106. $('#catalog_name').text(catalogName);
  107. }
  108. function updateCatalog(img) {
  109. var catalog = $(img).attr('data-catalog')||"";
  110. var subCatalog = $(img).attr('data-sub-catalog')||"";
  111. $('.img-catalog').find('a.c-btn-icon[data-type="'+catalog+'"]').trigger('click',[false]);
  112. $('.sub-catalog').find('a.c-btn-icon[data-type="'+subCatalog+'"]').trigger('click',[false]);
  113. }
  114. function previewImage(sid) {
  115. var pswpElement = document.querySelectorAll('.pswp')[0];
  116. var w = $(window).width(), h = $(window).height();
  117. var items = _.map($('img.preview-img'),function(img) {
  118. return {
  119. src: $(img).attr('src'),
  120. w: w,
  121. h: h,
  122. initialPosition: { x: 0, y:0 }
  123. }
  124. });
  125. var options = {
  126. // optionName: 'option value'
  127. // for example:
  128. index: sid||0 // start at first slide
  129. };
  130. options.mainClass = 'pswp--minimal--dark';
  131. options.barsSize = {top:0,bottom:0};
  132. options.captionEl = false;
  133. options.fullscreenEl = false;
  134. options.shareEl = false;
  135. options.bgOpacity = 0.85;
  136. options.tapToToggleControls = false;
  137. options.pinchToClose = false;
  138. options.clickToCloseNonZoomable = false;
  139. options.tapToClose = true;
  140. options.errorMsg = '<div class="pswp__error-msg">对不起,该图片加载失败</div>';
  141. // Initializes and opens PhotoSwipe
  142. gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
  143. gallery.init();
  144. }
  145. // 页面业务处理流程开始
  146. new Promise(function(resolve, reject) {
  147. mui.plusReady(function() {
  148. // plus已经准备好,可以往下执行
  149. resolve(true);
  150. });
  151. }).then(function() {
  152. // 获取基础环境信息
  153. return getBaseEnvPromise().then(function(env) {
  154. baseEnv = env;
  155. // 获取登录医生信息
  156. baseInfo = getBaseInfo();
  157. })
  158. })
  159. .then(function() {
  160. return getDetailPromise();
  161. })
  162. .catch(function(e) { console && console.error(e) });
  163. template.helper("setPhoto", function(p) {
  164. return getImgUrl(p);
  165. });