123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- var Requests = GetRequest(),
- fromEventType = Requests.eventType;
- var $date = $("#date"),
- $type = $('#type'),
- $member = $('#member'),
- $hospital = $('#hospital'),
- $dept = $('#dept'),
- $docName = $('#doc_name');
- var userAgent = JSON.parse(window.localStorage.getItem(agentName));
- 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()
- })
- }
- }
- Promise.resolve()
- .then(function() {
- /* 选择日期 */
- var opt = {
- preset: 'date',
- theme: 'ios',
- lang: 'zh',
- minDate: new Date(1900, 01, 01)
- };
- $('input[data-time=date]').mobiscroll(opt);
- var date = new Date()
- $date.val(date.Format("yyyy-MM-dd"));
-
- })
- .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);
- }
- });
-
- //关联被代理人
- $member.attr('data-val',userAgent.represented?userAgent.represented:userAgent.uid);
- $member.val(window.localStorage.getItem('nowPatientName'));
- }).then(function() {
- $('#add_diag').on('click',function() {
- var $diagInp = $('#diag_input'),
- diag = $.trim($diagInp.val());
- if(diag) {
- var li = '<li class="ptb12">'
- +'<div class="c-list-info">'+ diag +'</div>'
- +'<div class="c-list-key pl20 c-909090"><img class="del-icon mt5" src="../images/shanchu01_btn.png"/></div>'
- +'</li>'
- $('#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 $diagInp = $('#diag_input'),
- diag = $.trim($diagInp.val());
- if(diag) { // 如果用户忘记点击“添加”诊断,则自动保存
- diagnosis.push(diag);
- }
-
- var d = dialog({contentType:'load', skin:'bk-popup',content: '正在保存,请稍后'}).showModal();
- var params = {
- patient: userAgent.represented?userAgent.represented: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();
- }
-
- });
-
- }).catch(function(e) { console && console.error(e); })
|