Commit 72b1b692d21ce83f2cabe11f24c4fbd048fd151f

Authored by Andy
1 parent 654bfaaf

add 兑换券

js/billCodePay.js
... ... @@ -7,10 +7,13 @@ var webAppParams = null;
7 7 var $btnObj = null;
8 8 var $btnLoad = null;
9 9 var webAppCode = null;//如果是微信,先获取微信code
  10 +var flag = 0;
10 11 window.onload = function () {
11 12 //var root = document.getElementById("root");
12 13 $btnObj = document.getElementById("btnPayOK");
13 14 $btnLoad = document.getElementById("loading");
  15 + //兑换按钮
  16 + $discountBtn = document.getElementById("discountBtn");
14 17 $linkPayDetail = getObjectByID("linkPayDetail");
15 18 $linkPayDetail.onclick = webAppClass.linkPayDetailClick;
16 19 var webRoot = window.location.href;
... ... @@ -40,6 +43,8 @@ window.onload = function () {
40 43 alertMsg("没有接收到url参数信息");
41 44 }
42 45 }
  46 + //兑换按钮事件
  47 + $discountBtn.onclick = webAppClass.discountClick;
43 48 }
44 49 /**/
45 50 var webAppClass = {
... ... @@ -127,6 +132,95 @@ var webAppClass = {
127 132 $btnLoad.style.display = "block";
128 133 webAppClass.okPay(webAppParams);//唤醒支付
129 134 },
  135 + //优惠券兑换
  136 + codediscountClick:function(tmpObj){
  137 + discountVal = document.getElementById("discountBox").value;
  138 + // console.log(discountVal)
  139 + // console.log(discountVal.length)
  140 + if(discountVal.length > 0){
  141 + $btnObj.style.display = "none";
  142 + $btnLoad.style.display = "block";
  143 + $discountBtn.disabled = true
  144 + console.log(webAppParams.orderId)
  145 + var url = webAppRoot + window.webAppH5.discountServer;
  146 + var discountParams = {
  147 + app_id:'1',
  148 + salt:'1',
  149 + deviceInfo:'1',
  150 + sign_type:'1',
  151 + sign:'1',
  152 + token:'1',
  153 + terminalSource:7,
  154 + orderId:webAppParams.orderId,
  155 + cardNo:discountVal,
  156 + codeType:0
  157 + }
  158 + postRequest(url, discountParams, function (res) {
  159 + console.log(res)
  160 + if(res.code==0){
  161 +
  162 + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100)
  163 + document.getElementById("discountTip").innerHTML = res.data.couponDescribe
  164 + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100)
  165 + document.getElementById("discountDesc").style.display="none"
  166 + $btnLoad.style.display = "none";
  167 + $btnObj.style.display = "block";
  168 + flag = 1
  169 + webAppClass.okPay(tmpObj);//唤醒支付
  170 + }else{
  171 + $discountBtn.disabled = false
  172 + document.getElementById("discountTip").innerHTML = res.message
  173 + }
  174 + })
  175 +
  176 + }else{
  177 + return
  178 + }
  179 + },
  180 + discountClick: function(){
  181 + discountVal = document.getElementById("discountBox").value;
  182 + // console.log(discountVal)
  183 + // console.log(discountVal.length)
  184 + if(discountVal.length > 0){
  185 + $btnObj.style.display = "none";
  186 + $btnLoad.style.display = "block";
  187 + $discountBtn.disabled = true
  188 + console.log(webAppParams.orderId)
  189 + var url = webAppRoot + window.webAppH5.discountServer;
  190 + var discountParams = {
  191 + app_id:'1',
  192 + salt:'1',
  193 + deviceInfo:'1',
  194 + sign_type:'1',
  195 + sign:'1',
  196 + token:'1',
  197 + terminalSource:7,
  198 + orderId:webAppParams.orderId,
  199 + cardNo:discountVal,
  200 + codeType:0
  201 + }
  202 + postRequest(url, discountParams, function (res) {
  203 + console.log(res)
  204 + if(res.code==0){
  205 +
  206 + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100)
  207 + document.getElementById("discountTip").innerHTML = res.data.couponDescribe
  208 + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100)
  209 + document.getElementById("discountDesc").style.display="none"
  210 + $btnLoad.style.display = "none";
  211 + $btnObj.style.display = "block";
  212 + document.getElementById("discountBox").setAttribute('readonly','readonly');
  213 + flag = 1
  214 + }else{
  215 + $discountBtn.disabled = false
  216 + document.getElementById("discountTip").innerHTML = res.message
  217 + }
  218 + })
  219 +
  220 + }else{
  221 + return
  222 + }
  223 + },
130 224 //校验该订单当前支付时的费用(排除扫描订单后不支付时长)
131 225 checkParkCost: function () {
132 226 $btnObj.style.display = "none";
... ... @@ -142,9 +236,14 @@ var webAppClass = {
142 236 if (res.code == 0) {//进场
143 237 var tmpObj = res.data;
144 238 if (tmpObj) {
145   - webAppClass.setUI(tmpObj);
146   - webAppParams = tmpObj;//重新赋值
147   - webAppClass.okPay(tmpObj);//唤醒支付
  239 + if(flag == 1){
  240 + webAppClass.codediscountClick(tmpObj);
  241 + }else{
  242 + webAppClass.setUI(tmpObj);
  243 + webAppParams = tmpObj;//重新赋值
  244 + webAppClass.okPay(tmpObj);//唤醒支付
  245 + }
  246 +
148 247 } else {
149 248 alertMsg("没有找到相应订单");
150 249 $btnLoad.style.display = "none";
... ...
js/dynCodePay.js
... ... @@ -8,9 +8,12 @@ var webAppParams = null;//URL参数
8 8 var $btnObj = null;
9 9 var $btnLoad = null;
10 10 var webAppCode = null;//如果是微信,先获取微信code
  11 +var flag = 0;
11 12 window.onload = function () {
12 13 $btnObj = getObjectByID("btnPayOK");
13 14 $btnLoad = getObjectByID("loading");
  15 + //兑换按钮
  16 + $discountBtn = document.getElementById("discountBtn");
14 17 $linkPayDetail = getObjectByID("linkPayDetail");
15 18 $linkPayDetail.onclick = webAppClass.linkPayDetailClick;
16 19 var webRoot = window.location.href;
... ... @@ -39,9 +42,100 @@ window.onload = function () {
39 42 if (state == "wxPay") {
40 43 webAppCode = webAppClass.getCode();
41 44 }
  45 + //兑换按钮事件
  46 + $discountBtn.onclick = webAppClass.discountClick;
42 47 }
43 48 /**/
44 49 var webAppClass = {
  50 + //优惠券兑换
  51 + codediscountClick:function(tmpObj){
  52 + discountVal = document.getElementById("discountBox").value;
  53 + // console.log(discountVal)
  54 + // console.log(discountVal.length)
  55 + if(discountVal.length > 0){
  56 + $btnObj.style.display = "none";
  57 + $btnLoad.style.display = "block";
  58 + $discountBtn.disabled = true
  59 + console.log(webAppParams.orderId)
  60 + var url = webAppRoot + window.webAppH5.discountServer;
  61 + var discountParams = {
  62 + app_id:'1',
  63 + salt:'1',
  64 + deviceInfo:'1',
  65 + sign_type:'1',
  66 + sign:'1',
  67 + token:'1',
  68 + terminalSource:7,
  69 + orderId:webAppParams.orderId,
  70 + cardNo:discountVal,
  71 + codeType:1
  72 + }
  73 + postRequest(url, discountParams, function (res) {
  74 + console.log(res)
  75 + if(res.code==0){
  76 +
  77 + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100)
  78 + document.getElementById("discountTip").innerHTML = res.data.couponDescribe
  79 + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100)
  80 + document.getElementById("discountDesc").style.display="none"
  81 + $btnLoad.style.display = "none";
  82 + $btnObj.style.display = "block";
  83 + flag = 1
  84 + webAppClass.okPay(tmpObj);//唤醒支付
  85 + }else{
  86 + $discountBtn.disabled = false
  87 + document.getElementById("discountTip").innerHTML = res.message
  88 + }
  89 + })
  90 +
  91 + }else{
  92 + return
  93 + }
  94 + },
  95 + discountClick: function(){
  96 + discountVal = document.getElementById("discountBox").value;
  97 + // console.log(discountVal)
  98 + // console.log(discountVal.length)
  99 + if(discountVal.length > 0){
  100 + $btnObj.style.display = "none";
  101 + $btnLoad.style.display = "block";
  102 + $discountBtn.disabled = true
  103 + console.log(webAppParams.orderId)
  104 + var url = webAppRoot + window.webAppH5.discountServer;
  105 + var discountParams = {
  106 + app_id:'1',
  107 + salt:'1',
  108 + deviceInfo:'1',
  109 + sign_type:'1',
  110 + sign:'1',
  111 + token:'1',
  112 + terminalSource:7,
  113 + orderId:webAppParams.orderId,
  114 + cardNo:discountVal,
  115 + codeType:1
  116 + }
  117 + postRequest(url, discountParams, function (res) {
  118 + console.log(res)
  119 + if(res.code==0){
  120 +
  121 + document.getElementById("sumMoney").innerHTML = (res.data.orderFee/100)
  122 + document.getElementById("discountTip").innerHTML = res.data.couponDescribe
  123 + document.getElementById("discountFee").innerHTML = (res.data.discountFee/100)
  124 + document.getElementById("discountDesc").style.display="none"
  125 + $btnLoad.style.display = "none";
  126 + $btnObj.style.display = "block";
  127 + document.getElementById("discountBox").setAttribute('readonly','readonly');
  128 + flag = 1
  129 + }else{
  130 + $discountBtn.disabled = false
  131 + document.getElementById("discountTip").innerHTML = res.message
  132 + }
  133 + })
  134 +
  135 + }else{
  136 + return
  137 + }
  138 + },
45 139 //OK
46 140 okClick: function (ev) {
47 141 //document.getElementById("payTip").innerHTML = "";
... ... @@ -54,6 +148,9 @@ var webAppClass = {
54 148  
55 149 //确定支付
56 150 okPay: function (params) {
  151 + if(flag == 1){
  152 + webAppClass.codediscountClick(tmpObj);
  153 + }
57 154 var orderID = params.orderId;//订单号
58 155 //第一首先判断当前哪种浏览器方式[微信内置、支付宝内置、第三方浏览器]
59 156 var clientType = clientBrowserEx();
... ...
js/pay.js
... ... @@ -47,7 +47,7 @@ window.onload = function () {
47 47 /**/
48 48 var webAppClass = {
49 49 //优惠券兑换
50   - discountClick1:function(tmpObj){
  50 + codediscountClick:function(tmpObj){
51 51 discountVal = document.getElementById("discountBox").value;
52 52 // console.log(discountVal)
53 53 // console.log(discountVal.length)
... ... @@ -80,7 +80,7 @@ var webAppClass = {
80 80 $btnLoad.style.display = "none";
81 81 $btnObj.style.display = "block";
82 82 flag = 1
83   - //webAppClass.okPay(tmpObj);//唤醒支付
  83 + webAppClass.okPay(tmpObj);//唤醒支付
84 84 }else{
85 85 $discountBtn.disabled = false
86 86 document.getElementById("discountTip").innerHTML = res.message
... ... @@ -123,7 +123,7 @@ var webAppClass = {
123 123 document.getElementById("discountDesc").style.display="none"
124 124 $btnLoad.style.display = "none";
125 125 $btnObj.style.display = "block";
126   - document.getElementById("discountBox").attr('readonly','readonly');
  126 + document.getElementById("discountBox").setAttribute('readonly','readonly');
127 127 flag = 1
128 128 }else{
129 129 $discountBtn.disabled = false
... ... @@ -160,7 +160,7 @@ var webAppClass = {
160 160 var tmpObj = res.data;
161 161 if (tmpObj) {
162 162 if(flag == 1){
163   - webAppClass.discountClick1(tmpObj);
  163 + webAppClass.codediscountClick(tmpObj);
164 164 }else{
165 165 webAppClass.setUI(tmpObj);
166 166 webAppParams = tmpObj;//重新赋值
... ...