123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- var id=mobile.getUrlVars("id");
- var type = mobile.getUrlVars("type");
- var item;
- var money = 0;
- mui.init();
- mui.ready(function(){
- getMoney();
- $(".mui-input-row").on("tap",function(e){
- var list = $(this).find("input[type='radio']");
- list.each(function(){
- this.checked = true;
- });
- });
- $(".mui-btn-primary").on("tap",function(e){
- var i=-1;
- $('input[type="radio"]').each(function(){
- if(this.checked){
- i = $(this).parent().index();
- }
- });
- if(i==0){
- if(parseFloat(money)<parseFloat(item.order_amt)){
- layer.open({content: "余额不足",time: 3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/moneyPay',{id:id},function(json){
- if(json.success){
- history.replaceState(null, "", base+"/mobile/userOrderDetail.jsp?id="+id);
- location.href=base+"/mobile/userPayResult.jsp?id="+id+"&payType=20";
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }else{
- var url;
- if(type=="card"){
- url=base+'/userCardOrder/pay'
- }else{
- url=base+'/userOrder/pay';
- }
- mobile.ajaxPost(url,{id:id},function(json){
- if(json.success){
- var data=json.data;
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
- document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
- }
- }else{
- onBridgeReady(data);
- }
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- });
- });
- function onBridgeReady(json){
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest',
- json,
- function(res){
- if(res.err_msg == "get_brand_wcpay_request:ok" ) {
- if(type=="card"){
- history.replaceState(null, "", base+"/mobile/userCard.jsp");
- }else{
- history.replaceState(null, "", base+"/mobile/userOrder.jsp?orderStatus=20");
- }
- location.href=base+"/mobile/userPayResult.jsp?id="+id+"&type="+type;
- }else{
- layer.open({content: '支付失败',time: 3});
- }
- }
- );
- }
- function getById(){
- if(type=="card"){
- document.getElementById("pay2").checked = true;
- $("#pay1").parents(".mui-radio").addClass("mui-hidden");
- }else{
- mobile.ajaxPost(base+'/userOrder/getById',{id:id},function(json){
- item = json.data;
- $(".mui-content-padded.color-red").html("待支付 ¥"+item.order_amt);
- if(parseFloat(money)>=parseFloat(item.order_amt)){
- document.getElementById("pay1").checked = true;
- }else{
- document.getElementById("pay2").checked = true;
- }
- });
- }
- }
- //获取余额
- function getMoney() {
- mobile.ajaxPost(base + '/userMoney/getMoney', {}, function(json) {
- money = json.data;
- $('#money').html("¥"+json.data);
- getById();
- },"");
- }
|