prescription-detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. $(function(){
  2. //获取团队信息
  3. var request = getRequest(),
  4. teamCode = request.id,
  5. docInfo = JSON.parse(window.localStorage.getItem('docInfo')),
  6. isLeader = isTeamLeader() && (teamCode == docInfo.adminTeamCode),
  7. prescriptionCode = request.code,
  8. from = request.from, // 判断是否是tab页加载进来
  9. fromTabIdx = request.fromTabIdx,
  10. jwCode;
  11. var $main = $('#main');
  12. var jwHospital = '',
  13. jwDoctorCode = '';
  14. // 认证专用
  15. var strOriginalData;
  16. template.helper('idcardWidthStar',function(idcard) {
  17. if(idcard) {
  18. if(idcard.length == 18) {
  19. return idcard.substring(0,8) +'********'+idcard.substring(16,18)
  20. } else {
  21. idcard.substring(0,5) +'********'+idcard.substring(16,18)
  22. }
  23. }
  24. return "";
  25. })
  26. template.config("escape", false);
  27. template.helper('getStatusName',function(status) {
  28. return getStatusName(status)
  29. })
  30. template.helper('getReviewResultName',function(status) {
  31. return getReviewResultName(status)
  32. })
  33. template.helper('setStatus',function(o){
  34. if(o == -3){ return '<span style="color:#999">续方取消(24小时未支付)</span>' }
  35. if(o == -2){ return '<span style="color:#999">续方取消(居民主动取消)</span>' }
  36. if(o == -1){ return '<span style="color:#ff4c4c">审核未通过</span>' }
  37. if(o == 0 || o == 10){ return '<span style="color:#ffa54b">审核中</span>' }
  38. if(o == 2){ return '<span style="color:#ffa54b">调整中</span>' }
  39. if(o == 3){ return '<span style="color:#ffa54b">调整成功/待ca认证</span>' }
  40. if(o == 4){ return '<span style="color:#ffa54b">调整失败</span>' }
  41. if(o == 20){ return '<span style="color:#ffa54b">药师审核中</span>' }
  42. if(o == 21){ return '<span style="color:#ff4c4c">药师审核失败</span>' }
  43. if(o == 30){ return '<span style="color:#ffa54b">开方中</span>' }
  44. if(o == 31){ return '<span style="color:#ff4c4c">开方失败</span>' }
  45. if(o == 40 || o == 41){ return '<span style="color:#db6bbd">待支付</span>' }
  46. if(o == 50){ return '<span style="color:#ffa54b">配药中</span>' }
  47. if(o == 60){ return '<span style="color:#db6bbd">等待领药</span>' }
  48. if(o == 61 || o == 62 || o == 65 || o == 69){ return '<span style="color:#06bf04">配送中</span>' }
  49. if(o == 100){ return '<span style="color:#17b3ec">已完成</span>' }
  50. })
  51. template.helper('setRestTime',function(minDate,sDate){
  52. if(!minDate || !sDate) {
  53. return ""
  54. }
  55. var now = getNowDate();
  56. var createDate = sDate.split(' ');
  57. var diff = getDays(createDate[0],now);
  58. if(diff<minDate){
  59. return '<span style="color:#17b3ec">'+(minDate-diff)+'天</span>'
  60. }else{
  61. return '<span style="color:#ff4c4c">已用完</span>'
  62. }
  63. })
  64. //相隔几天
  65. function getDays(sDate,eDate){
  66. var oDate1;
  67. var oDate2;
  68. var iDays;
  69. oDate1= sDate.split("-");
  70. oDate2= eDate.split("-");
  71. var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
  72. var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
  73. iDays = parseInt(Math.abs(strDateE - strDateS ) / 1000 / 60 / 60 /24)
  74. return iDays ;
  75. }
  76. //现在时间
  77. function getNowDate() {
  78. var date = new Date();
  79. var year = date.getFullYear();
  80. var month = date.getMonth() + 1;
  81. var day = date.getDate();
  82. var hour = date.getHours();
  83. var minute = date.getMinutes();
  84. var second = date.getSeconds();
  85. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  86. }
  87. prescriptionDetailApis.getContinuedPrescriptionAsDoctor({
  88. data: {
  89. code: prescriptionCode, // 续方CODE
  90. type: isLeader?1:2 // 是否为团队长,1:是,2:否
  91. }
  92. }).then(function(res) {
  93. if(res.status == 200) {
  94. var detailData = res.data;
  95. var prescription = detailData.prescription;
  96. var diagnosis = detailData.diagnosis;
  97. var patient = detailData.patient;
  98. strOriginalData = detailData;
  99. jwHospital = prescription.jwHospital;
  100. jwDoctorCode = prescription.jwDoctorCode;
  101. jwCode = prescription.jwCode;
  102. var diagnosisNames = _.pluck(diagnosis,'name').join('、')
  103. prescriptionDetailApis.getPrescription({
  104. data: {
  105. code: jwCode,
  106. patient: patient.code
  107. }
  108. }).then(function(res) {
  109. if(res.status == 200) {
  110. if(isLeader) {
  111. getDataPromises().then(function(responses) {
  112. var deptRes = responses[0],
  113. feeRes = responses[1],
  114. authRes = responses[2],
  115. reasonRes = responses[3];
  116. $main.html(template('detailTmpl',$.extend({}, detailData , {
  117. primary: res.data,
  118. diagnosisNames: diagnosisNames,
  119. depts: deptRes.data,
  120. feeRes: feeRes.data,
  121. isAuthentication: authRes.data.type == 4,
  122. isLeader: isLeader,
  123. reasonTypes: reasonRes.data
  124. })))
  125. bindEvents()
  126. }).catch(function(e) {
  127. showErrorMsg('初始化失败')
  128. })
  129. } else {
  130. $main.html(template('detailTmpl',$.extend({}, detailData , {
  131. primary: res.data,
  132. diagnosisNames: diagnosisNames,
  133. isLeader: isLeader
  134. })))
  135. bindEvents()
  136. }
  137. }else {
  138. showErrorMsg(res.msg)
  139. }
  140. }).catch(function(e){
  141. console && console.error(e)
  142. })
  143. } else {
  144. showErrorMsg(res.msg)
  145. }
  146. }).catch(function(e){
  147. console && console.error(e)
  148. })
  149. function bindEvents() {
  150. $('#auditResultSel').on('change',function() {
  151. var value = $(this).val();
  152. if(value == 1) {
  153. $('#disagreeAudit').hide();
  154. $('#agreeAudit').show();
  155. } else if(value == 2) {
  156. $('#agreeAudit').hide();
  157. $('#disagreeAudit').show();
  158. } else {
  159. $('#agreeAudit').hide();
  160. $('#disagreeAudit').hide();
  161. }
  162. })
  163. $('#reviewBtn').on('click',function() {
  164. var result = $('#auditResultSel').val();
  165. var data = {
  166. code: prescriptionCode, // 续方CODE
  167. reason: '', // 不同意原因
  168. reasonCode: '', // 不同意原因CODE
  169. state: '', // 1同意,2不同意
  170. dept: '', // 科室
  171. registerFee: '', // 诊金
  172. rateTypeCode: '' // 诊金类型
  173. }
  174. if(result == 1) { // 审核通过
  175. if(!checkAgreeInputs()) {
  176. return ;
  177. }
  178. $('#reviewBtn').attr('disabled','disabled')
  179. var params ={
  180. strRealNameSoftCertCalledPasswd: $('#reviewPassword').val(),
  181. strOriginalData:JSON.stringify(getStrOriginalData()),
  182. prescriptionCode:prescriptionCode
  183. }
  184. prescriptionDetailApis.requestRealNameSoftCertAndSign({
  185. data: params
  186. }).then(function(res) {
  187. if(res.status==200 && res.data){
  188. var feesel = $('#feeSel').val().split(' ');
  189. prescriptionDetailApis.reviewPrescription({
  190. data: {
  191. code: prescriptionCode, // 续方CODE
  192. state: 1, // 1同意,2不同意
  193. dept: $('#deptSel').val(), // 科室
  194. registerFee: feesel[1], // 诊金
  195. rateTypeCode: feesel[0] // 诊金类型
  196. }
  197. }).then(function(res) {
  198. if(res.status == 200 && res.data){
  199. showSuccessMsg('提交成功')
  200. setTimeout(function() {
  201. location.reload(true)
  202. }, 2000)
  203. } else {
  204. showErrorMsg(res.msg)
  205. $('#reviewBtn').removeAttr('disabled')
  206. }
  207. })
  208. } else {
  209. showErrorMsg(res.msg)
  210. $('#reviewBtn').removeAttr('disabled')
  211. }
  212. }).catch(function(e) {
  213. showErrorMsg(e)
  214. })
  215. } else if(result == 2){ // 审核不通过
  216. if(!checkDisAgreeInputs()) {
  217. return ;
  218. }
  219. var reason = $('#disagreeReason').val();
  220. var reasonType = _.map($('#adjustReason li.active'),function(el) {
  221. return $(el).attr('data-code')
  222. }).join(',');
  223. prescriptionDetailApis.reviewPrescription({
  224. data: {
  225. code: prescriptionCode, // 续方CODE
  226. state: 2, // 1同意,2不同意
  227. reason: reason || "-", // 不同意原因
  228. reasonCode: reasonType // 不同意原因CODE
  229. }
  230. }).then(function(res) {
  231. if(res.status == 200 && res.data){
  232. showSuccessMsg('提交成功')
  233. setTimeout(function() {
  234. location.reload(true)
  235. }, 2000)
  236. } else {
  237. $('#reviewBtn').removeAttr('disabled')
  238. }
  239. }).catch(function(e) {
  240. showErrorMsg(e)
  241. })
  242. } else {
  243. showErrorMsg("请选择审核结果")
  244. }
  245. })
  246. $('#editBtn').on('click',function() {
  247. location.href = 'prescription-adjustment.html?code='+prescriptionCode
  248. })
  249. $('#backBtn').on('click',function() {
  250. if(from == 'tab') {
  251. top.toPrePrescriptionTab && top.toPrePrescriptionTab()
  252. } else {
  253. history.go(-1);
  254. }
  255. })
  256. $('#adjustReason').on('click','li',function() {
  257. if($(this).hasClass('active')) {
  258. $(this).removeClass('active')
  259. } else {
  260. $(this).addClass('active')
  261. }
  262. setDisagreeReason()
  263. })
  264. calcWorldWithTextarea()
  265. }
  266. function setDisagreeReason() {
  267. var reasons = _.map($('#adjustReason li.active'),function(el) {
  268. return $.trim($(el).text())
  269. });
  270. // if(reasons && reasons.length) {
  271. $('#disagreeReason').val(reasons.join(','))
  272. $('#disagreeReason').focus()
  273. // }
  274. }
  275. function getStrOriginalData() {
  276. var imporMsg = {
  277. prescription: {}
  278. };
  279. imporMsg.prescription.jwCode = strOriginalData.prescription.jwCode;
  280. imporMsg.prescription.patientName = strOriginalData.prescription.patientName;
  281. imporMsg.prescription.doctorName = strOriginalData.prescription.doctorName;
  282. imporMsg.prescription.diagnosis = strOriginalData.diagnosis;
  283. var arr = _.map(strOriginalData.prescriptionInfo,function(item){
  284. return _.pick(item, 'drugCode','drugName','jwSubCode','physicAmount','physicAmountUnit','physicAmountUnitName');
  285. })
  286. imporMsg.prescription.prescriptionInfo = arr;
  287. return imporMsg;
  288. }
  289. function checkAgreeInputs() {
  290. var fee = $('#feeSel').val();
  291. var dept = $('#deptSel').val();
  292. var pwd = $('#reviewPassword').val();
  293. if(!fee) {
  294. showErrorMsg("请选择诊查费用")
  295. return false;
  296. } else if(!dept) {
  297. showErrorMsg("请选择开方科室")
  298. return false;
  299. } else if(!pwd) {
  300. showErrorMsg("请输入审方密码")
  301. return false;
  302. }
  303. return true;
  304. }
  305. function checkDisAgreeInputs() {
  306. var reason = $('#disagreeReason').val();
  307. if(!reason) {
  308. showErrorMsg("请输入不通过原因")
  309. return false;
  310. }
  311. return true;
  312. }
  313. function getDataPromises() {
  314. return Promise.all([
  315. prescriptionDetailApis.getDeptList({
  316. data: {
  317. jwHospital: jwHospital,
  318. jwDoctorCode: jwDoctorCode
  319. }
  320. }),
  321. prescriptionDetailApis.getRegisterRee({
  322. data: {
  323. jwHospital: jwHospital,
  324. jwDoctorCode: jwDoctorCode
  325. }
  326. }),
  327. prescriptionDetailApis.isAuthentication({}),
  328. prescriptionDetailApis.getReasonByType({
  329. data: {
  330. type: '0'
  331. }
  332. })
  333. ])
  334. }
  335. })