prescription-detail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. jwHospital = prescription.jwHospital;
  107. jwDoctorCode = prescription.jwDoctorCode;
  108. jwCode = prescription.jwCode;
  109. if(res.data.followup){
  110. fv_id = res.data.followup.id;
  111. }
  112. var diagnosisNames = _.pluck(diagnosis,'name').join('、')
  113. prescriptionDetailApis.getPrescription({
  114. data: {
  115. code: jwCode,
  116. patient: patient.code
  117. }
  118. }).then(function(res) {
  119. if(res.status == 200) {
  120. if(isLeader) {
  121. getDataPromises().then(function(responses) {
  122. var deptRes = responses[0],
  123. feeRes = responses[1],
  124. authRes = responses[2],
  125. reasonRes = responses[3];
  126. $main.html(template('detailTmpl',$.extend({}, detailData , {
  127. primary: res.data,
  128. diagnosisNames: diagnosisNames,
  129. depts: deptRes.data,
  130. feeRes: feeRes.data,
  131. isAuthentication: authRes.data.type == 4,
  132. isLeader: isLeader,
  133. reasonTypes: reasonRes.data
  134. })))
  135. bindEvents()
  136. }).catch(function(e) {
  137. showErrorMsg('初始化失败')
  138. })
  139. } else {
  140. $main.html(template('detailTmpl',$.extend({}, detailData , {
  141. primary: res.data,
  142. diagnosisNames: diagnosisNames,
  143. isLeader: isLeader
  144. })))
  145. bindEvents()
  146. }
  147. }else {
  148. showErrorMsg(res.msg)
  149. }
  150. }).catch(function(e){
  151. console && console.error(e)
  152. })
  153. } else {
  154. showErrorMsg(res.msg)
  155. }
  156. }).catch(function(e){
  157. console && console.error(e)
  158. })
  159. function bindEvents() {
  160. $('#auditResultSel').on('change',function() {
  161. var value = $(this).val();
  162. if(value == 1) {
  163. $('#disagreeAudit').hide();
  164. $('#agreeAudit').show();
  165. } else if(value == 2) {
  166. $('#agreeAudit').hide();
  167. $('#disagreeAudit').show();
  168. } else {
  169. $('#agreeAudit').hide();
  170. $('#disagreeAudit').hide();
  171. }
  172. })
  173. $('#reviewBtn').on('click',function() {
  174. var result = $('#auditResultSel').val();
  175. var data = {
  176. code: prescriptionCode, // 续方CODE
  177. reason: '', // 不同意原因
  178. reasonCode: '', // 不同意原因CODE
  179. state: '', // 1同意,2不同意
  180. dept: '', // 科室
  181. registerFee: '', // 诊金
  182. rateTypeCode: '' // 诊金类型
  183. }
  184. if(result == 1) { // 审核通过
  185. if(!checkAgreeInputs()) {
  186. return ;
  187. }
  188. $('#reviewBtn').attr('disabled','disabled')
  189. var params ={
  190. strRealNameSoftCertCalledPasswd: $('#reviewPassword').val(),
  191. strOriginalData:JSON.stringify(getStrOriginalData()),
  192. prescriptionCode:prescriptionCode
  193. }
  194. prescriptionDetailApis.requestRealNameSoftCertAndSign({
  195. data: params
  196. }).then(function(res) {
  197. if(res.status==200 && res.data){
  198. var feesel = $('#feeSel').val().split(' ');
  199. prescriptionDetailApis.reviewPrescription({
  200. data: {
  201. code: prescriptionCode, // 续方CODE
  202. state: 1, // 1同意,2不同意
  203. dept: $('#deptSel').val(), // 科室
  204. registerFee: feesel[1], // 诊金
  205. rateTypeCode: feesel[0] // 诊金类型
  206. }
  207. }).then(function(res) {
  208. if(res.status == 200 && res.data){
  209. // showSuccessMsg('提交成功')
  210. // setTimeout(function() {
  211. // location.reload(true)
  212. // }, 2000)
  213. dialog({
  214. content: "提交审核成功,记得去APP完成该居民的随访哦",
  215. okValue: "我知道了",
  216. ok: function(){
  217. location.reload(true)
  218. }
  219. }).showModal();
  220. } else {
  221. showErrorMsg(res.msg)
  222. $('#reviewBtn').removeAttr('disabled')
  223. }
  224. })
  225. } else {
  226. showErrorMsg(res.msg)
  227. $('#reviewBtn').removeAttr('disabled')
  228. }
  229. }).catch(function(e) {
  230. showErrorMsg(e)
  231. })
  232. } else if(result == 2){ // 审核不通过
  233. if(!checkDisAgreeInputs()) {
  234. return ;
  235. }
  236. var reason = $('#disagreeReason').val();
  237. var reasonType = _.map($('#adjustReason li.active'),function(el) {
  238. return $(el).attr('data-code')
  239. }).join(',');
  240. prescriptionDetailApis.reviewPrescription({
  241. data: {
  242. code: prescriptionCode, // 续方CODE
  243. state: 2, // 1同意,2不同意
  244. reason: reason || "-", // 不同意原因
  245. reasonCode: reasonType // 不同意原因CODE
  246. }
  247. }).then(function(res) {
  248. if(res.status == 200 && res.data){
  249. showSuccessMsg('提交成功')
  250. setTimeout(function() {
  251. location.reload(true)
  252. }, 2000)
  253. } else {
  254. $('#reviewBtn').removeAttr('disabled')
  255. }
  256. }).catch(function(e) {
  257. showErrorMsg(e)
  258. })
  259. } else {
  260. showErrorMsg("请选择审核结果")
  261. }
  262. })
  263. $('#editBtn').on('click',function() {
  264. location.href = 'prescription-adjustment.html?code='+prescriptionCode
  265. })
  266. $('#backBtn').on('click',function() {
  267. if(from == 'tab') {
  268. top.toPrePrescriptionTab && top.toPrePrescriptionTab()
  269. } else {
  270. history.go(-1);
  271. }
  272. })
  273. $('#adjustReason').on('click','li',function() {
  274. if($(this).hasClass('active')) {
  275. $(this).removeClass('active')
  276. } else {
  277. $(this).addClass('active')
  278. }
  279. setDisagreeReason()
  280. })
  281. calcWorldWithTextarea()
  282. }
  283. function setDisagreeReason() {
  284. var reasons = _.map($('#adjustReason li.active'),function(el) {
  285. return $.trim($(el).text())
  286. });
  287. // if(reasons && reasons.length) {
  288. $('#disagreeReason').val(reasons.join(','))
  289. $('#disagreeReason').focus()
  290. // }
  291. }
  292. function getStrOriginalData() {
  293. var imporMsg = {
  294. prescription: {}
  295. };
  296. imporMsg.prescription.jwCode = strOriginalData.prescription.jwCode;
  297. imporMsg.prescription.patientName = strOriginalData.prescription.patientName;
  298. imporMsg.prescription.doctorName = strOriginalData.prescription.doctorName;
  299. imporMsg.prescription.diagnosis = strOriginalData.diagnosis;
  300. var arr = _.map(strOriginalData.prescriptionInfo,function(item){
  301. return _.pick(item, 'drugCode','drugName','jwSubCode','physicAmount','physicAmountUnit','physicAmountUnitName');
  302. })
  303. imporMsg.prescription.prescriptionInfo = arr;
  304. return imporMsg;
  305. }
  306. function checkAgreeInputs() {
  307. var fee = $('#feeSel').val();
  308. var dept = $('#deptSel').val();
  309. var pwd = $('#reviewPassword').val();
  310. if(!fee) {
  311. showErrorMsg("请选择诊查费用")
  312. return false;
  313. } else if(!dept) {
  314. showErrorMsg("请选择开方科室")
  315. return false;
  316. } else if(!pwd) {
  317. showErrorMsg("请输入审方密码")
  318. return false;
  319. }
  320. return true;
  321. }
  322. function checkDisAgreeInputs() {
  323. var reason = $('#disagreeReason').val();
  324. if(!reason) {
  325. showErrorMsg("请输入不通过原因")
  326. return false;
  327. }
  328. return true;
  329. }
  330. function getDataPromises() {
  331. return Promise.all([
  332. prescriptionDetailApis.getDeptList({
  333. data: {
  334. jwHospital: jwHospital,
  335. jwDoctorCode: jwDoctorCode
  336. }
  337. }),
  338. prescriptionDetailApis.getRegisterRee({
  339. data: {
  340. jwHospital: jwHospital,
  341. jwDoctorCode: jwDoctorCode
  342. }
  343. }),
  344. prescriptionDetailApis.isAuthentication({}),
  345. prescriptionDetailApis.getReasonByType({
  346. data: {
  347. type: '0'
  348. }
  349. })
  350. ])
  351. }
  352. })