jiuzhenxiangqing.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. var d= dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var Requests = GetRequest(),
  3. event = Requests.event;
  4. var $time = $('#time'),
  5. $type = $('#type'),
  6. $deptDoctor = $('#dept_doctor'),
  7. $org = $('#org'),
  8. $diagnosis = $('#diagnosis');
  9. var gallery = null;
  10. // 修改页面标题
  11. function setPageTitle(name) {
  12. //动态修改title的值
  13. var $body = $('body');
  14. document.title = name+"详情";
  15. // hack在微信等webview中无法修改document.title的情况
  16. var $iframe = $('<iframe src="/favicon.ico"></iframe>');
  17. $iframe.on('load',function() {
  18. setTimeout(function() {
  19. $iframe.off('load').remove();
  20. }, 0);
  21. }).appendTo($body);
  22. }
  23. function getEventTypeName(type) {
  24. if(type=="1") {
  25. return "门诊";
  26. } else if(type=="2"){
  27. return "住院";
  28. } else if(type == "3"){
  29. return "体检";
  30. }
  31. }
  32. function showDeptDoctor(dept,doctor) {
  33. if(!dept&&!doctor) {
  34. return ;
  35. } else if(dept&& doctor) {
  36. $deptDoctor.html('<label>科室/医生:</label>'+dept+'/'+doctor);
  37. } else if(dept) {
  38. $deptDoctor.html('<label>科室:</label>'+dept);
  39. } else if(doctor) {
  40. $deptDoctor.html('<label>医生:</label>'+doctor);
  41. }
  42. $deptDoctor.show();
  43. }
  44. function updateCatalogNameTip(img) {
  45. var catalog = $(img).attr('data-catalog')||"";
  46. var subCatalog = $(img).attr('data-sub-catalog')||"";
  47. var catalogName = catalog;
  48. if(subCatalog) {
  49. catalogName = catalogName + '_' + subCatalog;
  50. }
  51. $('#catalog_name').text(catalogName);
  52. }
  53. function updateCatalog(img) {
  54. var catalog = $(img).attr('data-catalog')||"";
  55. var subCatalog = $(img).attr('data-sub-catalog')||"";
  56. $('.img-catalog').find('a.c-btn-icon[data-type="'+catalog+'"]').trigger('click',[false]);
  57. $('.sub-catalog').find('a.c-btn-icon[data-type="'+subCatalog+'"]').trigger('click',[false]);
  58. }
  59. function previewImage(sid) {
  60. var pswpElement = document.querySelectorAll('.pswp')[0];
  61. var w = $(window).width(), h = $(window).height();
  62. var items = _.map($('img.preview-img'),function(img) {
  63. return {
  64. src: getImgUrl($(img).attr('src')),
  65. w: w,
  66. h: h,
  67. initialPosition: { x: 0, y:0 }
  68. }
  69. });
  70. var options = {
  71. // optionName: 'option value'
  72. // for example:
  73. index: sid||0 // start at first slide
  74. };
  75. options.mainClass = 'pswp--minimal--dark';
  76. options.barsSize = {top:0,bottom:0};
  77. options.captionEl = false;
  78. options.fullscreenEl = false;
  79. options.shareEl = false;
  80. options.bgOpacity = 0.85;
  81. options.tapToToggleControls = false;
  82. options.pinchToClose = false;
  83. options.clickToCloseNonZoomable = false;
  84. options.tapToClose = false;
  85. // Initializes and opens PhotoSwipe
  86. gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
  87. gallery.init();
  88. }
  89. function updateImgTypeToDB($img) {
  90. var id = $img.attr('data-id'),
  91. catalog = $img.attr('data-catalog'),
  92. subCatalog = $img.attr('data-sub-catalog');
  93. getReqPromise('patient/archives/event/img/edit',{id: id, imgType: catalog, imgLabel: subCatalog},'JSON','POST')
  94. .then(function(res) {
  95. if(res.status == 200) {
  96. $('.pswp__scroll-wrap').trigger('click');
  97. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑成功!'}).show();
  98. } else {
  99. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑失败!'}).show();
  100. }
  101. }).catch(function(e) {
  102. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑失败!'}).show();
  103. console && console.error(e);
  104. })
  105. }
  106. getReqPromise('patient/archives/event/detail',{event:Requests.event},'JSON','GET')
  107. .then(function(res) {
  108. d.close();
  109. var data = {},
  110. imgsMap = {};
  111. if(res.status==200) {
  112. data = res.data;
  113. var eventName = getEventTypeName(data.eventType);
  114. setPageTitle(eventName);
  115. $type.text(eventName);
  116. showDeptDoctor(data.deptName,data.doctorName);
  117. $time.text(data.eventDate.substr(0,10));
  118. if(data.orgName) {
  119. $org.text(data.orgName);
  120. $org.parent().show();
  121. }
  122. $diagnosis.text(data.dianosis);
  123. imgsMap = _.groupBy(data.eventImg, function(v) {
  124. return v.imgType;
  125. });
  126. _.mapObject(imgsMap,function(val, key) {
  127. var catalog = key?key:"未分类";
  128. var $wrap = $('div[data-type="'+catalog+'"]'),
  129. $ul = $wrap.find('.img-list').eq(0);
  130. html = template('li_tmpl',{list: val});
  131. $ul.html(html);
  132. $wrap.show();
  133. });
  134. }
  135. })
  136. .then(function() {
  137. var $imgs = $('img.preview-img');
  138. $imgs.on('click',function() {
  139. var idx = $imgs.index(this);
  140. var length = $imgs.length;
  141. updateCatalogNameTip(this);
  142. $('#page_counter').text('('+(idx+1)+'/'+length+')')
  143. previewImage(idx);
  144. gallery.listen('afterChange', function() {
  145. var imgIdx = gallery.getCurrentIndex();
  146. var $img = $imgs.eq(imgIdx);
  147. updateCatalogNameTip($img);
  148. $('#page_counter').text('('+(imgIdx+1)+'/'+length+')')
  149. updateCatalog($img);
  150. });
  151. gallery.listen('close', function() {
  152. window.location.reload();
  153. });
  154. updateCatalog(this);
  155. });
  156. $('.pop-catalog-sel').on('click',function() {
  157. var imgIdx = gallery.getCurrentIndex();
  158. $('#cur_page').text(imgIdx+1);
  159. $('#amount_page').text($imgs.length);
  160. $('#catalog_bar').hide();
  161. $('#catalog_box').slideDown();
  162. });
  163. $('.pswp__scroll-wrap').on('tap',function() {
  164. if($('#catalog_box').css('display')!='none') {
  165. $('#catalog_box').hide();
  166. $('#catalog_bar').slideDown();
  167. var imgIdx = gallery.getCurrentIndex();
  168. var $img = $imgs.eq(imgIdx);
  169. updateCatalogNameTip($img);
  170. } else {
  171. gallery.close();
  172. }
  173. });
  174. $('.img-catalog').on('click','a.c-btn-icon',function(e,readOnly) {
  175. var ref = $(this).attr('data-ref');
  176. var imgIdx = gallery.getCurrentIndex();
  177. var $img = $imgs.eq(imgIdx);
  178. if(ref) {
  179. $('.sub-catalog').not('#'+ref).hide();
  180. $('#'+ref).slideDown().find('a.c-btn-icon').removeClass('active');
  181. } else {
  182. $('.sub-catalog').hide();
  183. }
  184. var $catalog = $(this).closest('.img-catalog');
  185. $catalog.find('a.c-btn-icon').removeClass('active');
  186. $(this).addClass('active');
  187. if(readOnly!==false){
  188. $img.attr('data-catalog',$(this).attr('data-type'));
  189. $img.attr('data-sub-catalog','');
  190. if(!ref){
  191. updateImgTypeToDB($img);
  192. }
  193. }
  194. })
  195. $('.sub-catalog').on('click','a.c-btn-icon',function(e,readOnly) {
  196. var $catalog = $(this).closest('.sub-catalog');
  197. $catalog.find('a.c-btn-icon').removeClass('active');
  198. $(this).addClass('active');
  199. var imgIdx = gallery.getCurrentIndex();
  200. var $img = $imgs.eq(imgIdx);
  201. if(readOnly!==false){
  202. $img.attr('data-sub-catalog',$(this).attr('data-type'));
  203. updateImgTypeToDB($img);
  204. }
  205. });
  206. $('#delete_img_btn').on('click',function() {
  207. var imgIdx = gallery.getCurrentIndex();
  208. var $img = $imgs.eq(imgIdx);
  209. var id = $img.attr("data-id");
  210. getReqPromise('patient/archives/event/img/delete',{id: id},'JSON','POST')
  211. .then(function(res) {
  212. if(res.status == 200) {
  213. gallery.close();
  214. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除成功!'}).show();
  215. window.location.reload();
  216. } else {
  217. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除失败!'}).show();
  218. }
  219. }).catch(function(e) {
  220. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除失败!'}).show();
  221. console && console.error(e);
  222. })
  223. })
  224. })
  225. .then(function() {
  226. $('#edit_btn').on('click',function() {
  227. window.location.href = "shangchuanjiuzhenjilu-edit.html?event="+Requests.event
  228. })
  229. })
  230. .catch(function(e) {
  231. d.close();
  232. console && console.error(e)
  233. })
  234. window.onpageshow = function() {
  235. var isLoaded = localStorage.getItem("jiuzhenxiangqing")
  236. if(isLoaded=="1") {
  237. localStorage.removeItem("jiuzhenxiangqing");
  238. location.reload(true);
  239. }
  240. else {
  241. localStorage.setItem("jiuzhenxiangqing","1");
  242. }
  243. }
  244. template.helper("setPhoto", function(p) {
  245. return getImgUrl(p);
  246. });