payment.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. var Request = GetRequest();
  2. var checktype=false;
  3. var loading = dialog({
  4. contentType: 'load',
  5. skin: 'bk-popup'
  6. });
  7. (function() {
  8. new Vue({
  9. el: "#app",
  10. data: {
  11. dataList:[],
  12. cardId:Request.id,
  13. payMoney:"",
  14. repayAmout:Request.repayAmout,
  15. cardNo:"",
  16. paytype:"1", //paytype 1为门诊缴费 2为住院缴费
  17. surplusMoney:"",
  18. data:{},
  19. code:"",
  20. cardlenght:0,
  21. ischangeCard:false,
  22. _payMoney:"",
  23. },
  24. mounted: function() {
  25. var vm = this
  26. loading.showModal();
  27. if(Request.openid&&Request.openid!="undefined"&&Request.openid!="123456"){
  28. saveAgentOpenid(Request.openid);
  29. }
  30. checkUserAgent();
  31. vm.code=JSON.parse(localStorage.getItem("wlyyAgent")).uid
  32. vm.paytype=Request.paytype?Request.paytype:"1"
  33. vm.checkType()
  34. $(".c-ser-input").focus()
  35. },
  36. methods: {
  37. //获取列表数据
  38. getData:function(){
  39. var vm=this
  40. sendPost("patient/card/getCardList", {patient:vm.code}, "json", "get",function(){
  41. loading.close();
  42. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  43. }, function(res){
  44. if(res.status == 200){
  45. if(res.data.length>0){
  46. vm.cardlenght=res.data.length
  47. var cardList=[]
  48. _.each(res.data,function(obj,idx){
  49. sendPost("patient/card/getCardInfo", {id:obj.id}, "json", "get",function(){
  50. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  51. }, function(res1){
  52. if(res1.status == 200){
  53. cardList.push(res1.data)
  54. }else{
  55. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  56. }
  57. })
  58. })
  59. if(cardList.length==res.data.length){
  60. vm.comfireCardInfo(cardList)
  61. }else{
  62. var t = setInterval(function(){
  63. if(cardList.length==res.data.length){
  64. loading.close();
  65. vm.comfireCardInfo(cardList)
  66. clearInterval(t)
  67. }
  68. },200);
  69. }
  70. }else{
  71. dialog({
  72. content: "请先绑定就诊卡!",
  73. okValue: '确定',
  74. ok: function(){
  75. window.location.href='../../payment/html/patientIDCards.html';
  76. },
  77. }).showModal()
  78. }
  79. }else{
  80. loading.close();
  81. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据获取失败'}).show();
  82. }
  83. })
  84. },
  85. //确认该页支付卡
  86. comfireCardInfo:function(cardList){
  87. var vm=this
  88. if(Request.id){
  89. vm.data=cardList.filter(function(item){
  90. return item.id==Request.id && vm.hasInpCardNo(item)
  91. })[0]
  92. if(!vm.data){
  93. vm.data=cardList.filter(function(item){
  94. return item.isDefault==1 && vm.hasInpCardNo(item)
  95. })[0]
  96. }
  97. }else{
  98. vm.data=cardList.filter(function(item){
  99. return item.isDefault==1 && vm.hasInpCardNo(item)
  100. })[0]
  101. }
  102. if(!vm.data){
  103. if(vm.paytype==2){
  104. var ispass=_.every(cardList,function(obj,idx){
  105. vm.data=obj
  106. var aaaa=vm.hasInpCardNo(obj)
  107. return !vm.hasInpCardNo(obj)
  108. })
  109. if(ispass){
  110. dialog({
  111. content: "请选择含住院的就诊卡!",
  112. okValue: '确定',
  113. ok: function(){
  114. window.location.href='../../payment/html/patientIDCards.html';
  115. },
  116. }).showModal()
  117. }
  118. }else{
  119. vm.data=cardList[0]
  120. }
  121. }
  122. vm.cardId=vm.data.id
  123. vm.setCardInfo()
  124. },
  125. setCardInfo:function(){
  126. var vm=this
  127. if(vm.paytype=="2"){
  128. vm.surplusMoney=vm.data.cardInpMoney?vm.data.cardInpMoney:0
  129. vm.cardNo=vm.data.inpCardNo
  130. if(vm.data.type=="2"){
  131. vm.cardNo=vm.data.inpCardNo.substr(0,1)+"*******"+vm.data.inpCardNo.substr(vm.data.inpCardNo.length-4,4)
  132. }
  133. }else{
  134. vm.surplusMoney=vm.data.cardMoney?vm.data.cardMoney:0
  135. vm.cardNo=vm.data.cardNo
  136. if(vm.data.type=="2"){
  137. vm.cardNo=vm.data.cardNo.substr(0,1)+"*******"+vm.data.cardNo.substr(vm.data.cardNo.length-4,4)
  138. }
  139. }
  140. if(Request.repayAmout){ //从缴费结算进入
  141. vm.payMoney=parseFloat(vm.repayAmout-vm.surplusMoney).toFixed(2)
  142. vm._payMoney=vm.payMoney
  143. }
  144. },
  145. //去支付
  146. toPayment:function(){
  147. var vm=this
  148. if(vm.payMoney&&vm.payMoney>0){
  149. if(Request.repayAmout&&parseFloat(vm._payMoney)>parseFloat(vm.payMoney)){ //从缴费结算进入,若支付金额少于预付则弹框提示
  150. dialog({
  151. content: "金额低于补差费用"+vm._payMoney+"元,请修改后支付。",
  152. okValue: '好的',
  153. ok: function() {
  154. vm.payMoney=vm._payMoney
  155. },
  156. }).showModal()
  157. }else{
  158. loading.showModal();
  159. // vm.wxReady()
  160. if(judgeWxVersion()){
  161. vm.getWeixinSign()
  162. }
  163. }
  164. }else{
  165. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入正确的充值金额'}).show();
  166. }
  167. },
  168. //获得微信sdk信息
  169. getWeixinSign:function() {
  170. var vm=this
  171. var params = {};
  172. params.pageUrl = window.location.href;
  173. sendPost("weixin/getSign", params, "json", "post",function(){
  174. loading.close();
  175. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  176. }, function(res){
  177. if(res.status == 200) {
  178. var timestamp = res.data.timestamp;
  179. var noncestr = res.data.noncestr;
  180. var signature = res.data.signature;
  181. wx.config({
  182. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  183. appId: appId, // 必填,公众号的唯一标识
  184. timestamp: timestamp, // 必填,生成签名的时间戳
  185. nonceStr: noncestr, // 必填,生成签名的随机串
  186. signature: signature, // 必填,签名,见附录1
  187. jsApiList: [
  188. 'chooseWXPay',
  189. 'checkJsApi'
  190. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  191. });
  192. wx.ready(function(){
  193. vm.wxReady()
  194. })
  195. }else{
  196. loading.close();
  197. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  198. }
  199. })
  200. },
  201. wxReady:function(){
  202. var vm=this
  203. var cardNo=vm.cardNo
  204. if(vm.data.type=="2"){
  205. if(vm.paytype=="2"){
  206. cardNo=vm.data.inpCardNo
  207. }else{
  208. cardNo=vm.data.cardNo
  209. }
  210. }
  211. var params = {
  212. patient:vm.data.patient,
  213. healthNo:cardNo,
  214. healthType:vm.paytype,
  215. payAmount:parseFloat(vm.payMoney).toFixed(2),
  216. spbillCreateIp:returnCitySN["cip"],
  217. // code:getUrlParam("code"),
  218. openid:JSON.parse(localStorage.getItem("wlyyAgent")).openid
  219. };
  220. sendPost("third/hy/pay/createPayOrder", params, "json", "post",function(){
  221. loading.close();
  222. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  223. }, function(res){
  224. if(res.status == 200) {
  225. loading.close();
  226. var data = res.data;
  227. wx.chooseWXPay({
  228. appId:data.appId,
  229. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  230. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  231. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  232. signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  233. paySign: data.sign, // 支付签名
  234. success: function (res) {
  235. // 支付成功后的回调函数
  236. if(Request.repayAmout){ //从缴费结算进入,直接进行缴费结算
  237. window.location.href = "../../payment/html/repaymentResult.html?seqNo="+data.seqNo+"&patientName=" + vm.data.name + "&healthNo=" + cardNo + "&payAmount=" + vm.repayAmout + "&createDate=" + getNowFormatDate() + "&cardId=" + vm.cardId;
  238. // vm.torePay()
  239. }else{
  240. window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo+"&payStatus=1&cardId="+vm.cardId;
  241. }                                
  242. },
  243. cencel:function(res){
  244. // 支付取消回调函数
  245. //alert("支付过程中用户取消");
  246. },
  247. fail: function(res){
  248. // 支付失败回调函数
  249. var errorparams={seqNo:data.seqNo,wxErrorMsg:res.errMsg}
  250. sendPost("third/hy/pay/setPayLogWxFail", errorparams, "json", "post",function(){
  251. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  252. }, function(res){
  253. window.location.href='../../payment/html/paymentResult.html?seqNo='+data.seqNo+"&payStatus=2&cardId="+vm.cardId;
  254. })
  255. }
  256. });
  257. }else{
  258. loading.close();
  259. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  260. }
  261. })
  262. },
  263. //缴费结算
  264. torePay: function() {
  265. var vm = this
  266. var reloading = dialog({
  267. contentType: 'load',
  268. skin: 'bk-popup',
  269. content:'缴费结算中...'
  270. });
  271. reloading.showModal();
  272. sendPost("/third/hy/paySettle/outpSettle", {
  273. hisId: vm.data.hisId
  274. }, "json", "get", function() {
  275. reloading.close();
  276. dialog({
  277. contentType: 'tipsbox',
  278. bottom: true,
  279. skin: 'bk-popup',
  280. content: '请求失败'
  281. }).show();
  282. }, function(res) {
  283. reloading.close();
  284. if(res.status == 200) {
  285. if(res.data.code == 0) {
  286. 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;
  287. }
  288. } else {
  289. dialog({
  290. contentType: 'tipsbox',
  291. bottom: true,
  292. skin: 'bk-popup',
  293. content: res.msg || '数据查询失败'
  294. }).show();
  295. }
  296. })
  297. },
  298. //强制设定最多只能输入两位小数
  299. checkNumber:function(payMoney){
  300. var myreg=/^[0][0-9]{1}$/;
  301. if(myreg.test(payMoney)){
  302. payMoney="0"
  303. }
  304. this.payMoney= (payMoney.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  305. if(this.payMoney>20000){
  306. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:"支付金额不得超过20000"}).show();
  307. this.payMoney=20000
  308. }
  309. },
  310. hasInpCardNo:function(item){
  311. var vm=this
  312. var ispass=true
  313. if(vm.paytype==2){
  314. if(item.inpCardNo&&(item.inpStatus=="0"||item.inpStatus=="1")){
  315. ispass=true
  316. }else{
  317. ispass=false
  318. }
  319. }
  320. return ispass
  321. },
  322. //更改支付卡(门诊/住院)
  323. changePayType:function(paytype){
  324. window.location.href='../../payment/html/payment.html?id='+this.cardId+'&paytype='+paytype;
  325. },
  326. //跳转切换就诊卡
  327. changeCards:function(){
  328. window.location.href='../../payment/html/changeCards.html?pre=payment&paytype='+this.paytype;
  329. },
  330. //判断是否验证登录通过
  331. checkType:function(){
  332. var vm=this
  333. var timer = setInterval(function(){
  334. if(checktype){
  335. clearInterval(timer);
  336. vm.getData()
  337. }
  338. },10);
  339. },
  340. },
  341. })
  342. })()
  343. function queryInit(){
  344. checktype=true
  345. }
  346. function getUrlParam(name){
  347. //构造一个含有目标参数的正则表达式对象
  348. var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  349. //匹配目标参数
  350. var r = window.location.search.substr(1).match(reg);
  351. //返回参数值
  352. if (r!=null) return unescape(r[2]); return null;
  353. }
  354. //判断微信版本号
  355. function judgeWxVersion(name){
  356. var ispass=false
  357. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  358. if(!wechatInfo) {
  359. loading.close();
  360. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前不是微信,不支持微信支付'}).show();
  361. }
  362. else
  363. {
  364. if ( wechatInfo[1] < "5.0" ) {
  365. loading.close();
  366. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'当前微信低于5.0,不支持微信支付,请升级后支付'}).show();
  367. }else{
  368. ispass=true
  369. }
  370. }
  371. return ispass
  372. }
  373. function getNowFormatDate() {
  374. var date = new Date();
  375. var seperator1 = "-";
  376. var year = date.getFullYear();
  377. var month = date.getMonth() + 1;
  378. var strDate = date.getDate();
  379. if(month >= 1 && month <= 9) {
  380. month = "0" + month;
  381. }
  382. if(strDate >= 0 && strDate <= 9) {
  383. strDate = "0" + strDate;
  384. }
  385. var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  386. var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  387. var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  388. var currentdate = year + seperator1 + month + seperator1 + strDate + " " + hour + ":" + minute + ":" + second;
  389. return currentdate;
  390. }