re-prescription_info.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. //var pagetype = 42;
  6. var request = GetRequest();
  7. var code = request.code; //从链接中获得处方code
  8. var toUser = request["toUser"];
  9. var toName = decodeURIComponent(request["toName"]);
  10. var openid = request["openid"];
  11. var represented = request["represented"];
  12. var userAgent = window.localStorage.getItem(agentName);
  13. var userInfo;
  14. var patientCode,
  15. patientName,
  16. prescriptionInfo;
  17. $(function(){
  18. isRepresent(function(){
  19. getInfo();
  20. bindEvents();
  21. popover()
  22. })
  23. userInfo = JSON.parse(userAgent);
  24. wxGetSign();
  25. })
  26. function popover() {
  27. var url = "/patient/prescription/pay/getPopups",
  28. params = {
  29. type: 1
  30. };
  31. sendPost(url, params, 'JSON', 'GET', queryFailed, function(res) {
  32. if(res.status == 200) {
  33. popoverData = res.data;
  34. } else {
  35. queryFailed(res);
  36. }
  37. })
  38. }
  39. function getInfo(){
  40. var url = "/patient/prescriptionInfo/getPrescriptionProcess",
  41. params = {code: code};
  42. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  43. if(res.status == 200){
  44. //填充居民信息
  45. var patientInfo = res.data.patient,
  46. patientHtml = "";
  47. patientCode = patientInfo.code;
  48. patientName = patientInfo.name;
  49. patientHtml = template('patientInfo_tmp', patientInfo);
  50. $("#patientInfo").empty().append(patientHtml);
  51. //填充续方信息
  52. var rePreInfo = res.data.prescription,
  53. rePreHtml = "";
  54. prescriptionInfo = res.data.prescription;
  55. rePreHtml = template('rePreInfo_tmp', rePreInfo);
  56. $("#rePreInfo").empty().append(rePreHtml);
  57. //如果已支付,则显示订单跟踪链接
  58. if(rePreInfo.status >= 50){
  59. $("#orderTracking").show();
  60. }
  61. //填充原处方的code, 基卫那边的处方code
  62. $("#prescriptionInfo").attr("data-code", rePreInfo.jwCode);
  63. $("#applyAgain").attr("data-code", rePreInfo.jwCode);
  64. //如果是待缴费,则前端开启计时器,显示缴费剩余时间
  65. if(rePreInfo.status == 40 || rePreInfo.status == 41){
  66. var time = getRemainTime(res.data.reviewed.reviewedTime); //时间戳
  67. createTimer(time);
  68. }
  69. //填充调整后处方的信息(先判断是否有调整后的处方记录)
  70. var isAdjust = res.data.isAdjust;
  71. if(isAdjust){
  72. var disease = "";
  73. for(var i=0; i<res.data.prescriptionDt.length; i++){
  74. var item = res.data.prescriptionDt[i];
  75. disease += item.healthProblemName+ ' ';
  76. }
  77. $("#diagnosis").text(disease); //填充诊断结果
  78. var drugsList = res.data.prescriptionInfo,
  79. html = "";
  80. html = template('drug_tmp', {list: drugsList});
  81. $("#drugsList").append(html);
  82. $("#changeDrugPanel").show();
  83. }else{
  84. $("#changeDrugPanel").hide();
  85. }
  86. //填充审核记录信息
  87. var checkInfo = res.data.reviewed,
  88. checkInfoHtml = "";
  89. checkInfoHtml = template('checkInfo_tmp', checkInfo);
  90. $('#checkInfo').empty().append(checkInfoHtml);
  91. //根据审核状态,控制底部按钮的显示
  92. var checkStatus = res.data.reviewed.status; //1审核通过,0待审核,-1审核不通过,-2无效的审核
  93. if(checkStatus == 0){
  94. //待审核,判断续方的状态
  95. //(-3 支付过期 -2 患者自己取消 )续方取消,
  96. if(rePreInfo.status == '-3' || rePreInfo.status == '-2'){
  97. $("#cancel").hide();
  98. }else{
  99. $("#cancel").show();
  100. }
  101. }else if(checkStatus == 1){
  102. if(rePreInfo.status == 40 || rePreInfo.status == 41){
  103. $("#cancel").show();
  104. }else{
  105. $("#cancel").hide();
  106. }
  107. }else{
  108. $("#applyAgain").show();
  109. }
  110. }else{
  111. queryFailed(res);
  112. }
  113. });
  114. }
  115. /**
  116. * 获得剩余时间
  117. * @param {string} sT 续方审核通过的时间
  118. */
  119. function getRemainTime(st){
  120. //审核通过后,患者有24小时的时间来支付
  121. var arr = st.split(/[- : \/]/);
  122. var d = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]),
  123. now = new Date(),
  124. us = parseInt((now.getTime() - d.getTime()) / 1000);
  125. //24小时对应的时间戳是 24*3600=86400
  126. return 86400 - us;
  127. }
  128. //创建计时器
  129. function createTimer(time){
  130. var timer;
  131. //原始储存值
  132. var setOri = time;
  133. //原始系统时间值
  134. var timeOri = (new Date()).getTime();
  135. //现在所剩时间值
  136. var setNow;
  137. cancelAnimationFrame(timer);
  138. timer = requestAnimationFrame(function fn(){
  139. //当前系统时间值
  140. var timeNow = (new Date()).getTime();
  141. //使系统时间的差值与设置时间的差值相等,来获得正常的时间变化
  142. setNow = setOri - Math.floor((timeNow - timeOri)/1000);
  143. var h = Math.floor(setNow/3600)
  144. m = Math.floor((setNow%3600)/60),
  145. s = Math.floor(setNow%60);
  146. var ms = m < 10 ? '0'+m : m,
  147. ss = s < 10 ? '0'+s : s;
  148. if(h > 0){
  149. $("#remainTime").text(h+"时"+ms+"分"+ss+"秒");
  150. }else if(m > 0){
  151. $("#remainTime").text(ms+"分"+ss+"秒");
  152. }else if(s > 0){
  153. $("#remainTime").text(ss+"秒");
  154. }
  155. timer = requestAnimationFrame(fn);
  156. if(setNow==0){
  157. cancelAnimationFrame(timer);
  158. timer = 0;
  159. $("#pay").find("a").remove();
  160. $("#pay").find('span').text('超时取消');
  161. //发送请求去取消续方申请
  162. // cancelPrescription();
  163. }
  164. })
  165. }
  166. function cancelPrescription(){
  167. var url = '/patient/prescriptionInfo/cancelPrescriotion',
  168. params = {code: code, reason: ''};
  169. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  170. });
  171. }
  172. //判断是否绑卡
  173. function bindCard(){
  174. d.show();
  175. var url = "/patient/bindCard";
  176. sendPost(url, {}, 'json', 'post', queryFailed, function(res){
  177. d.close();
  178. if(res.data.bindStatus == '000000'){ //已绑卡
  179. checkBindMobile(function() {
  180. //跳转去支付页面
  181. window.location.href = "payment.html?code="+code;
  182. })
  183. }else if(res.data.bindStatus == '030007'){//未绑卡
  184. //跳转去绑卡链接
  185. var bindUrl = res.data.sicardUrl;
  186. window.location.href = bindUrl;
  187. }
  188. });
  189. }
  190. function checkBindMobile(cb) {
  191. var url = "patient/prescription/pay/getPatientMobile"
  192. sendPost(url, {}, "json", "get", queryFailed, function(res) {
  193. if(res.status == 200) {
  194. if(res.data == 1) {
  195. cb && cb()
  196. } else {
  197. d.close();
  198. dialog({
  199. content: '您当前暂未绑定手机,无法在线缴费,请点击确认完成手机号码绑定',
  200. cancelValue: '取消',
  201. cancel: function() {},
  202. okValue: '确认',
  203. ok: function() {
  204. window.location.href = "../../home/html/bind-mobile.html"
  205. }
  206. }).showModal();
  207. }
  208. } else {
  209. queryFailed(res);
  210. }
  211. })
  212. }
  213. function bindEvents(){
  214. //点击跳转原处方页面
  215. $("#prescriptionInfo").on('click', function(){
  216. //需先获得原处方的id
  217. var code = $(this).attr("data-code");
  218. window.location.href = "prescription_detail.html?code="+code;
  219. });
  220. //订单跟踪
  221. $("#orderTracking").on('click', function(){
  222. window.location.href = "order_tracking.html?code="+code+"&toUser="+userInfo.uid;
  223. });
  224. //待支付按钮
  225. $("#rePreInfo").on('click', '#pay', function(){
  226. // window.location.href = "payment.html?code="+code;
  227. if(popoverData == 1) {
  228. layer.open({
  229. title:['温馨提示','font-weight:700;font-size:16px;height:40px;line-height:40px;'],
  230. content:'<div id="zhifu_div">\
  231. 需使用实名且与医保卡同名的微信公众号进行绑卡及支付,如为家人代支付,需先到市行政服务中心申请家庭共济关系后,才可以绑定家人的医保卡并支付哟~</div></br>\
  232. <div class="c-t-center mtb10">\
  233. <label class="input-group-checkbox" style="color: #40AFFE">\
  234. <div class="input-group-pack">\
  235. <input id="input_1" type="checkbox">\
  236. <span class="tick"></span>\
  237. </div>\
  238. 下次不再提醒\
  239. </label>\
  240. </div>',
  241. btn: ['<div id="jiaofei">开始支付</div>', '<div id="bujiaofei">暂不支付</div>'],
  242. shadeClose:false,
  243. yes:function(index){
  244. var checkedValue = $("#input_1").prop("checked"),
  245. val;
  246. if(checkedValue) {
  247. val = 0;
  248. } else {
  249. val = 1;
  250. }
  251. var url = "/patient/prescription/pay/savePopups",
  252. params = {
  253. type: 1,
  254. status: val
  255. };
  256. // alert(1)
  257. sendPost(url, params, 'JSON', 'POST', queryFailed, function(res){
  258. layer.close(index);
  259. //判断患者是否绑卡,未绑卡则跳转去绑卡页面
  260. bindCard();
  261. })
  262. },
  263. no:function(index){
  264. location.reload();
  265. }
  266. })
  267. }else {
  268. //判断患者是否绑卡,未绑卡则跳转去绑卡页面
  269. bindCard();
  270. }
  271. });
  272. //再次申请
  273. $("#applyAgain a").on('click', function(){
  274. //跳转去新增续方咨询页面
  275. var preCode = $("#applyAgain").attr("data-code");
  276. window.location.href = "../../yszx/html/add-prescription-consult.html?patient="+patientCode+"&name="+patientName+"&prescriptionCode="+preCode;
  277. });
  278. //跳转续方咨询页面
  279. $("#xfzx").on('click', function(){
  280. window.location.href = '../../yszx/html/prescription-consulting.html?consult='+prescriptionInfo.consult+'&type=8&toUser='+patientCode+'&doctor='+prescriptionInfo.doctor;
  281. });
  282. //取消续方
  283. $("#cancel a").on('click', function(){
  284. window.location.href = "re-prescription_cancel.html?code="+code;
  285. })
  286. window.onpageshow = function(){
  287. var pageback = window.localStorage.getItem("pageback");
  288. if(pageback && pageback == '1'){
  289. window.localStorage.removeItem("pageback");
  290. window.location.reload();
  291. }
  292. }
  293. }
  294. function queryFailed(res){
  295. d.close();
  296. if(res && res.msg) {
  297. dialog({
  298. contentType: 'tipsbox',
  299. skin: 'bk-popup',
  300. content: res.msg
  301. }).show();
  302. } else {
  303. dialog({
  304. contentType: 'tipsbox',
  305. skin: 'bk-popup',
  306. content: '加载失败'
  307. }).show();
  308. }
  309. }
  310. template.helper("getStatusName", function(status){
  311. return getStatusName(status);
  312. });
  313. template.helper("getStatusColor", function(status){
  314. return getStatusColor(status);
  315. });
  316. template.helper('getCheckResult', function(status){
  317. //1审核通过 0待审核 -1 审核不通过 -2无效审核
  318. var name = "";
  319. switch (status){
  320. case 1:
  321. name = '审核通过';
  322. break;
  323. case 0:
  324. name = '待审核';
  325. break;
  326. case -1:
  327. name = '审核不通过';
  328. break;
  329. case -2:
  330. name = "无效审核";
  331. break;
  332. default:
  333. break;
  334. }
  335. return name;
  336. });
  337. template.helper('getCheckResultColor', function(status){
  338. //1审核通过 0待审核 -1 审核不通过 -2无效审核
  339. var color = "";
  340. switch (status){
  341. case 1:
  342. color = 'c-success';
  343. break;
  344. case 0:
  345. color = 'c-waiting';
  346. break;
  347. case -1:
  348. case -2:
  349. color = 'c-error';
  350. break;
  351. default:
  352. break;
  353. }
  354. return color;
  355. })
  356. //获取微信信息,并配置微信api接口
  357. function wxGetSign(){
  358. var params = {};
  359. params.pageUrl = window.location.href;
  360. $.ajax(server + "weixin/getSign", {
  361. data: params,
  362. dataType: "json",
  363. type: "post",
  364. success: function(res){
  365. if (res.status == 200) {
  366. var t = res.data.timestamp;
  367. var noncestr = res.data.noncestr;
  368. var signature = res.data.signature;
  369. wx.config({
  370. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  371. appId: appId, // 必填,公众号的唯一标识
  372. timestamp: t, // 必填,生成签名的时间戳
  373. nonceStr: noncestr, // 必填,生成签名的随机串
  374. signature: signature,// 必填,签名,见附录1
  375. jsApiList: [
  376. 'closeWindow'
  377. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  378. });
  379. }
  380. }
  381. });
  382. }