shangchuanjiuzhenjilu.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. var Requests = GetRequest(),
  2. fromEventType = Requests.eventType;
  3. var $date = $("#date"),
  4. $type = $('#type'),
  5. $member = $('#member'),
  6. $hospital = $('#hospital'),
  7. $dept = $('#dept'),
  8. $docName = $('#doc_name');
  9. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  10. function updateImageCounter() {
  11. var cur = gallery.getCurrentIndex()+1;
  12. var amount = gallery.items.length;
  13. $('#cur_page').text(cur);
  14. $('#amount_page').text(amount);
  15. }
  16. function initImageTypeBox($img) {
  17. var catalog = $img.attr('data-catalog');
  18. var subCatalog = $img.attr('data-sub-catalog');
  19. $('.img-catalog').find('a.c-btn-icon').removeClass('active');
  20. $('.sub-catalog').find('a.c-btn-icon').removeClass('active');
  21. $('.img-catalog').find('a.c-btn-icon[data-type="'+catalog+'"]').trigger('click',[false]);
  22. $('.sub-catalog').find('a.c-btn-icon[data-type="'+subCatalog+'"]').trigger('click',[false]);
  23. }
  24. function validRequired() {
  25. var form = getFormData();
  26. var date = form.date,
  27. type = form.type;
  28. if(!date || !type) {
  29. return false;
  30. }
  31. return true;
  32. }
  33. function getFormData() {
  34. return {
  35. date: $('#date').val(),
  36. type: $('#type').attr('data-val'),
  37. hospital: $('#hospital').val(),
  38. dept: $('#dept').val(),
  39. doctor: $('#doc_name').val(),
  40. diagnosis: _.map($('#diagnosis li'),function(el) {
  41. return $(el).find('.c-list-info').text()
  42. })
  43. }
  44. }
  45. Promise.resolve()
  46. .then(function() {
  47. /* 选择日期 */
  48. var opt = {
  49. preset: 'date',
  50. theme: 'ios',
  51. lang: 'zh',
  52. minDate: new Date(1900, 01, 01)
  53. };
  54. $('input[data-time=date]').mobiscroll(opt);
  55. var date = new Date()
  56. $date.val(date.Format("yyyy-MM-dd"));
  57. })
  58. .then(function() {
  59. var arr_key=['1', '2', '3'];
  60. var arr_value=['门/急诊', '住院','体检'];
  61. $type.mobiscroll({
  62. theme: 'ios',
  63. lang: 'zh',
  64. formatValue: function(d) {
  65. return d.join(',');
  66. },
  67. customWheels: true,
  68. wheels: [
  69. [{
  70. keys: arr_key,
  71. values: arr_value
  72. }]
  73. ],
  74. onSelect: function(valueText, inst) {
  75. var dd = eval("[" + valueText + "]");
  76. $type.attr('data-val',dd[0].keys);
  77. $type.val(dd[0].values);
  78. }
  79. });
  80. //关联被代理人
  81. $member.attr('data-val',userAgent.represented?userAgent.represented:userAgent.uid);
  82. $member.val(window.localStorage.getItem('nowPatientName'));
  83. }).then(function() {
  84. $('#add_diag').on('click',function() {
  85. var $diagInp = $('#diag_input'),
  86. diag = $.trim($diagInp.val());
  87. if(diag) {
  88. var li = '<li class="ptb12">'
  89. +'<div class="c-list-info">'+ diag +'</div>'
  90. +'<div class="c-list-key pl20 c-909090"><img class="del-icon mt5" src="../images/shanchu01_btn.png"/></div>'
  91. +'</li>'
  92. $('#diagnosis').append(li);
  93. $diagInp.val('');
  94. }
  95. });
  96. $('#diagnosis').on('click','.del-icon',function(){
  97. var $li = $(this).closest('li');
  98. $li.remove();
  99. });
  100. $('#img_ul').on('click','li:not(#add_img_li)',function() {
  101. previewImage($(this).index());
  102. var preIdx = $(this).index();
  103. gallery.listen('beforeChange', function() {
  104. var imgIdx = preIdx;
  105. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  106. var $img = $li.find('img:not(.del-icon)');
  107. var $p = $li.find('.catalog-name');
  108. var catalog = $img.attr('data-catalog')||"";
  109. var subCatalog = $img.attr('data-sub-catalog')||"";
  110. var name = catalog+(subCatalog?('_'+subCatalog):"");
  111. if(name=="_") {
  112. $p.hide();
  113. } else {
  114. $p.text(name).show();;
  115. }
  116. });
  117. gallery.listen('afterChange', function() {
  118. updateImageCounter();
  119. var imgIdx = gallery.getCurrentIndex();
  120. preIdx = imgIdx;
  121. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  122. var $img = $li.find('img:not(.del-icon)');
  123. initImageTypeBox($img);
  124. });
  125. updateImageCounter();
  126. initImageTypeBox($(this).find('img:not(.del-icon)'));
  127. }).on('click','.del-wrap',function() {
  128. $(this).closest('li').remove();
  129. return false;
  130. });
  131. $('.img-catalog').on('click','a.c-btn-icon',function(e,toNext) {
  132. var ref = $(this).attr('data-ref');
  133. if(ref) {
  134. $('.sub-catalog').not('#'+ref).hide();
  135. $('#'+ref).slideDown().find('a.c-btn-icon').removeClass('active');
  136. } else {
  137. $('.sub-catalog').hide();
  138. }
  139. var $catalog = $(this).closest('.img-catalog');
  140. $catalog.find('a.c-btn-icon').removeClass('active');
  141. $(this).addClass('active');
  142. var imgIdx = gallery.getCurrentIndex();
  143. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  144. var $img = $li.find('img:not(.del-icon)');
  145. $img.attr('data-catalog',$(this).attr('data-type'));
  146. if(toNext!==false && !ref) {
  147. //gallery.next();
  148. }
  149. })
  150. $('.sub-catalog').on('click','a.c-btn-icon',function(e,toNext) {
  151. var $catalog = $(this).closest('.sub-catalog');
  152. $catalog.find('a.c-btn-icon').removeClass('active');
  153. $(this).addClass('active');
  154. var imgIdx = gallery.getCurrentIndex();
  155. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  156. var $img = $li.find('img:not(.del-icon)');
  157. $img.attr('data-sub-catalog',$(this).attr('data-type'));
  158. if(toNext!==false) {
  159. //gallery.next();
  160. }
  161. });
  162. $('#set_type_ack').on('click',function() {
  163. gallery.close();
  164. });
  165. $('#save_btn').on('click',function() {
  166. if(validRequired()) {
  167. var form = getFormData();
  168. var images = _.map($('#img_ul img:not(.del-icon)'),function(img){
  169. var $img = $(img);
  170. return {
  171. "imgUrl": $img.attr('src'),
  172. "imgLabel": $img.attr('data-sub-catalog')||"",
  173. "imgType": $img.attr('data-catalog') || ""
  174. }
  175. });
  176. var diagnosis = _.map($('#diagnosis li'),function(el) {
  177. return $(el).find('.c-list-info').text()
  178. });
  179. var $diagInp = $('#diag_input'),
  180. diag = $.trim($diagInp.val());
  181. if(diag) { // 如果用户忘记点击“添加”诊断,则自动保存
  182. diagnosis.push(diag);
  183. }
  184. var d = dialog({contentType:'load', skin:'bk-popup',content: '正在保存,请稍后'}).showModal();
  185. var params = {
  186. patient: userAgent.represented?userAgent.represented:userAgent.uid,
  187. orgName: form.hospital,
  188. deptName: form.dept,
  189. doctorName: form.doctor,
  190. eventDate: form.date,
  191. eventType: form.type,
  192. dianosis: diagnosis.join(','),
  193. eventImg: images
  194. };
  195. getReqPromise("patient/archives/event/save",{data: JSON.stringify(params)},'JSON','POST')
  196. .then(function(res) {
  197. d.close();
  198. if(res.status == 200) {
  199. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存成功!'}).show();
  200. window.history.back();
  201. } else {
  202. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show();
  203. }
  204. }).catch(function(e) {
  205. d.close();
  206. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show();
  207. console && console.error(e);
  208. });
  209. } else {
  210. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请填写完整信息'}).show();
  211. }
  212. });
  213. }).catch(function(e) { console && console.error(e); })