diff --git a/config.js b/config.js index 6f9f1bc..7b46936 100644 --- a/config.js +++ b/config.js @@ -34,7 +34,8 @@ webAppH5.dynCode = {//卫岗固定参数 /*出、入场接口*/ webAppH5.comServer = "/keyTopQrCodeInOutPark/noCarQRcodeInOutPark"; - +/*优惠券*/ +webAppH5.discountServer = "/keyTopQrCodeInOutPark/useCouponQueryFee"; //缴费-微信 webAppH5.wxPayServer = "/weixinpay/publicUnifiedOrder"; diff --git a/js/pay.js b/js/pay.js index f3fab29..db078a0 100644 --- a/js/pay.js +++ b/js/pay.js @@ -6,12 +6,15 @@ var webAppParams = null; var $btnObj = null; var $btnLoad = null; +var flag = 0; var webAppCode = null;//如果是微信,先获取微信code //var $btnLoad = document.getElementById("loading"); window.onload = function () { //var root = document.getElementById("root"); $btnObj = document.getElementById("btnPayOK"); $btnLoad = document.getElementById("loading"); + + $discountBtn = document.getElementById("discountBtn"); $linkPayDetail = getObjectByID("linkPayDetail"); $linkPayDetail.onclick = webAppClass.linkPayDetailClick; var webRoot = window.location.href; @@ -39,9 +42,98 @@ window.onload = function () { if (state == "wxPay") { webAppCode = webAppClass.getCode(); } + $discountBtn.onclick = webAppClass.discountClick; } /**/ var webAppClass = { + //优惠券兑换 + discountClick1:function(tmpObj){ + discountVal = document.getElementById("discountBox").value; + // console.log(discountVal) + // console.log(discountVal.length) + if(discountVal.length > 0){ + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + $discountBtn.disabled = true + console.log(webAppParams.orderId) + var url = webAppRoot + window.webAppH5.discountServer; + var discountParams = { + app_id:'1', + salt:'1', + deviceInfo:'1', + sign_type:'1', + sign:'1', + token:'1', + terminalSource:7, + orderId:webAppParams.orderId, + cardNo:discountVal, + codeType:0 + } + postRequest(url, discountParams, function (res) { + console.log(res) + if(res.code==0){ + + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) + document.getElementById("discountTip").innerHTML = res.data.couponDescribe + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100) + document.getElementById("discountDesc").style.display="none" + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + flag = 1 + //webAppClass.okPay(tmpObj);//唤醒支付 + }else{ + $discountBtn.disabled = false + document.getElementById("discountTip").innerHTML = res.message + } + }) + + }else{ + return + } + }, + discountClick: function(){ + discountVal = document.getElementById("discountBox").value; + // console.log(discountVal) + // console.log(discountVal.length) + if(discountVal.length > 0){ + $btnObj.style.display = "none"; + $btnLoad.style.display = "block"; + $discountBtn.disabled = true + console.log(webAppParams.orderId) + var url = webAppRoot + window.webAppH5.discountServer; + var discountParams = { + app_id:'1', + salt:'1', + deviceInfo:'1', + sign_type:'1', + sign:'1', + token:'1', + terminalSource:7, + orderId:webAppParams.orderId, + cardNo:discountVal, + codeType:0 + } + postRequest(url, discountParams, function (res) { + console.log(res) + if(res.code==0){ + + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100) + document.getElementById("discountTip").innerHTML = res.data.couponDescribe + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100) + document.getElementById("discountDesc").style.display="none" + $btnLoad.style.display = "none"; + $btnObj.style.display = "block"; + flag = 1 + }else{ + $discountBtn.disabled = false + document.getElementById("discountTip").innerHTML = res.message + } + }) + + }else{ + return + } + }, //OK okClick: function (ev) { document.getElementById("payTip").innerHTML = ""; @@ -66,9 +158,16 @@ var webAppClass = { if (res.code == 0) {//进场 var tmpObj = res.data; if (tmpObj) { - webAppClass.setUI(tmpObj); - webAppParams = tmpObj;//重新赋值 - webAppClass.okPay(tmpObj);//唤醒支付 + if(flag == 1){ + webAppClass.discountClick1(tmpObj); + }else{ + webAppClass.setUI(tmpObj); + webAppParams = tmpObj;//重新赋值 + webAppClass.okPay(tmpObj);//唤醒支付 + } + + console.log(tmpObj) + // webAppClass.okPay(tmpObj);//唤醒支付 } else { alertMsg("没有找到相应订单"); } @@ -264,7 +363,7 @@ var webAppClass = { //0:页面初始化获取code[webAppCode] var codeParams = { code: webAppCode, appId: appWxID }; var openIdUrl = webAppRoot + window.webAppH5.wxGetOpenIdServer; - + //1:有code获取OpenId postRequest(openIdUrl, codeParams, function (res) { //alert(JSON.stringify(res)); @@ -290,7 +389,7 @@ var webAppClass = { }); //2:获取支付参数 //function getPayParams(openId) { - + //} }, getPayParams: function (openId, orderID) { @@ -337,12 +436,12 @@ var webAppClass = { WeixinJSBridge.invoke( 'getBrandWCPayRequest', params, //'getBrandWCPayRequest', { - // "appId": appWxID, //公众号名称,由商户传入 - // "timeStamp": "1395712654", //时间戳,自1970年以来的秒数 - // "nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串 + // "appId": appWxID, //公众号名称,由商户传入 + // "timeStamp": "1395712654", //时间戳,自1970年以来的秒数 + // "nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串 // "package": "prepay_id=u802345jgfjsdfgsdg888", - // "signType": "MD5", //微信签名方式: - // "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 + // "signType": "MD5", //微信签名方式: + // "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 //}, function (res) { //alert(res.err_msg); @@ -393,6 +492,7 @@ var webAppClass = { //设置UI setUI: function (params) { + console.log('ui') var $carNum = getObjectByID("carNum"),//车牌号 $orderNum = getObjectByID("orderNum"),//订单号 $sumMoney = getObjectByID("sumMoney"),//实际应付金额 @@ -420,7 +520,7 @@ var webAppClass = { $parkName.innerHTML = params.parkName; $inparktime.innerHTML = params.inparktime; $staytime.innerHTML = formatSeconds(params.staytime); - + $due.innerHTML = keepTwoDecimalFull((params.due / 100));//停车总费用 $paid.innerHTML = params.paid; $discountFee.innerHTML = keepTwoDecimalFull((params.discountFee / 100));//优惠金额 @@ -442,4 +542,4 @@ var webAppClass = { $payDetail.style.height = "55px"; } } -} \ No newline at end of file +} diff --git a/pay.html b/pay.html index 3af6c5f..0e9a7c5 100644 --- a/pay.html +++ b/pay.html @@ -15,7 +15,7 @@ - + @@ -43,6 +43,7 @@ display: inline-block; float: left; color: #8a8a8a; + font-size: 14px; } .discountBox:focus{ border: 0; @@ -63,6 +64,8 @@ background: #fff; } .discount-tip{ + padding-top: 10px; + font-size: 14px; color: #EB453B; } @@ -88,10 +91,10 @@
- - + +
-
注意:
+