add-prescription-consult.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var d2 = dialog({contentType:'load', skin:'bk-popup'});
  3. var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'});
  4. var request = GetRequest();
  5. var patientCode = request['patient'],
  6. patientName = decodeURI(request['name']),
  7. prescriptionCode = request['prescriptionCode']; //处方的code
  8. var jw_code = request['jw_code']
  9. var baseInfo = {};
  10. mui.init();
  11. //初始化单页view
  12. var viewApi = mui('#app').view({
  13. defaultPage: '#main'
  14. });
  15. var view = viewApi.view;
  16. (function($) {
  17. //处理view的后退与webview后退
  18. var oldBack = $.back;
  19. $.back = function() {
  20. if (viewApi.canBack()) { //如果view可以后退,则执行view的后退
  21. viewApi.back();
  22. } else { //执行webview后退
  23. oldBack();
  24. }
  25. };
  26. //监听页面切换事件方案1,通过view元素监听所有页面切换事件,目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
  27. //第一个参数为事件名称,第二个参数为事件回调,其中e.detail.page为当前页面的html对象
  28. view.addEventListener('pageBeforeShow', function(e) {
  29. console.log(e.detail.page.id + ' beforeShow');
  30. if(e.detail.page.id == "list"){
  31. //显示处方列表页面
  32. // reloadListImage();
  33. var list = listPage();
  34. list.initPage();
  35. }else if(e.detail.page.id == "main"){
  36. console.log("back to main");
  37. prescriptionCode = window.localStorage.getItem("prescriptionCode");
  38. window.localStorage.removeItem("prescriptionCode");
  39. getPrescriptionDetail(prescriptionCode);
  40. }
  41. });
  42. view.addEventListener('pageShow', function(e) {
  43. // console.log(e.detail.page.id + ' show');
  44. });
  45. view.addEventListener('pageBeforeBack', function(e) {
  46. // console.log(e.detail.page.id + ' beforeBack');
  47. });
  48. view.addEventListener('pageBack', function(e) {
  49. // console.log(e.detail.page.id + ' back');
  50. });
  51. })(mui);
  52. $(function(){
  53. //判断是否可以续方咨询,并且获得咨询对象的信息
  54. isPrescriptionConsult();
  55. if(jw_code){
  56. //获得处方信息
  57. getPrescriptionDetail(jw_code);
  58. }else if(prescriptionCode){
  59. //获得处方信息
  60. getPrescriptionDetail(prescriptionCode);
  61. }
  62. bindEvents();
  63. });
  64. //判断是否可以续方咨询,并且获得咨询对象的信息
  65. function isPrescriptionConsult(){
  66. d2.show();
  67. var url = '/patient/consult/isPrescriptionConsult',
  68. params = {patient: patientCode};
  69. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  70. if(res.status == 200){
  71. d2.close()
  72. baseInfo = res.data;
  73. $("#patientName").text(patientName);
  74. $("#docName").text(baseInfo.doctorName);
  75. $("#checkDocName").text(baseInfo.doctorName);
  76. $("#dept").text(baseInfo.hospitalName);
  77. //增加续方说明选择文本
  78. var html = template('explain_tmp', {list: res.data.prescriptionExplain});
  79. $("#explain").empty().append(html);
  80. }else{
  81. queryFailed(res);
  82. }
  83. });
  84. }
  85. //获得处方信息
  86. function getPrescriptionDetail(code){
  87. //TODO
  88. d.showModal();
  89. var url = '/patient/prescriptionInfo/getPrescription',
  90. params = {code: code};
  91. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  92. if(res.status == 200){
  93. d.close();
  94. var str = "";
  95. for(i=0; i<res.data.prescriptionDt.length; i++){
  96. str += res.data.prescriptionDt[i].healthProblemName+" ";
  97. }
  98. for(j=0; j<res.data.prescriptionInfo.length; j++){
  99. if(j < 2){
  100. var item = res.data.prescriptionInfo[j];
  101. str += item.drugName + ' ' + item.num+item.drugNumUnitName+' ';
  102. }
  103. }
  104. $("#preInfo").text(str);
  105. }else{
  106. queryFailed(res);
  107. }
  108. });
  109. }
  110. function bindEvents(){
  111. $("#consultType").mobiscroll({
  112. theme: 'ios',
  113. lang: 'zh',
  114. customWheels: true,
  115. wheels: [
  116. [{
  117. keys: [1,2,3],
  118. values: ['高血压-续方咨询', '糖尿病-续方咨询','高&糖-续方咨询']
  119. }]
  120. ],
  121. onSelect: function(valueText, inst){
  122. var dd = eval("[" + valueText + "]"),
  123. k = dd[0].keys,
  124. v = dd[0].values;
  125. $("#consultType").val(v);
  126. $("#consultType").attr("data-type", k);
  127. }
  128. });
  129. // $("#preInfo").on('click', function(){
  130. // //跳转去处方选择页面时,缓存textarea内的信息
  131. // var text = $("textarea").val().trim();
  132. // if(text.length > 0){
  133. // window.localStorage.setItem("precontent", text);
  134. // }
  135. // window.location.href = "prescription-selection.html";
  136. // });
  137. $("textarea").on("input", function(){
  138. var text = $(this).val().trim(),
  139. len = text.length;
  140. $("#count").text(len);
  141. });
  142. //选择续方说明文本,直接将内容添加到textarea中
  143. $("#explain").on('click', '.text-tag', function(){
  144. var $this = $(this),
  145. text = $this.text(),
  146. tatext = $("textarea").val();
  147. if($this.hasClass("active")){
  148. $this.removeClass("active");
  149. var a = tatext.split(text);
  150. tatext = a.join("");
  151. $("textarea").val(tatext);
  152. $("#count").text(tatext.length);
  153. }else{
  154. $this.addClass("active");
  155. tatext += text;
  156. $("textarea").val(tatext);
  157. $("#count").text(tatext.length);
  158. }
  159. });
  160. var count = 0;
  161. $("#commit").on('click', function(){
  162. count ++;
  163. if(count > 1){
  164. return false;
  165. }
  166. //判断是否选择了咨询类型
  167. var consultType = $("#consultType").val();
  168. if(!consultType){
  169. dialog({
  170. contentType: 'tipsbox',
  171. content: '请选择咨询类型',
  172. skin:'bk-popup',
  173. closeTime: 2000
  174. }).showModal();
  175. count = 0;
  176. return false;
  177. }
  178. //判断是否存在处方信息
  179. if(!jw_code && !prescriptionCode){
  180. dialog({
  181. contentType: 'tipsbox',
  182. content: '请选择需要续方的处方记录',
  183. skin: 'bk-popup',
  184. closeTime: 2000
  185. }).showModal();
  186. count = 0;
  187. return false;
  188. }
  189. d.showModal();
  190. var url = "/patient/consult/addPrescriptionConsult",
  191. params = {
  192. jwCode: prescriptionCode || jw_code, //处方的code
  193. doctor: baseInfo.doctor,
  194. adminTeamId: baseInfo.adminTeamId,
  195. reason: $("textarea").val().trim(),
  196. type: $("#consultType").attr("data-type")
  197. };
  198. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  199. count = 0;
  200. d.close()
  201. if(res.status == 200){
  202. dialog({
  203. content: '已提交咨询,是否填写随访调查,作为医生审核续方的参考数据',
  204. okValue:'是',
  205. cancelValue: '否',
  206. cancel: function () {
  207. window.location.href = "prescription-consulting.html?consult="+res.data.consult+"&toUser="+patientCode;
  208. },
  209. ok: function (){
  210. window.location.href = "suifangdiaocha.html?consult="+res.data.consult+"&prescriptionCode="+res.data.relationCode;
  211. }
  212. }).showModal()
  213. }else{
  214. queryFailed(res)
  215. }
  216. })
  217. })
  218. // window.onpageshow = function(){
  219. // var isReload = window.localStorage.getItem('reload');
  220. // if(isReload){
  221. // window.localStorage.removeItem('reload');
  222. // var ua = navigator.userAgent;
  223. // if(ua.toLowerCase().indexOf('iphone') > -1){
  224. // window.location.reload();
  225. // }
  226. // }
  227. // }
  228. }
  229. function queryFailed(res, message){
  230. d.close();
  231. if(message){
  232. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  233. }else{
  234. if (res && res.msg) {
  235. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  236. } else {
  237. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  238. }
  239. }
  240. }