master
kira 6 years ago
parent d416b2265f
commit deebb88a2c

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

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