jiuzhenxiangqing.js 5.2 KB

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