userOrderPay.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var id=mobile.getUrlVars("id");
  2. var type = mobile.getUrlVars("type");
  3. var item;
  4. var money = 0;
  5. mui.init();
  6. mui.ready(function(){
  7. getMoney();
  8. $(".mui-input-row").on("tap",function(e){
  9. var list = $(this).find("input[type='radio']");
  10. list.each(function(){
  11. this.checked = true;
  12. });
  13. });
  14. $(".mui-btn-primary").on("tap",function(e){
  15. var i=-1;
  16. $('input[type="radio"]').each(function(){
  17. if(this.checked){
  18. i = $(this).parent().index();
  19. }
  20. });
  21. if(i==0){
  22. if(parseFloat(money)<parseFloat(item.order_amt)){
  23. layer.open({content: "余额不足",time: 3});
  24. return;
  25. }
  26. mobile.ajaxPost(base+'/userOrder/moneyPay',{id:id},function(json){
  27. if(json.success){
  28. history.replaceState(null, "", base+"/mobile/userOrderDetail.jsp?id="+id);
  29. location.href=base+"/mobile/userPayResult.jsp?id="+id+"&payType=20";
  30. }else{
  31. layer.open({content: json.msg,time: 3});
  32. }
  33. });
  34. }else{
  35. var url;
  36. if(type=="card"){
  37. url=base+'/userCardOrder/pay'
  38. }else{
  39. url=base+'/userOrder/pay';
  40. }
  41. mobile.ajaxPost(url,{id:id},function(json){
  42. if(json.success){
  43. var data=json.data;
  44. if (typeof WeixinJSBridge == "undefined"){
  45. if( document.addEventListener ){
  46. document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
  47. }else if (document.attachEvent){
  48. document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
  49. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
  50. }
  51. }else{
  52. onBridgeReady(data);
  53. }
  54. }else{
  55. layer.open({content: json.msg,time: 3});
  56. }
  57. });
  58. }
  59. });
  60. });
  61. function onBridgeReady(json){
  62. WeixinJSBridge.invoke(
  63. 'getBrandWCPayRequest',
  64. json,
  65. function(res){
  66. if(res.err_msg == "get_brand_wcpay_request:ok" ) {
  67. if(type=="card"){
  68. history.replaceState(null, "", base+"/mobile/userCard.jsp");
  69. }else{
  70. history.replaceState(null, "", base+"/mobile/userOrder.jsp?orderStatus=20");
  71. }
  72. location.href=base+"/mobile/userPayResult.jsp?id="+id+"&type="+type;
  73. }else{
  74. layer.open({content: '支付失败',time: 3});
  75. }
  76. }
  77. );
  78. }
  79. function getById(){
  80. if(type=="card"){
  81. document.getElementById("pay2").checked = true;
  82. $("#pay1").parents(".mui-radio").addClass("mui-hidden");
  83. }else{
  84. mobile.ajaxPost(base+'/userOrder/getById',{id:id},function(json){
  85. item = json.data;
  86. $(".mui-content-padded.color-red").html("待支付 ¥"+item.order_amt);
  87. if(parseFloat(money)>=parseFloat(item.order_amt)){
  88. document.getElementById("pay1").checked = true;
  89. }else{
  90. document.getElementById("pay2").checked = true;
  91. }
  92. });
  93. }
  94. }
  95. //获取余额
  96. function getMoney() {
  97. mobile.ajaxPost(base + '/userMoney/getMoney', {}, function(json) {
  98. money = json.data;
  99. $('#money').html("¥"+json.data);
  100. getById();
  101. },"");
  102. }