var Request = GetRequest(); var checktype=false; var loading = dialog({ contentType: 'load', skin: 'bk-popup' }); var vmodel = null; ;(function() { new Vue({ el: "#app", data: { dataList:[], cardId:Request.id, payMoney:"", repayAmout:Request.repayAmout, cardNo:"", paytype:"1", //paytype 1为门诊缴费 2为住院缴费 surplusMoney:"", data:{}, code:"", cardlenght:0, ischangeCard:false, _payMoney:"", }, mounted: function() { var vm = this vmodel = vm loading.showModal(); if(Request.openid&&Request.openid!="undefined"&&Request.openid!="123456"){ saveAgentOpenid(Request.openid); } checkUserAgent(); vm.paytype=Request.paytype?Request.paytype:"1" // vm.checkType() $(".c-ser-input").focus() }, methods: { //获取列表数据 getData:function(){ var vm=this sendPost("patient/card/getCardList", {patient:vm.code}, "json", "get",function(){ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res){ if(res.status == 200){ if(res.data.length>0){ vm.cardlenght=res.data.length var cardList=[] _.each(res.data,function(obj,idx){ sendPost("patient/card/getCardInfo", {id:obj.id}, "json", "get",function(){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res1){ if(res1.status == 200){ cardList.push(res1.data) }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show(); } }) }) if(cardList.length==res.data.length){ vm.comfireCardInfo(cardList) }else{ var t = setInterval(function(){ if(cardList.length==res.data.length){ clearInterval(t) loading.close(); vm.comfireCardInfo(cardList) } },200); } }else{ dialog({ content: "请先绑定就诊卡!", okValue: '确定', ok: function(){ window.location.href='../../payment/html/patientIDCards.html'; }, }).showModal() } }else{ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show(); } }) }, //确认该页支付卡 comfireCardInfo:function(cardList){ var vm=this if(Request.id){ vm.data=cardList.filter(function(item){ return item.id==Request.id && vm.hasInpCardNo(item) })[0] if(!vm.data){ vm.data=cardList.filter(function(item){ return item.isDefault==1 && vm.hasInpCardNo(item) })[0] } }else{ vm.data=cardList.filter(function(item){ return item.isDefault==1 && vm.hasInpCardNo(item) })[0] } if(!vm.data){ if(vm.paytype==2){ var ispass=_.every(cardList,function(obj,idx){ vm.data=obj var aaaa=vm.hasInpCardNo(obj) return !vm.hasInpCardNo(obj) }) if(ispass){ dialog({ content: "请选择含住院的就诊卡!", okValue: '确定', ok: function(){ window.location.href='../../payment/html/patientIDCards.html'; }, }).showModal() } }else{ vm.data=cardList[0] } } vm.cardId=vm.data.id vm.setCardInfo() }, setCardInfo:function(){ var vm=this if(vm.paytype=="2"){ vm.surplusMoney=vm.data.cardInpMoney?vm.data.cardInpMoney:0 vm.cardNo=vm.data.inpCardNo if(vm.data.type=="2"){ vm.cardNo=vm.data.inpCardNo.substr(0,1)+"*******"+vm.data.inpCardNo.substr(vm.data.inpCardNo.length-4,4) } }else{ vm.surplusMoney=vm.data.cardMoney?vm.data.cardMoney:0 vm.cardNo=vm.data.cardNo if(vm.data.type=="2"){ vm.cardNo=vm.data.cardNo.substr(0,1)+"*******"+vm.data.cardNo.substr(vm.data.cardNo.length-4,4) } } if(Request.repayAmout){ //从缴费结算进入 vm.payMoney=parseFloat(vm.repayAmout-vm.surplusMoney).toFixed(2) vm._payMoney=vm.payMoney } }, //去支付 toPayment:function(){ var vm=this if(vm.payMoney&&vm.payMoney>0){ if(Request.repayAmout&&parseFloat(vm._payMoney)>parseFloat(vm.payMoney)){ //从缴费结算进入,若支付金额少于预付则弹框提示 dialog({ content: "金额低于补差费用"+vm._payMoney+"元,请修改后支付。", okValue: '好的', ok: function() { vm.payMoney=vm._payMoney }, }).showModal() }else{ loading.showModal(); // vm.wxReady() if(judgeWxVersion()){ vm.getWeixinSign() } } }else{ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入正确的充值金额'}).show(); } }, //获得微信sdk信息 getWeixinSign:function() { var vm=this var params = {}; params.pageUrl = window.location.href; sendPost("weixin/getSign", params, "json", "post",function(){ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res){ if(res.status == 200) { var timestamp = res.data.timestamp; var noncestr = res.data.noncestr; var signature = res.data.signature; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: appId, // 必填,公众号的唯一标识 timestamp: timestamp, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature, // 必填,签名,见附录1 jsApiList: [ 'chooseWXPay', 'checkJsApi' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ vm.wxReady() }) }else{ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } }) }, wxReady:function(){ var vm=this var cardNo=vm.cardNo if(vm.data.type=="2"){ if(vm.paytype=="2"){ cardNo=vm.data.inpCardNo }else{ cardNo=vm.data.cardNo } } var params = { patient:vm.data.patient, healthNo:cardNo, healthType:vm.paytype, payAmount:parseFloat(vm.payMoney).toFixed(2), spbillCreateIp:returnCitySN["cip"], // code:getUrlParam("code"), openid:JSON.parse(localStorage.getItem("wlyyAgent")).openid }; sendPost("third/hy/pay/createPayOrder", params, "json", "post",function(){ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res){ if(res.status == 200) { loading.close(); var data = res.data; wx.chooseWXPay({ appId:data.appId, timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位 package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***) signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' paySign: data.sign, // 支付签名 success: function (res) { // 支付成功后的回调函数 if(Request.repayAmout){ //从缴费结算进入,直接进行缴费结算 window.location.href = "../../payment/html/repaymentResult.html?seqNo="+data.seqNo+"&patientName=" + vm.data.name + "&healthNo=" + cardNo + "&payAmount=" + vm.repayAmout + "&createDate=" + getNowFormatDate() + "&cardId=" + vm.cardId; // vm.torePay() }else{ window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo+"&payStatus=1&cardId="+vm.cardId; }                                 }, cencel:function(res){ // 支付取消回调函数 //alert("支付过程中用户取消"); }, fail: function(res){ // 支付失败回调函数 var errorparams={seqNo:data.seqNo,wxErrorMsg:res.errMsg} sendPost("third/hy/pay/setPayLogWxFail", errorparams, "json", "post",function(){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res){ window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo+"&payStatus=2&cardId="+vm.cardId; }) } }); }else{ loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } }) }, //缴费结算 torePay: function() { var vm = this var reloading = dialog({ contentType: 'load', skin: 'bk-popup', content:'缴费结算中...' }); reloading.showModal(); sendPost("/third/hy/paySettle/outpSettle", { hisId: vm.data.hisId }, "json", "get", function() { reloading.close(); dialog({ contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '请求失败' }).show(); }, function(res) { reloading.close(); if(res.status == 200) { if(res.data.code == 0) { window.location.href = "../../payment/html/repaymentResult.html?seqNo="+data.seqNo+"patientName=" + vm.data.name + "&healthNo=" + vm.cardNo + "&payAmount=" + vm.repayAmout + "&createDate=" + getNowFormatDate() + "&cardId=" + vm.cardId; } } else { dialog({ contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg || '数据查询失败' }).show(); } }) }, //强制设定最多只能输入两位小数 checkNumber:function(payMoney){ var myreg=/^[0][0-9]{1}$/; if(myreg.test(payMoney)){ payMoney="0" } this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null if(this.payMoney>20000){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:"支付金额不得超过20000"}).show(); this.payMoney=20000 } }, hasInpCardNo:function(item){ var vm=this var ispass=true if(vm.paytype==2){ if(item.inpCardNo&&(item.inpStatus=="0"||item.inpStatus=="1")){ ispass=true }else{ ispass=false } } return ispass }, //更改支付卡(门诊/住院) changePayType:function(paytype){ window.location.href='../../payment/html/payment.html?id='+this.cardId+'&paytype='+paytype; }, //跳转切换就诊卡 changeCards:function(){ window.location.href='../../payment/html/changeCards.html?pre=payment&paytype='+this.paytype; }, //判断是否验证登录通过 checkType:function(){ var vm=this var timer = setInterval(function(){ if(checktype){ clearInterval(timer); vm.getData() } },10); }, }, }) })() function queryInit(){ checktype=true vmodel.code=JSON.parse(localStorage.getItem("wlyyAgent")).uid vmodel.getData() } function getUrlParam(name){ //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)"); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //返回参数值 if (r!=null) return unescape(r[2]); return null; } //判断微信版本号 function judgeWxVersion(name){ var ispass=false var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i) if(!wechatInfo) { loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show(); } else { if ( wechatInfo[1] < "5.0" ) { loading.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show(); }else{ ispass=true } } return ispass } function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); if(month >= 1 && month <= 9) { month = "0" + month; } if(strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); var currentdate = year + seperator1 + month + seperator1 + strDate + " " + hour + ":" + minute + ":" + second; return currentdate; }