var d= dialog({contentType:'load', skin:'bk-popup'}).show(); var Requests = GetRequest(), event = Requests.event; var $time = $('#time'), $type = $('#type'), $deptDoctor = $('#dept_doctor'), $org = $('#org'), $diagnosis = $('#diagnosis'); var gallery = null; // 修改页面标题 function setPageTitle(name) { //动态修改title的值 var $body = $('body'); document.title = name+"详情"; // hack在微信等webview中无法修改document.title的情况 var $iframe = $(''); $iframe.on('load',function() { setTimeout(function() { $iframe.off('load').remove(); }, 0); }).appendTo($body); } function getEventTypeName(type) { if(type=="1") { return "门诊"; } else if(type=="2"){ return "住院"; } else if(type == "3"){ return "体检"; } } function showDeptDoctor(dept,doctor) { if(!dept&&!doctor) { return ; } else if(dept&& doctor) { $deptDoctor.html(''+dept+'/'+doctor); } else if(dept) { $deptDoctor.html(''+dept); } else if(doctor) { $deptDoctor.html(''+doctor); } $deptDoctor.show(); } function updateCatalogNameTip(img) { var catalog = $(img).attr('data-catalog')||""; var subCatalog = $(img).attr('data-sub-catalog')||""; var catalogName = catalog; if(subCatalog) { catalogName = catalogName + '_' + subCatalog; } $('#catalog_name').text(catalogName); } function updateCatalog(img) { var catalog = $(img).attr('data-catalog')||""; var subCatalog = $(img).attr('data-sub-catalog')||""; $('.img-catalog').find('a.c-btn-icon[data-type="'+catalog+'"]').trigger('click',[false]); $('.sub-catalog').find('a.c-btn-icon[data-type="'+subCatalog+'"]').trigger('click',[false]); } function previewImage(sid) { var pswpElement = document.querySelectorAll('.pswp')[0]; var w = $(window).width(), h = $(window).height(); var items = _.map($('img.preview-img'),function(img) { return { src: getImgUrl($(img).attr('src')), w: w, h: h, initialPosition: { x: 0, y:0 } } }); var options = { // optionName: 'option value' // for example: index: sid||0 // start at first slide }; options.mainClass = 'pswp--minimal--dark'; options.barsSize = {top:0,bottom:0}; options.captionEl = false; options.fullscreenEl = false; options.shareEl = false; options.bgOpacity = 0.85; options.tapToToggleControls = false; options.pinchToClose = false; options.clickToCloseNonZoomable = false; options.tapToClose = false; // Initializes and opens PhotoSwipe gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); gallery.init(); } function updateImgTypeToDB($img) { var id = $img.attr('data-id'), catalog = $img.attr('data-catalog'), subCatalog = $img.attr('data-sub-catalog'); getReqPromise('patient/archives/event/img/edit',{id: id, imgType: catalog, imgLabel: subCatalog},'JSON','POST') .then(function(res) { if(res.status == 200) { $('.pswp__scroll-wrap').trigger('click'); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑成功!'}).show(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑失败!'}).show(); } }).catch(function(e) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片编辑失败!'}).show(); console && console.error(e); }) } getReqPromise('patient/archives/event/detail',{event:Requests.event},'JSON','GET') .then(function(res) { d.close(); var data = {}, imgsMap = {}; if(res.status==200) { data = res.data; var eventName = getEventTypeName(data.eventType); setPageTitle(eventName); $type.text(eventName); showDeptDoctor(data.deptName,data.doctorName); $time.text(data.eventDate.substr(0,10)); if(data.orgName) { $org.text(data.orgName); $org.parent().show(); } $diagnosis.text(data.dianosis); imgsMap = _.groupBy(data.eventImg, function(v) { return v.imgType; }); _.mapObject(imgsMap,function(val, key) { var catalog = key?key:"未分类"; var $wrap = $('div[data-type="'+catalog+'"]'), $ul = $wrap.find('.img-list').eq(0); html = template('li_tmpl',{list: val}); $ul.html(html); $wrap.show(); }); } }) .then(function() { var $imgs = $('img.preview-img'); $imgs.on('click',function() { var idx = $imgs.index(this); var length = $imgs.length; updateCatalogNameTip(this); $('#page_counter').text('('+(idx+1)+'/'+length+')') previewImage(idx); gallery.listen('afterChange', function() { var imgIdx = gallery.getCurrentIndex(); var $img = $imgs.eq(imgIdx); updateCatalogNameTip($img); $('#page_counter').text('('+(imgIdx+1)+'/'+length+')') updateCatalog($img); }); gallery.listen('close', function() { window.location.reload(); }); updateCatalog(this); }); $('.pop-catalog-sel').on('click',function() { var imgIdx = gallery.getCurrentIndex(); $('#cur_page').text(imgIdx+1); $('#amount_page').text($imgs.length); $('#catalog_bar').hide(); $('#catalog_box').slideDown(); }); $('.pswp__scroll-wrap').on('tap',function() { if($('#catalog_box').css('display')!='none') { $('#catalog_box').hide(); $('#catalog_bar').slideDown(); var imgIdx = gallery.getCurrentIndex(); var $img = $imgs.eq(imgIdx); updateCatalogNameTip($img); } else { gallery.close(); } }); $('.img-catalog').on('click','a.c-btn-icon',function(e,readOnly) { var ref = $(this).attr('data-ref'); var imgIdx = gallery.getCurrentIndex(); var $img = $imgs.eq(imgIdx); if(ref) { $('.sub-catalog').not('#'+ref).hide(); $('#'+ref).slideDown().find('a.c-btn-icon').removeClass('active'); } else { $('.sub-catalog').hide(); } var $catalog = $(this).closest('.img-catalog'); $catalog.find('a.c-btn-icon').removeClass('active'); $(this).addClass('active'); if(readOnly!==false){ $img.attr('data-catalog',$(this).attr('data-type')); $img.attr('data-sub-catalog',''); if(!ref){ updateImgTypeToDB($img); } } }) $('.sub-catalog').on('click','a.c-btn-icon',function(e,readOnly) { var $catalog = $(this).closest('.sub-catalog'); $catalog.find('a.c-btn-icon').removeClass('active'); $(this).addClass('active'); var imgIdx = gallery.getCurrentIndex(); var $img = $imgs.eq(imgIdx); if(readOnly!==false){ $img.attr('data-sub-catalog',$(this).attr('data-type')); updateImgTypeToDB($img); } }); $('#delete_img_btn').on('click',function() { var imgIdx = gallery.getCurrentIndex(); var $img = $imgs.eq(imgIdx); var id = $img.attr("data-id"); getReqPromise('patient/archives/event/img/delete',{id: id},'JSON','POST') .then(function(res) { if(res.status == 200) { gallery.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除成功!'}).show(); window.location.reload(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除失败!'}).show(); } }).catch(function(e) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'图片删除失败!'}).show(); console && console.error(e); }) }) }) .then(function() { $('#edit_btn').on('click',function() { window.location.href = "shangchuanjiuzhenjilu-edit.html?event="+Requests.event }) }) .catch(function(e) { d.close(); console && console.error(e) }) window.onpageshow = function() { var isLoaded = localStorage.getItem("jiuzhenxiangqing") if(isLoaded=="1") { localStorage.removeItem("jiuzhenxiangqing"); location.reload(true); } else { localStorage.setItem("jiuzhenxiangqing","1"); } } template.helper("setPhoto", function(p) { return getImgUrl(p); });