var $date = $("#date"), $type = $('#type'), $hospital = $('#hospital'), $dept = $('#dept'), $docName = $('#doc_name'); var Requests = GetRequest(), eventId = Requests.event; var userAgent = JSON.parse(window.localStorage.getItem(agentName)); var eventInfo = null; function updateImageCounter() { var cur = gallery.getCurrentIndex()+1; var amount = gallery.items.length; $('#cur_page').text(cur); $('#amount_page').text(amount); } function initImageTypeBox($img) { var catalog = $img.attr('data-catalog'); var subCatalog = $img.attr('data-sub-catalog'); $('.img-catalog').find('a.c-btn-icon').removeClass('active'); $('.sub-catalog').find('a.c-btn-icon').removeClass('active'); $('.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 validRequired() { var form = getFormData(); var date = form.date, type = form.type; if(!date || !type) { return false; } return true; } function getFormData() { return { date: $('#date').val(), type: $('#type').attr('data-val'), hospital: $('#hospital').val(), dept: $('#dept').val(), doctor: $('#doc_name').val(), diagnosis: _.map($('#diagnosis li'),function(el) { return $(el).find('.c-list-info').text() }) } } getReqPromise('patient/archives/event/detail',{ event: eventId },'JSON','GET') .then(function(res) { return new Promise(function(resolve,reject) { eventInfo = res.data; if(eventInfo) { resolve(true) } else { reject(res) } }) }) .then(function() { /* 选择日期 */ var opt = { preset: 'date', theme: 'ios', lang: 'zh', minDate: new Date(1900, 01, 01) }; $('input[data-time=date]').mobiscroll(opt); if(eventInfo.eventDate) { $date.val(eventInfo.eventDate.slice(0,10)); } }) .then(function() { var arr_key=['1', '2', '3']; var arr_value=['门/急诊', '住院','体检']; $type.mobiscroll({ theme: 'ios', lang: 'zh', formatValue: function(d) { return d.join(','); }, customWheels: true, wheels: [ [{ keys: arr_key, values: arr_value }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); $type.attr('data-val',dd[0].keys); $type.val(dd[0].values); } }); var eventName = ""; for(var i=0;i'+ diag +'' +'
' +''; }); $('#diagnosis').html(html); } }) .then(function() { var imgs = eventInfo.eventImg; if(imgs) { _.each(imgs,function(img) { var $li = $('
  • ' + '

  • '); var name = img.imgType+(img.imgLabel?('_'+img.imgLabel):""); if(name!="_") { $li.find('.catalog-name').text(name); } $('#add_img_li').before($li); }); } }) .then(function() { $('#add_diag').on('click',function() { var $diagInp = $('#diag_input'), diag = $.trim($diagInp.val()); if(diag) { var li = '
  • ' +'
    '+ diag +'
    ' +'
    ' +'
  • '; $('#diagnosis').append(li); $diagInp.val(''); } }); $('#diagnosis').on('click','.del-icon',function(){ var $li = $(this).closest('li'); $li.remove(); }); $('#img_ul').on('click','li:not(#add_img_li)',function() { previewImage($(this).index()); var preIdx = $(this).index(); gallery.listen('beforeChange', function() { var imgIdx = preIdx; var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx); var $img = $li.find('img:not(.del-icon)'); var $p = $li.find('.catalog-name'); var catalog = $img.attr('data-catalog')||""; var subCatalog = $img.attr('data-sub-catalog')||""; var name = catalog+(subCatalog?('_'+subCatalog):""); if(name=="_") { $p.hide(); } else { $p.text(name).show(); } }); gallery.listen('afterChange', function() { updateImageCounter(); var imgIdx = gallery.getCurrentIndex(); preIdx = imgIdx; var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx); var $img = $li.find('img:not(.del-icon)'); initImageTypeBox($img); }); updateImageCounter(); initImageTypeBox($(this).find('img:not(.del-icon)')); }).on('click','.del-wrap',function() { $(this).closest('li').remove(); return false; }) $('.img-catalog').on('click','a.c-btn-icon',function(e,toNext) { var ref = $(this).attr('data-ref'); 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'); var imgIdx = gallery.getCurrentIndex(); var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx); var $img = $li.find('img:not(.del-icon)'); $img.attr('data-catalog',$(this).attr('data-type')); if(toNext!==false && !ref) { //gallery.next(); } }) $('.sub-catalog').on('click','a.c-btn-icon',function(e,toNext) { var $catalog = $(this).closest('.sub-catalog'); $catalog.find('a.c-btn-icon').removeClass('active'); $(this).addClass('active'); var imgIdx = gallery.getCurrentIndex(); var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx); var $img = $li.find('img:not(.del-icon)'); $img.attr('data-sub-catalog',$(this).attr('data-type')); if(toNext!==false) { //gallery.next(); } }); $('#set_type_ack').on('click',function() { gallery.close(); }); $('#save_btn').on('click',function() { if(validRequired()) { var form = getFormData(); var images = _.map($('#img_ul img:not(.del-icon)'),function(img){ var $img = $(img); return { "imgUrl": $img.attr('src'), "imgLabel": $img.attr('data-sub-catalog')||"", "imgType": $img.attr('data-catalog') || "" } }); var diagnosis = _.map($('#diagnosis li'),function(el) { return $(el).find('.c-list-info').text() }); var d = dialog({contentType:'load', skin:'bk-popup',content: '正在保存,请稍后'}).showModal(); var params = { id: eventId, patient: userAgent.uid, orgName: form.hospital, deptName: form.dept, doctorName: form.doctor, eventDate: form.date, eventType: form.type, dianosis: diagnosis.join(','), eventImg: images }; getReqPromise("patient/archives/event/save",{data: JSON.stringify(params)},'JSON','POST') .then(function(res) { d.close(); if(res.status == 200) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存成功!'}).show(); window.history.back(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show(); } }).catch(function(e) { d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show(); console && console.error(e); }); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请填写完整信息'}).show(); } }); $('#delete_btn').on('click',function(){ // TODO 删除请求 dialog({ content: '确定删除该病历?', okValue:'确定', ok: function (){ getReqPromise("patient/archives/event/delete",{event: eventId},'JSON','POST') .then(function(res) { if(res.status == 200) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除成功!'}).show(); window.location.href = "jiuzhenjilu.html?"+$.now(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除失败!'}).show(); } }).catch(function(e){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除失败!'}).show(); }) }, cancelValue: '取消', cancel: function () { return; } }).showModal(); }) }).catch(function(e) { console && console.error(e); })