/* @songcxa @2018-12-14 @移动支付 */ var webAppParams = null; var $btnObj = null; var $btnLoad = null; var flag = 0; var appWxID = getQueryString(window.location).appId; // var appWxID = 'wx945eccc8163fd75b' 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"); var webRoot = window.location.href; //设置当前客户端浏览器模式[微信、支付宝、其他] webAppClass.clientBrowser(); //绑定事件 var ali = document.getElementById("rowAliPay"); var wx = document.getElementById("rowWxPay"); ali.onclick = webAppClass.aliClick; wx.onclick = webAppClass.wxClick; //$btnObj.onclick = webAppClass.okClick; $btnObj.onclick = webAppClass.okPay; document.getElementById("payTip").innerHTML = ""; //参数 webAppParams = getQueryString(window.location); if (webAppParams != null) { console.log(webAppParams.carNumber) //设置UI参数 webAppClass.setUI(webAppParams); } else { alertMsg("暂无订单信息"); } //获取微信code //webAppClass.getCode(); var state = clientBrowserEx(); if (state == "wxPay") { webAppCode = webAppClass.getCode(); } // $discountBtn.onclick = webAppClass.discountClick; } /**/ var webAppClass = { //优惠券兑换 codediscountClick: 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 { $btnLoad.style.display = "none"; $btnObj.style.display = "block"; $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); if (webAppParams === null || webAppParams === 'null' || webAppParams === undefined) { document.getElementById("discountTip").innerHTML = '缺少参数'; $btnLoad.style.display = "none"; $btnObj.style.display = "block"; return false; } 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"; document.getElementById("discountBox").setAttribute('readonly', 'readonly'); flag = 1 } else { $btnLoad.style.display = "none"; $btnObj.style.display = "block"; $discountBtn.disabled = false; document.getElementById("discountTip").innerHTML = res.message } }) } else { $btnLoad.style.display = "none"; $btnObj.style.display = "block"; return false; } }, //OK okClick: function (ev) { document.getElementById("payTip").innerHTML = ""; if (webAppParams == null) { alertMsg("暂无订单信息"); return; } //先校验停车费用后缴费提交 webAppClass.checkParkCost(); }, //校验该订单当前支付时的费用(排除扫描订单后不支付时长) checkParkCost: function () { $btnObj.style.display = "none"; $btnLoad.style.display = "block"; if (typeof (webAppParams.queryOrderInfo) == "undefined") {//没有queryOrderInfo返回第一页 window.history.back(-1); } var tmpParams = JSON.parse(webAppParams.queryOrderInfo); var url = webAppRoot + window.webAppH5.comServer; postRequest(url, tmpParams, function (res) { //btnObj.style.display = "block"; //$btnLoad.style.display = "none"; //$btnObj.style.display = "block"; if (res.code == 0) {//进场 var tmpObj = res.data; if (tmpObj) { if (flag == 1) { webAppClass.codediscountClick(tmpObj); } else { webAppClass.setUI(tmpObj); webAppParams = tmpObj;//重新赋值 webAppClass.okPay(tmpObj);//唤醒支付 } console.log(tmpObj) // webAppClass.okPay(tmpObj);//唤醒支付 } else { alertMsg("没有找到相应订单"); } } else {//其他情况如【该卡号场内已存在】 $btnLoad.style.display = "none"; $btnObj.style.display = "block"; console.log(res.message); alertMsg(res.message); } }, function (err) { console.log("网络服务超时..." + url); alertMsg("网络服务超时"); $btnLoad.style.display = "none"; $btnObj.style.display = "block"; //$btnLoad.style.display = "none"; }); }, //确定支付 okPay: function (params) { var _paySrcType = getQueryVariable("paySrcType") var orderID = webAppParams.orderId;//订单号 // alert(_paySrcType) if(_paySrcType==103){ var code = orderID.slice(0,orderID.length) var codes = code.split(',') orderID = [] console.log(code) console.log(codes) for(var i=0;i