prescription-detail.js 12 KB

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