payment.js 13 KB

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