prescription-detail.js 11 KB

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