prescription-detail.js 9.5 KB

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