master
kira 6 years ago
parent d416b2265f
commit deebb88a2c

@ -21,7 +21,7 @@ $(function (){
if(isiOS){
window.webkit.messageHandlers.rpayplus.postMessage(msg);
} else{
//rpayplus.send(msg);
rpayplus.send(msg);
}
},

@ -3,21 +3,21 @@
*/
$(function () {
'use strict';
// document.querySelector('body').addEventListener('touchmove', function (e) {
// if (!document.querySelector('.coupons').contains(e.target)) {
// e.preventDefault();
// }
// })
document.querySelector('body').addEventListener('touchmove', function (e) {
if (!document.querySelector('.coupons').contains(e.target)) {
e.preventDefault();
}
})
var dataCache = {price: '0', coupons: [], coupon_groups: {}};
var exchangeRate = parseFloat(window.exchange_rate);
// if (window.AlipayJSBridge) {
// AlipayJSBridge.call('hideOptionMenu');
// } else {
// document.addEventListener('AlipayJSBridgeReady', function () {
// AlipayJSBridge.call('hideOptionMenu');
// }, false);
// }
if (window.AlipayJSBridge) {
AlipayJSBridge.call('hideOptionMenu');
} else {
document.addEventListener('AlipayJSBridgeReady', function () {
AlipayJSBridge.call('hideOptionMenu');
}, false);
}
dataCache.paying = false;
var ctrl = {};
@ -62,9 +62,11 @@ $(function () {
var checked = $(this).is('.checked');
if (checked) {
dataCache.coupons.push(couponId);
updatePrice();
} else {
var idx = dataCache.coupons.indexOf(couponId);
dataCache.coupons.splice(idx, 1);
}
});
@ -87,6 +89,29 @@ $(function () {
return price;
}
function updatePrice() {
$('#audVal').html(dataCache.price);
var realPrice = dataCache.price;
$('#audValReal').html(realPrice);
var surchargeData = calculateSurcharge(realPrice);
var price = surchargeData.newPrice || realPrice;
var priceBeforeDiscount = price;
dataCache.discounts = [];
dataCache.tax = surchargeData.tax;
dataCache.surcharge = surchargeData.surcharge;
$(window.coupons).each(function () {
price = this.handleDiscount(price, dataCache.price, dataCache.discounts, dataCache.coupons);
});
dataCache.customSurcharge = new Decimal(price).sub(realPrice).toFixed(2,Decimal.ROUND_HALF_UP);
dataCache.finalPrice = new Decimal(price).toFixed(2, Decimal.ROUND_FLOOR);
var rate = 'CNY' == window.currency ? 1 : exchangeRate;
var cnyVal = Decimal.mul(price, rate).toFixed(2, Decimal.ROUND_HALF_UP);
$('#cnyVal').html(cnyVal);
dataCache.currencyPrice = 'CNY' == window.currency ? Decimal.div(priceBeforeDiscount, exchangeRate).toFixed(2, Decimal.ROUND_FLOOR) : priceBeforeDiscount;
}
function updatePoundageStatus() {
$(window.coupons).each(function () {
var coupon = this;
@ -117,6 +142,7 @@ $(function () {
if (dataCache.price.length == 0) {
dataCache.price = '0';
}
updatePrice();
updatePoundageStatus();
}
@ -133,6 +159,7 @@ $(function () {
dataCache.price = '';
}
dataCache.price += char;
updatePrice();
updatePoundageStatus();
}
}
@ -232,7 +259,6 @@ $(function () {
dataCache.remark = '';
window.RPayPlus.send("showLoading", null, null);
$.ajax({
url: '/api/v1.0/rpay/partners/' + window.client_moniker + '/orders',
method: 'POST',
@ -241,11 +267,7 @@ $(function () {
dataType: 'json',
success: function (resp) {
window.RPayPlus.send("closeLoading", null, null);
// pay(resp);
if (resp.direct_paid) {
location.href = '/api/v1.0/rpay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result';
return;
}
pay(resp,location.href = '/api/v1.0/rpay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result');
// if (window.AlipayJSBridge) {
// callPayment();
// } else {
@ -287,8 +309,6 @@ $(function () {
error: function (jqXhr) {
window.RPayPlus.send("closeLoading", null, null);
weuiAlert(jqXhr.responseJSON.message);
$('#key_P').removeClass('hidden');
$('#key_Loading').addClass('hidden');
dataCache.paying = false;
}
})
@ -390,19 +410,19 @@ $(function () {
}
/* function getUserId(){
function getUserId(){
window.RPayPlus.send("getUserId", null, function(data){
window.Rpay.userInfo = data;
});
}
function pay(param){
function pay(param,callback){
var order={
nonce_str:param.nonce_str,
rpay_order_id:param.rpay_order_id,
mch_order_id:param.mch_order_id
};
alert("rpay_order_info: nonce_str:"+param.nonce_str+"rpay_order_id:"+param.rpay_order_id+"mch_order_id:"+param.mch_order_id);
window.RPayPlus.send('pay', order, null);
window.RPayPlus.send('pay', order, callback);
}
function back(){
@ -436,5 +456,5 @@ $(function () {
queryOrder(data);
});
}
getUserId();*/
getUserId();
});
Loading…
Cancel
Save