shangchuanjiuzhenjilu-edit.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. var $date = $("#date"),
  2. $type = $('#type'),
  3. $hospital = $('#hospital'),
  4. $dept = $('#dept'),
  5. $docName = $('#doc_name');
  6. var Requests = GetRequest(),
  7. eventId = Requests.event;
  8. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  9. var eventInfo = null;
  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. getReqPromise('patient/archives/event/detail',{
  46. event: eventId
  47. },'JSON','GET')
  48. .then(function(res) {
  49. return new Promise(function(resolve,reject) {
  50. eventInfo = res.data;
  51. if(eventInfo) {
  52. resolve(true)
  53. } else {
  54. reject(res)
  55. }
  56. })
  57. })
  58. .then(function() {
  59. /* 选择日期 */
  60. var opt = {
  61. preset: 'date',
  62. theme: 'ios',
  63. lang: 'zh',
  64. minDate: new Date(1900, 01, 01)
  65. };
  66. $('input[data-time=date]').mobiscroll(opt);
  67. if(eventInfo.eventDate) {
  68. $date.val(eventInfo.eventDate.slice(0,10));
  69. }
  70. })
  71. .then(function() {
  72. var arr_key=['1', '2', '3'];
  73. var arr_value=['门/急诊', '住院','体检'];
  74. $type.mobiscroll({
  75. theme: 'ios',
  76. lang: 'zh',
  77. formatValue: function(d) {
  78. return d.join(',');
  79. },
  80. customWheels: true,
  81. wheels: [
  82. [{
  83. keys: arr_key,
  84. values: arr_value
  85. }]
  86. ],
  87. onSelect: function(valueText, inst) {
  88. var dd = eval("[" + valueText + "]");
  89. $type.attr('data-val',dd[0].keys);
  90. $type.val(dd[0].values);
  91. }
  92. });
  93. var eventName = "";
  94. for(var i=0;i<arr_key.length;i++) {
  95. if((i+1)==eventInfo.eventType) {
  96. eventName = arr_value[i];
  97. break;
  98. }
  99. }
  100. if(eventName) {
  101. $type.attr('data-val',eventInfo.eventType);
  102. $type.val(eventName);
  103. }
  104. })
  105. .then(function() {
  106. $hospital.val(eventInfo.orgName);
  107. $dept.val(eventInfo.deptName);
  108. $docName.val(eventInfo.doctorName);
  109. var dianosis = [];
  110. if(eventInfo.dianosis) {
  111. dianosis = eventInfo.dianosis.split(',');
  112. var html = '';
  113. _.each(dianosis,function(diag) {
  114. html += '<li class="ptb12">'
  115. +'<div class="c-list-info">'+ diag +'</div>'
  116. +'<div class="c-list-key pl20 c-909090"><img class="del-icon mt5" src="../images/shanchu01_btn.png"/></div>'
  117. +'</li>';
  118. });
  119. $('#diagnosis').html(html);
  120. }
  121. })
  122. .then(function() {
  123. var imgs = eventInfo.eventImg;
  124. if(imgs) {
  125. _.each(imgs,function(img) {
  126. var $li = $('<li>' + '<img src="' + getImgUrl(img.imgUrl) + '" data-id="'+img.id+'" data-catalog="'+img.imgType+'" data-sub-catalog="'+img.imgLabel+'"/><div class="del-wrap"><img src="../images/shanchu02_btn.png" class="del-icon"/></div><p class="catalog-name"></p></li>');
  127. var name = img.imgType+(img.imgLabel?('_'+img.imgLabel):"");
  128. if(name!="_") {
  129. $li.find('.catalog-name').text(name);
  130. }
  131. $('#add_img_li').before($li);
  132. });
  133. }
  134. })
  135. .then(function() {
  136. $('#add_diag').on('click',function() {
  137. var $diagInp = $('#diag_input'),
  138. diag = $.trim($diagInp.val());
  139. if(diag) {
  140. var li = '<li class="ptb12">'
  141. +'<div class="c-list-info">'+ diag +'</div>'
  142. +'<div class="c-list-key pl20 c-909090"><img class="del-icon mt5" src="../images/shanchu01_btn.png"/></div>'
  143. +'</li>';
  144. $('#diagnosis').append(li);
  145. $diagInp.val('');
  146. }
  147. });
  148. $('#diagnosis').on('click','.del-icon',function(){
  149. var $li = $(this).closest('li');
  150. $li.remove();
  151. });
  152. $('#img_ul').on('click','li:not(#add_img_li)',function() {
  153. previewImage($(this).index());
  154. var preIdx = $(this).index();
  155. gallery.listen('beforeChange', function() {
  156. var imgIdx = preIdx;
  157. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  158. var $img = $li.find('img:not(.del-icon)');
  159. var $p = $li.find('.catalog-name');
  160. var catalog = $img.attr('data-catalog')||"";
  161. var subCatalog = $img.attr('data-sub-catalog')||"";
  162. var name = catalog+(subCatalog?('_'+subCatalog):"");
  163. if(name=="_") {
  164. $p.hide();
  165. } else {
  166. $p.text(name).show();
  167. }
  168. });
  169. gallery.listen('afterChange', function() {
  170. updateImageCounter();
  171. var imgIdx = gallery.getCurrentIndex();
  172. preIdx = imgIdx;
  173. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  174. var $img = $li.find('img:not(.del-icon)');
  175. initImageTypeBox($img);
  176. });
  177. updateImageCounter();
  178. initImageTypeBox($(this).find('img:not(.del-icon)'));
  179. }).on('click','.del-wrap',function() {
  180. $(this).closest('li').remove();
  181. return false;
  182. })
  183. $('.img-catalog').on('click','a.c-btn-icon',function(e,toNext) {
  184. var ref = $(this).attr('data-ref');
  185. if(ref) {
  186. $('.sub-catalog').not('#'+ref).hide();
  187. $('#'+ref).slideDown().find('a.c-btn-icon').removeClass('active');
  188. } else {
  189. $('.sub-catalog').hide();
  190. }
  191. var $catalog = $(this).closest('.img-catalog');
  192. $catalog.find('a.c-btn-icon').removeClass('active');
  193. $(this).addClass('active');
  194. var imgIdx = gallery.getCurrentIndex();
  195. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  196. var $img = $li.find('img:not(.del-icon)');
  197. $img.attr('data-catalog',$(this).attr('data-type'));
  198. if(toNext!==false && !ref) {
  199. //gallery.next();
  200. }
  201. })
  202. $('.sub-catalog').on('click','a.c-btn-icon',function(e,toNext) {
  203. var $catalog = $(this).closest('.sub-catalog');
  204. $catalog.find('a.c-btn-icon').removeClass('active');
  205. $(this).addClass('active');
  206. var imgIdx = gallery.getCurrentIndex();
  207. var $li = $('#img_ul').find('li:not(#add_img_li)').eq(imgIdx);
  208. var $img = $li.find('img:not(.del-icon)');
  209. $img.attr('data-sub-catalog',$(this).attr('data-type'));
  210. if(toNext!==false) {
  211. //gallery.next();
  212. }
  213. });
  214. $('#set_type_ack').on('click',function() {
  215. gallery.close();
  216. });
  217. $('#save_btn').on('click',function() {
  218. if(validRequired()) {
  219. var form = getFormData();
  220. var images = _.map($('#img_ul img:not(.del-icon)'),function(img){
  221. var $img = $(img);
  222. return {
  223. "imgUrl": $img.attr('src'),
  224. "imgLabel": $img.attr('data-sub-catalog')||"",
  225. "imgType": $img.attr('data-catalog') || ""
  226. }
  227. });
  228. var diagnosis = _.map($('#diagnosis li'),function(el) {
  229. return $(el).find('.c-list-info').text()
  230. });
  231. var d = dialog({contentType:'load', skin:'bk-popup',content: '正在保存,请稍后'}).showModal();
  232. var params = {
  233. id: eventId,
  234. patient: userAgent.uid,
  235. orgName: form.hospital,
  236. deptName: form.dept,
  237. doctorName: form.doctor,
  238. eventDate: form.date,
  239. eventType: form.type,
  240. dianosis: diagnosis.join(','),
  241. eventImg: images
  242. };
  243. getReqPromise("patient/archives/event/save",{data: JSON.stringify(params)},'JSON','POST')
  244. .then(function(res) {
  245. d.close();
  246. if(res.status == 200) {
  247. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存成功!'}).show();
  248. window.history.back();
  249. } else {
  250. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show();
  251. }
  252. }).catch(function(e) {
  253. d.close();
  254. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败!'}).show();
  255. console && console.error(e);
  256. });
  257. } else {
  258. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请填写完整信息'}).show();
  259. }
  260. });
  261. $('#delete_btn').on('click',function(){
  262. // TODO 删除请求
  263. dialog({
  264. content: '确定删除该病历?',
  265. okValue:'确定',
  266. ok: function (){
  267. getReqPromise("patient/archives/event/delete",{event: eventId},'JSON','POST')
  268. .then(function(res) {
  269. if(res.status == 200) {
  270. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除成功!'}).show();
  271. window.location.href = "jiuzhenjilu.html?"+$.now();
  272. } else {
  273. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除失败!'}).show();
  274. }
  275. }).catch(function(e){
  276. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'病历删除失败!'}).show();
  277. })
  278. },
  279. cancelValue: '取消',
  280. cancel: function () {
  281. return;
  282. }
  283. }).showModal();
  284. })
  285. }).catch(function(e) { console && console.error(e); })