prescription-detail.js 11 KB

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