var userIntegral = 0; // 用户可用积分 var meonyProportion = 0; // 兑换比例:1个积分=?分钱 var payTotal = 0.0; // 支付总金额 var userInputIntegral = 0; // 抵扣积分 var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求 var cartIdStr = ""; // 购物车ID var usePayMoney = 0; var ipt_balance = 0; var yhq_val = 0; var used_balance = 0; var yhq_type = 1; var showIs = false; mui.ready(function() { var name,value; var str=location.href; //取得整个地址栏 var num=str.indexOf("?") str=str.substr(num+1); //取得所有参数 $.ajax(base_path+'/order/payBefore?'+str, { dataType: 'json', type: 'POST', timeout: 15000, xhrFields: { withCredentials: true }, crossDomain: true, success: function(dt) { if (dt.isRedirect) { location.href = dt.redirectURL; } else { if(dt.status == true) { // 购物项遍历 //console.log(dt) var liNote = ""; var cNum = 0; if(dt.data.balance == 0) { $(".pay_ipt_box").hide(); } else { used_balance = accDiv(dt.data.balance, 100); $('#used_balance').html("¥ " + accDiv(dt.data.balance, 100)); } var yhq_str = ""; if(dt.data.couponItems.length == 0 || !dt.data.disable) { $(".forward").hide(); } else { $("#yhq_count").html(dt.data.couponItems.length); //如果购买商品只有饮水机滤芯,则不能使用优惠券 if (dt.data.disable) { mui(dt.data.couponItems).each(function(index) { yhq_str += '
'; }); $(".my-popover").html(yhq_str + ''); } } for(var i = 0; i < dt.data.cartItems.length; i++) { var total = dt.data.cartItems[i].cartNum * dt.data.cartItems[i].productPrice / 100; // 购物车小计,分-->元 var pro_color = switchcolor(dt.data.cartItems[i].cartColorId); var colorImg = switchColorImg(dt.data.cartItems[i].cartColorId); total = total.toFixed(2); // 保留两位小数 var productId = dt.data.cartItems[i].cartProductId; var colorId=dt.data.cartItems[i].cartColorId; var price = dt.data.cartItems[i].productPrice; var num = dt.data.cartItems[i].cartNum; if (dt.data.cartItems[i].productPrice / 100 == 3280) { liNote = liNote + "" + dt.data.addressInfo.salesAddressInfo + "
" + ""); $("#user-address-div").show(); $("#open-wechat-addres-a").hide(); //给微信参数赋值 wechatAddr.status = true; wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo; wechatAddr.userName = dt.data.addressInfo.salesAddressName; wechatAddr.userTel = dt.data.addressInfo.salesAddressTel; wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum; } } else { mui.alert(dt.message); } } }, error: function(xhr, type, errorThrown) { errorfn(xhr); } }); // 获取微信共享地址 mui('body').on('tap', '#open-wechat-addres-a,#user-address-div', function() { editAddrV1( function(res) { // 用户成功拉出地址 var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo; wechatAddr.status = true; wechatAddr.detailInfo = address; wechatAddr.postalCode = res.postalCode; wechatAddr.userName = res.userName; wechatAddr.userTel = res.telNumber; wechatAddr.nationalCode = res.nationalCode; $("#user-address-div").empty().append( "收货人:" + wechatAddr.userName + "" + wechatAddr.userTel + "" + "" + "" + wechatAddr.detailInfo + "
" + ""); $("#user-address-div").show(); $("#open-wechat-addres-a").hide(); }, function() { if($('#user-address-div').html() != null && $('#user-address-div').html() != '') { wechatAddr.status = true; } else { wechatAddr.status = false; // 用户取消拉出地址 mui.alert("您没有选择收货地址!"); } } ); }); // 积分数量改变时 mui('body').on('change', '#input-user-integral', function() { var inputUserIntegral = $("#input-user-integral").val(); $.trim(inputUserIntegral); var r = /^[1-9]+\d*$/; if(!r.test(inputUserIntegral)) { $("#input-user-integral").val(userInputIntegral); return false; } inputUserIntegral = parseInt(inputUserIntegral); if(inputUserIntegral > userIntegral) { $("#input-user-integral").val(userInputIntegral); return false; } if((inputUserIntegral * meonyProportion) > payTotal) { $("#input-user-integral").val(userInputIntegral); return false; } // 置换数据 userInputIntegral = inputUserIntegral; var temp = (userInputIntegral * meonyProportion / 100).toFixed(2); $("#integral-money-span").html(temp); temp = ((payTotal - (userInputIntegral * meonyProportion)) / 100).toFixed(2); $("#user-pay-money-span").html(temp); }); // 去支付 mui('body').on('tap', '.btn-weixin-pay', function() { var yhq_id = $("input[name=radio1]:checked").attr('id'); if(yhq_id == undefined) { yhq_id = ""; } var remark = $("#textarea").val(); var pattern = new RegExp("[ `~!@#$^&*()=|{}':;'\\[\\]<>/?~!@#¥……&*()——|{}【】‘;:”“'、?]") if(remark != "") { $.trim(remark); if(pattern.test(remark)) { mui.alert("请不要输入中文、字母、数字以外的特殊字符!"); return; } if(!(remark.length >= 0 && remark.length <= 100)) { mui.alert("备注字数长度在0-100之间!"); return; } } if(wechatAddr.status) { if(isPay) { isPay = false; // 锁定请求按钮 layer.open({ type: 2, shadeClose: false, content: "正在请求加载订单信息..." }); // 调用加载弹出层 /* 组装数据 */ var dataArgs = { "orderAddressInfo": wechatAddr.detailInfo, "orderAddressPostNum": wechatAddr.postalCode, "orderAddressMoblie": wechatAddr.userTel, "orderAddressName": wechatAddr.userName, "cartIdStr": cartIdStr, "orderIntegralNum": userInputIntegral, "orderUserRemark": remark, "couponId": yhq_id, "balancePayAmount": accMul(ipt_balance, 100) }; $.ajax('/watero/wechat/order/pay', { // 提交订单,准备支付 data: dataArgs, dataType: 'json', type: 'POST', timeout: 15000, xhrFields: { withCredentials: true }, crossDomain: true, success: function(dt) { if (dt.isRedirect) { location.href = dt.redirectURL; } else { layer.closeAll(); //mui.alert(dt.resultCode=="500"); if(dt.resultCode == "500") { mui.alert(dt.message); isPay = true; return; }; if(dt.data.info == "isOK") { mui.openWindow({ url: domanUrl + base_path+"/order/paySuccess?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime() }); return; }; if(dt.status) { var str = dt.data.info; var obj = JSON.parse("{" + str + "}"); WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) { if(res.err_msg == 'get_brand_wcpay_request:ok') { var orderIds = { "orderId": dt.data.orderId }; layer.open({ type: 2, shadeClose: false, content: "正在请求加载订单信息..." }); // 调用加载弹出层 var url = base_path+"/order/checkOrderPaySuccess"; $.getJSON(url, { "s": new Date().getTime(), "orderId": dt.data.orderId }, function(data) { if(data.status == true) { // 支付成功 window.location.href = base_path + "/order/paySuccess?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime(); } else { setTimeout("checkOrderStatus('" + dt.data.orderId + "')", 1000); } }); } else { isPay = true; // mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!"); window.location.href = "order_details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情 } }); } else { isPay = true; mui.alert(dt.message); window.location.href = "order_details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情 } } }, error: function(xhr, type, errorThrown) { isPay = true; layer.closeAll(); mui.alert("您的网络异常,请刷新重试!"); return; } }); } else { mui.alert("正在请求支付中~~请稍后!"); return; } } else { mui.alert("请选择收货地址!"); return; } }); mui('body').on('tap', '.mui-popover-action li>a', function() { var a = this, parent; //根据点击按钮,反推当前是哪个actionsheet for(parent = a.parentNode; parent != document.body; parent = parent.parentNode) { if(parent.classList.contains('mui-popover-action')) { break; } } //关闭actionsheet mui('#' + parent.id).popover('toggle'); yhq_val = $("input[name=radio1]:checked").val(); yhq_type = $("input[name=radio1]:checked").attr("yhq_type"); if(yhq_val == undefined) { yhq_val = 0 } else { if(yhq_type == 1) { if(yhq_val > (usePayMoney - ipt_balance)) { $("input[name=radio1]:checked").removeAttr("checked"); yhq_val = 0; mui.alert(' ', '当前优惠券不可用', function() {}); } $("#yhq_price").html(yhq_val); $("#accSub,#accSub>div:first-child").show(); $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2)); } else { yhq_val = accSub(usePayMoney, Math.floor(accMul($("input[name=radio1]:checked").val(), usePayMoney) * 100) / 100); $("#yhq_price").html(yhq_val); $("#accSub,#accSub>div:first-child").show(); $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2)); } } }); mui.os.ios ? listener_ipt() : keyup_fn(); var reg = /^(([1-9]\d*))$/; function keyup_fn() { $('body').on('blur', '#pay_ipt', function(e) { ipt_balance = $(this).val(); if(reg.test(ipt_balance)) { if(ipt_balance > (usePayMoney - yhq_val)) { ipt_balance = (usePayMoney - yhq_val).toFixed(2); if(ipt_balance < 0) { ipt_balance = 0; $(this).val(""); } else { $(this).val((usePayMoney - yhq_val).toFixed(2)); } } if(ipt_balance > used_balance) { ipt_balance = used_balance; $(this).val(used_balance); } $('#used_buy').html(ipt_balance); var money = (usePayMoney - yhq_val).toFixed(2); money <= 0 ? money = 0 : money; $("#accSub,#accSub>div:last-child").show(); $("#user-pay-money-span").html((money - ipt_balance).toFixed(2) + " 元"); } else { mui.alert(' ', '您输入的数字有误,请重新输入', function() { $(this).val(""); ipt_balance = 0; $('#used_buy').html(ipt_balance); $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元"); }); } }); } function listener_ipt() { document.getElementById('pay_ipt').onblur = function() { var th = this; ipt_balance = th.value; if(reg.test(ipt_balance)) { if(ipt_balance > (usePayMoney - yhq_val)) { ipt_balance = (usePayMoney - yhq_val).toFixed(2); if(ipt_balance < 0) { ipt_balance = 0; th.value = ""; } else { th.value = (usePayMoney - yhq_val).toFixed(2); } } if(ipt_balance > used_balance) { th.value = used_balance; ipt_balance = used_balance; } $('#used_buy').html(ipt_balance); var money = (usePayMoney - yhq_val).toFixed(2); money <= 0 ? money = 0 : money; $("#accSub,#accSub>div:last-child").show(); $("#user-pay-money-span").html((money - ipt_balance).toFixed(2) + " 元"); } else { mui.alert(' ', '您输入的数字有误