add aps静态码css,js,image

master
Todking 3 years ago
parent 5e4ce5d1ef
commit e1ba3b4eaa

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

@ -0,0 +1,444 @@
/**
* Created by yixian on 2017-05-08
*/
$(function () {
'use strict';
// 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);
}
dataCache.paying = false;
var ctrl = {};
$('.ff.key').bind('touchstart', function () {
if (dataCache.paying) {
return;
}
var char = $(this).attr('data-char');
appendChar(char);
});
$('.coupons .use-check').click(function () {
if ($(this).hasClass('disabled')) {
return;
}
var couponId = $(this).attr('data-coupon-id');
var couponGroup = $(this).attr('data-coupon-group');
if (couponGroup) {
var prevCouponId = dataCache.coupon_groups[couponGroup];
if (prevCouponId) {
var prevIdx = dataCache.coupons.indexOf(prevCouponId);
if (prevIdx >= 0) {
dataCache.coupons.splice(prevIdx, 1);
}
if (prevCouponId != couponId) {
$('.coupons .use-check[data-coupon-id="' + prevCouponId + '"]').removeClass('checked').addClass('unchecked');
dataCache.coupon_groups[couponGroup] = couponId;
} else {
dataCache.coupon_groups[couponGroup] = null;
}
} else {
dataCache.coupon_groups[couponGroup] = couponId;
}
}
if ($(this).is('.checked')) {
$(this).removeClass('checked').addClass('unchecked');
} else {
$(this).removeClass('unchecked').addClass('checked');
}
var checked = $(this).is('.checked');
if (checked) {
dataCache.coupons.push(couponId);
updatePrice();
} else {
var idx = dataCache.coupons.indexOf(couponId);
dataCache.coupons.splice(idx, 1);
updatePrice();
}
});
$('#key_B').bind('touchstart', function () {
backspace();
});
function updatePoundage(price) {
if (window.extensions.indexOf('customerrate') >= 0 && window.rateValue != null) {
if (window.use_customised_rate) {
var rate = new Decimal(100).plus(window.rateValue).div(100);
var poundageValue = new Decimal(dataCache.price).mul(rate).sub(dataCache.price);
} else {
var rateRemain = new Decimal(100).sub(window.rateValue).div(100);
poundageValue = new Decimal(dataCache.price).div(rateRemain).sub(dataCache.price);
}
dataCache.poundageValue = poundageValue.toFixed(2, Decimal.ROUND_HALF_UP);
return poundageValue.plus(price).toFixed(2, Decimal.ROUND_HALF_UP);
}
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;
var couponId = coupon.couponId();
if (coupon.isEnable(dataCache.currencyPrice || 0)) {
$('.coupons .use-check[data-coupon-id=' + couponId + ']').removeClass('disabled');
} else {
var dom = $('.coupons .use-check[data-coupon-id=' + couponId + ']').addClass('disabled');
var couponGroup = dom.attr('data-coupon-group');
if (couponGroup) {
if (dataCache.coupon_groups[couponGroup] == couponId) {
dataCache.coupon_groups[couponGroup] = null;
}
}
var idx = dataCache.coupons.indexOf(couponId);
if (idx >= 0) {
dataCache.coupons.splice(idx, 1);
}
dom.removeClass('checked').addClass('unchecked');
}
})
}
updatePoundageStatus();
function backspace() {
dataCache.price = dataCache.price.substring(0, dataCache.price.length - 1);
if (dataCache.price.length == 0) {
dataCache.price = '0';
}
updatePrice();
updatePoundageStatus();
}
function appendChar(char) {
var pointLocation = dataCache.price.indexOf('.');
if (pointLocation >= 0 || char == '.' || dataCache.price.length < 5) {
if (pointLocation >= 0 && char == '.') {
return;
}
if (pointLocation >= 0 && pointLocation <= dataCache.price.length - 3) {
return;
}
if (dataCache.price == '0' && char != '.') {
dataCache.price = '';
}
dataCache.price += char;
updatePrice();
updatePoundageStatus();
}
}
$('#coupon-box-toggle').click(function () {
$('.coupons-container').addClass('show');
});
$('.coupons-container>.coupons-mask,.coupons-container #close-coupon-box').click(function () {
$(this).parents('.coupons-container').removeClass('show');
});
$('.remark-btn').click(function () {
var cfg = {
title: '备注 Remark',
template: '',
initialize: function (dialog) {
$('<textarea rows="2" autofocus="autofocus"></textarea>').addClass('remark-input').attr('name', 'remark').val(dataCache.remark || '').appendTo($('.weui_dialog_bd', dialog));
},
confirm: function (dialog, chosen) {
if (chosen) {
var remark = $('textarea[name="remark"]', dialog).val();
if (remark) {
$('#remark-box').text('备注:' + remark).show()
} else {
$('#remark-box').text('').hide();
}
dataCache.remark = remark;
}
}
};
showWeuiDialog(cfg);
});
$('.paydetail').click(function () {
var config = {
title: 'Payment Detail',
template: '',
initialize: function (dialog) {
var bd = $('.weui_dialog_bd', dialog);
var currencySymbol = window.currency == 'AUD' ? '$' : '¥';
$('<p></p>').html('Input Price 输入金额:' + currencySymbol + dataCache.price).appendTo(bd);
if (parseFloat(dataCache.customSurcharge) > 0) {
$('<p></p>').html('Surcharge 手续费(' + window.rateValue + '%):+' + currencySymbol + dataCache.customSurcharge).appendTo(bd);
$('<p></p>').addClass('warning-sm').html('温馨提示:商户将向您收取本次消费手续费' + window.rateValue + '%').appendTo(bd);
}
$(dataCache.discounts).each(function () {
$('<p></p>').html(this.title + ':-' + currencySymbol + this.amount).appendTo(bd);
});
$('<p></p>').addClass('final').html('Final 支付金额:' + currencySymbol + (dataCache.finalPrice || 0)).appendTo(bd);
}
};
showWeuiDialog(config);
});
$('#key_P').click(function () {
if (window.requireRemark) {
if (!dataCache.remark) {
var config = {
title: '请先输入备注',
template: ''
};
showWeuiDialog(config);
}
}
});
$('#key_P').bind('touchstart', function () {
if (window.requireRemark) {
if (!dataCache.remark) {
return;
}
}
$('#key_P').addClass('hidden');
$('#key_Loading').removeClass('hidden');
if (dataCache.paying) {
return;
}
dataCache.paying = true;
var data = {price: dataCache.price + '', original_number: true, currency: window.currency};
if (dataCache.remark) {
data.description = dataCache.remark;
}
if (window.extensions.indexOf('preauthorize') >= 0) {
data.preauthorize = true;
}
if (window.extensions.indexOf('qrcodemode') >= 0) {
data.qrmode = true;
}
if (window.extensions.indexOf('customerrate') >= 0) {
data.customerrate = true;
}
data.coupons = dataCache.coupons;
data.qrcodeVersion = window.qrcodeVersion;
$.ajax({
url: '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders',
method: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function (pay) {
if (pay.direct_paid) {
location.href = '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result';
return;
}
if (pay.mweb_url){
location.href = pay.mweb_url;
return;
}
if (window.AlipayJSBridge) {
callPayment();
} else {
// 如果没有注入则监听注入的事件
document.addEventListener('AlipayJSBridgeReady', callPayment, false);
}
function callPayment() {
try {
AlipayJSBridge.call('tradePay', {
tradeNO: pay.trade_no
}, function (res) {
dataCache.paying = false;
if (res.resultCode == '9000') {
AlipayJSBridge.call('startApp', {
appId: '20000056',
param: {
actionType: 'showSuccPage',
payResult: res.result
},
closeCurrentApp: false
});
startCheckOrder(pay.order_id, '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result');
} else if (res.resultCode == '6001') {
//do nothing
} else {
if (res.memo) {
weuiAlert(res.memo);
}
}
$('#key_P').removeClass('hidden');
$('#key_Loading').addClass('hidden');
})
} catch (err) {
weuiAlert(err)
}
}
},
error: function (jqXhr) {
weuiAlert(jqXhr.responseJSON.message);
$('#key_P').removeClass('hidden');
$('#key_Loading').addClass('hidden');
dataCache.paying = false;
}
})
});
function startCheckOrder(orderId, url) {
function checkOrderStd() {
$.ajax({
url: '/api/v1.0/payment/orders/' + orderId + '/status',
method: 'GET',
dataType: 'json',
success: function (res) {
if (res.paid) {
location.href = url;
} else {
setTimeout(checkOrderStd, 500);
}
}
})
}
checkOrderStd();
}
function weuiAlert(msg) {
var config = {
template: msg
};
showWeuiDialog(config);
}
function showWeuiDialog(config) {
if (config.templateUrl) {
$.ajax({
url: config.templateUrl,
dataType: 'html',
success: function (template) {
buildDialog(template);
}
});
} else {
buildDialog(config.template);
}
function buildDialog(template) {
var defaultConfig = {backdrop: true};
config = $.extend({}, defaultConfig, config);
var dialog = $("<div></div>", {class: 'weui_dialog_confirm'});
var mask = $('<div></div>', {class: 'weui_mask'}).appendTo(dialog);
if (config.backdrop) {
mask.click(function () {
dialog.remove();
if ($.isFunction(config.dismiss)) {
config.dismiss();
}
})
}
var dialogBox = $("<div></div>", {class: 'weui_dialog'}).appendTo(dialog);
if (config.title) {
$('<div></div>', {class: 'weui_dialog_hd'}).append($('<strong></strong>', {class: 'weui_dialog_title'}).html(config.title)).appendTo(dialogBox);
}
var dialogBody = $("<div></div>", {class: 'weui_dialog_bd'}).appendTo(dialogBox);
if (template) {
dialogBody.append(template);
}
if ($.isFunction(config.initialize)) {
config.initialize(dialog);
}
var ft = $('<div class="weui_dialog_ft"></div>').appendTo(dialogBox);
if(window.paypad_version !== 'v3'){
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #108ee9;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #108ee9;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
}else{
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
}
dialog.appendTo($('body'));
}
}
});

@ -0,0 +1,488 @@
/**
* Created by yixian on 2017-05-08
*/
var num = function(obj){
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
};
$(function () {
'use strict';
// 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);
}
dataCache.paying = false;
var ctrl = {};
$('.ff.key').bind('touchstart', function () {
if (dataCache.paying) {
return;
}
var char = $(this).attr('data-char');
appendChar(char);
});
$('#audVal').bind('input porpertychange', function () {
if (dataCache.paying) {
return;
}
var char = $(this).val();
if (parseFloat(char) >= 100000) {
char = char.slice(0, char.length - 1);
$(this).val(char);
return;
}
appendChar(char);
});
$('.coupons .use-check').click(function () {
if ($(this).hasClass('disabled')) {
return;
}
var couponId = $(this).attr('data-coupon-id');
var couponGroup = $(this).attr('data-coupon-group');
if (couponGroup) {
var prevCouponId = dataCache.coupon_groups[couponGroup];
if (prevCouponId) {
var prevIdx = dataCache.coupons.indexOf(prevCouponId);
if (prevIdx >= 0) {
dataCache.coupons.splice(prevIdx, 1);
}
if (prevCouponId != couponId) {
$('.coupons .use-check[data-coupon-id="' + prevCouponId + '"]').removeClass('checked').addClass('unchecked');
dataCache.coupon_groups[couponGroup] = couponId;
} else {
dataCache.coupon_groups[couponGroup] = null;
}
} else {
dataCache.coupon_groups[couponGroup] = couponId;
}
}
if ($(this).is('.checked')) {
$(this).removeClass('checked').addClass('unchecked');
} else {
$(this).removeClass('unchecked').addClass('checked');
}
var checked = $(this).is('.checked');
if (checked) {
dataCache.coupons.push(couponId);
updatePrice();
} else {
var idx = dataCache.coupons.indexOf(couponId);
dataCache.coupons.splice(idx, 1);
updatePrice();
}
});
$('.cb_bankpay').click(function () {
$.ajax({
url: '/sys/partners/' + window.client_moniker + '/jump/link',
method: 'GET',
success: function (res) {
location.href = res;
},
error: function (resp) {
var config = {
template: resp
};
showWeuiDialog(config);
}
})
});
$('#key_B').bind('touchstart', function () {
backspace();
});
function updatePoundage(price) {
if (window.extensions.indexOf('customerrate') >= 0 && window.rateValue != null) {
if (window.use_customised_rate) {
var rate = new Decimal(100).plus(window.rateValue).div(100);
var poundageValue = new Decimal(dataCache.price).mul(rate).sub(dataCache.price);
} else {
var rateRemain = new Decimal(100).sub(window.rateValue).div(100);
poundageValue = new Decimal(dataCache.price).div(rateRemain).sub(dataCache.price);
}
dataCache.poundageValue = poundageValue.toFixed(2, Decimal.ROUND_HALF_UP);
return poundageValue.plus(price).toFixed(2, Decimal.ROUND_HALF_UP);
}
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.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_FLOOR);
dataCache.currencyPrice = 'CNY' == window.currency ? Decimal.div(priceBeforeDiscount, exchangeRate).toFixed(2, Decimal.ROUND_FLOOR) : priceBeforeDiscount;
$('#cnyVal').html(cnyVal)
}
function backspace() {
dataCache.price = dataCache.price.substring(0, dataCache.price.length - 1);
if (dataCache.price.length == 0) {
dataCache.price = '0';
}
updatePrice();
updatePoundageStatus();
}
function appendChar(char) {
if (char == "") {
char = '0';
}
var check = /[^\d.]/g;
if (check.test(char)) {
return;
}
var tmpChar = (char.split('.')).length-1;
if (tmpChar > 1) {
return;
}
var pointLocation = dataCache.price.indexOf('.');
if (char == '.' || char.length > 8) {
return;
}
if (pointLocation >= 0 && pointLocation <= char.length - 4) {
return;
}
if (dataCache.price == '0' && char != '.') {
dataCache.price = '';
}
dataCache.price = char;
updatePrice();
updatePoundageStatus();
}
function updatePoundageStatus() {
$(window.coupons).each(function () {
var coupon = this;
var couponId = coupon.couponId();
if (coupon.isEnable(dataCache.currencyPrice || 0)) {
$('.coupons .use-check[data-coupon-id=' + couponId + ']').removeClass('disabled');
} else {
var dom = $('.coupons .use-check[data-coupon-id=' + couponId + ']').addClass('disabled');
var couponGroup = dom.attr('data-coupon-group');
if (couponGroup) {
if (dataCache.coupon_groups[couponGroup] == couponId) {
dataCache.coupon_groups[couponGroup] = null;
}
}
var idx = dataCache.coupons.indexOf(couponId);
if (idx >= 0) {
dataCache.coupons.splice(idx, 1);
}
dom.removeClass('checked').addClass('unchecked');
}
})
}
updatePoundageStatus();
$('#coupon-box-toggle').click(function () {
$('.coupons-container').addClass('show');
});
$('.coupons-container>.coupons-mask,.coupons-container #close-coupon-box').click(function () {
$(this).parents('.coupons-container').removeClass('show');
});
$('.remark-btn').click(function () {
var cfg = {
title: '备注 Remark',
template: '',
initialize: function (dialog) {
$('<textarea rows="2" autofocus="autofocus"></textarea>').addClass('remark-input').attr('name', 'remark').val(dataCache.remark || '').appendTo($('.weui_dialog_bd', dialog));
},
confirm: function (dialog, chosen) {
if (chosen) {
var remark = $('textarea[name="remark"]', dialog).val();
if (remark) {
$('#remark-box').text('备注:' + remark).show()
} else {
$('#remark-box').text('').hide();
}
dataCache.remark = remark;
}
}
};
showWeuiDialog(cfg);
});
$('.paydetail').click(function () {
var config = {
title: 'Payment Detail',
template: '',
initialize: function (dialog) {
var bd = $('.weui_dialog_bd', dialog);
var currencySymbol = window.currency == 'CNY' ? '¥' : '$';
$('<p></p>').html('Input Price 输入金额:' + currencySymbol + dataCache.price).appendTo(bd);
if (parseFloat(dataCache.surcharge) > 0) {
$('<p></p>').html('Surcharge 手续费(' + window.rateValue + '%):+' + currencySymbol + dataCache.surcharge).appendTo(bd);
}
if (parseFloat(dataCache.tax) > 0) {
$('<p></p>').html('GST(10%):' + currencySymbol + dataCache.tax).appendTo(bd);
}
$(dataCache.discounts).each(function () {
$('<p></p>').html(this.title + ':-' + currencySymbol + this.amount).appendTo(bd);
});
$('<p></p>').addClass('final').html('Final 支付金额:' + currencySymbol + (dataCache.finalPrice || 0)).appendTo(bd);
}
};
showWeuiDialog(config);
});
$('#key_P').click(function () {
dataCache.remark = $('.remark-textarea-new').val();
if (window.requireRemark) {
if (!dataCache.remark) {
var config = {
title: '请先输入备注',
template: ''
};
showWeuiDialog(config);
}
}
});
$('#key_P').bind('touchstart', function () {
dataCache.remark = $('.remark-textarea-new').val();
if (window.requireRemark) {
if (!dataCache.remark) {
return;
}
}
$('#key_P_div').addClass('hidden');
$('#key_Loading_div').removeClass('hidden');
if (dataCache.paying) {
return;
}
dataCache.paying = true;
var data = {price: dataCache.price + '', currency: window.currency};
if (dataCache.remark) {
data.description = dataCache.remark;
}
if (window.extensions.indexOf('preauthorize') >= 0) {
data.preauthorize = true;
}
if (window.extensions.indexOf('qrcodemode') >= 0) {
data.qrmode = true;
}
if (window.extensions.indexOf('customerrate') >= 0) {
data.customerrate = true;
}
data.coupons = dataCache.coupons;
data.qrcodeVersion = window.qrcodeVersion;
$.ajax({
url: '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders',
method: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function (pay) {
if (pay.direct_paid) {
location.href = '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result';
return;
}
if (pay.mweb_url){
location.href = pay.mweb_url;
return;
}
if (window.AlipayJSBridge) {
callPayment();
} else {
// 如果没有注入则监听注入的事件
document.addEventListener('AlipayJSBridgeReady', callPayment, false);
}
function callPayment() {
try {
AlipayJSBridge.call('tradePay', {
tradeNO: pay.trade_no
}, function (res) {
dataCache.paying = false;
if (res.resultCode == '9000') {
AlipayJSBridge.call('startApp', {
appId: '20000056',
param: {
actionType: 'showSuccPage',
payResult: res.result
},
closeCurrentApp: false
});
startCheckOrder(pay.order_id, '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result');
} else if (res.resultCode == '6001') {
//do nothing
} else {
if (res.memo) {
weuiAlert(res.memo);
}
}
$('#key_P_div').removeClass('hidden');
$('#key_Loading_div').addClass('hidden');
})
} catch (err) {
weuiAlert(err)
}
}
},
error: function (jqXhr) {
weuiAlert(jqXhr.responseJSON.message);
$('#key_P_div').removeClass('hidden');
$('#key_Loading_div').addClass('hidden');
dataCache.paying = false;
}
})
});
function startCheckOrder(orderId, url) {
function checkOrderStd() {
$.ajax({
url: '/api/v1.0/payment/orders/' + orderId + '/status',
method: 'GET',
dataType: 'json',
success: function (res) {
if (res.paid) {
location.href = url;
} else {
setTimeout(checkOrderStd, 500);
}
}
})
}
checkOrderStd();
}
function weuiAlert(msg) {
var config = {
template: msg
};
showWeuiDialog(config);
}
function showWeuiDialog(config) {
if (config.templateUrl) {
$.ajax({
url: config.templateUrl,
dataType: 'html',
success: function (template) {
buildDialog(template);
}
});
} else {
buildDialog(config.template);
}
function buildDialog(template) {
var defaultConfig = {backdrop: true};
config = $.extend({}, defaultConfig, config);
var dialog = $("<div></div>", {class: 'weui_dialog_confirm'});
var mask = $('<div></div>', {class: 'weui_mask'}).appendTo(dialog);
if (config.backdrop) {
mask.click(function () {
dialog.remove();
if ($.isFunction(config.dismiss)) {
config.dismiss();
}
})
}
var dialogBox = $("<div></div>", {class: 'weui_dialog'}).appendTo(dialog);
if (config.title) {
$('<div></div>', {class: 'weui_dialog_hd'}).append($('<strong></strong>', {class: 'weui_dialog_title'}).html(config.title)).appendTo(dialogBox);
}
var dialogBody = $("<div></div>", {class: 'weui_dialog_bd'}).appendTo(dialogBox);
if (template) {
dialogBody.append(template);
}
if ($.isFunction(config.initialize)) {
config.initialize(dialog);
}
var ft = $('<div class="weui_dialog_ft"></div>').appendTo(dialogBox);
if(window.paypad_version !== 'v3'){
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #0bb20c;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #0bb20c;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
} else {
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
}
dialog.appendTo($('body'));
}
}
});

@ -0,0 +1,452 @@
/**
* Created by yixian on 2017-05-08
*/
$(function () {
'use strict';
// 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 = 'CNY' == window.currency ? 1 : parseFloat(window.exchange_rate);
dataCache.paying = false;
var ctrl = {};
if (window.AlipayJSBridge) {
AlipayJSBridge.call('hideOptionMenu');
} else {
document.addEventListener('AlipayJSBridgeReady', function () {
AlipayJSBridge.call('hideOptionMenu');
}, false);
}
dataCache.paying = false;
var ctrl = {};
$('.ff.key').bind('touchstart', function () {
if (dataCache.paying) {
return;
}
var char = $(this).attr('data-char');
appendChar(char);
});
$('.coupons .use-check').click(function () {
if ($(this).hasClass('disabled')) {
return;
}
var couponId = $(this).attr('data-coupon-id');
var couponGroup = $(this).attr('data-coupon-group');
if (couponGroup) {
var prevCouponId = dataCache.coupon_groups[couponGroup];
if (prevCouponId) {
var prevIdx = dataCache.coupons.indexOf(prevCouponId);
if (prevIdx >= 0) {
dataCache.coupons.splice(prevIdx, 1);
}
if (prevCouponId != couponId) {
$('.coupons .use-check[data-coupon-id="' + prevCouponId + '"]').removeClass('checked').addClass('unchecked');
dataCache.coupon_groups[couponGroup] = couponId;
} else {
dataCache.coupon_groups[couponGroup] = null;
}
} else {
dataCache.coupon_groups[couponGroup] = couponId;
}
}
if ($(this).is('.checked')) {
$(this).removeClass('checked').addClass('unchecked');
} else {
$(this).removeClass('unchecked').addClass('checked');
}
var checked = $(this).is('.checked');
if (checked) {
dataCache.coupons.push(couponId);
updatePrice();
} else {
var idx = dataCache.coupons.indexOf(couponId);
dataCache.coupons.splice(idx, 1);
updatePrice();
}
});
$('.cb_bankpay').click(function () {
$.ajax({
url: '/sys/partners/' + window.client_moniker + '/jump/link',
method: 'GET',
success: function (res) {
location.href = res;
},
error: function (resp) {
var config = {
template: resp
};
showWeuiDialog(config);
}
})
});
$('#key_B').bind('touchstart', function () {
backspace();
});
function updatePoundage(price) {
if (window.extensions.indexOf('customerrate') >= 0 && window.rateValue != null) {
if (window.use_customised_rate) {
var rate = new Decimal(100).plus(window.rateValue).div(100);
var poundageValue = new Decimal(dataCache.price).mul(rate).sub(dataCache.price);
} else {
var rateRemain = new Decimal(100).sub(window.rateValue).div(100);
poundageValue = new Decimal(dataCache.price).div(rateRemain).sub(dataCache.price);
}
dataCache.poundageValue = poundageValue.toFixed(2, Decimal.ROUND_HALF_UP);
return poundageValue.plus(price).toFixed(2, Decimal.ROUND_HALF_UP);
}
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.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_FLOOR);
dataCache.currencyPrice = 'CNY' == window.currency ? Decimal.div(priceBeforeDiscount, exchangeRate).toFixed(2, Decimal.ROUND_FLOOR) : priceBeforeDiscount;
$('#cnyVal').html(cnyVal)
}
function backspace() {
dataCache.price = dataCache.price.substring(0, dataCache.price.length - 1);
if (dataCache.price.length == 0) {
dataCache.price = '0';
}
updatePrice();
updatePoundageStatus();
}
function appendChar(char) {
var pointLocation = dataCache.price.indexOf('.');
if (pointLocation >= 0 || char == '.' || dataCache.price.length < 5) {
if (pointLocation >= 0 && char == '.') {
return;
}
if (pointLocation >= 0 && pointLocation <= dataCache.price.length - 3) {
return;
}
if (dataCache.price == '0' && char != '.') {
dataCache.price = '';
}
dataCache.price += char;
updatePrice();
updatePoundageStatus();
}
}
function updatePoundageStatus() {
$(window.coupons).each(function () {
var coupon = this;
var couponId = coupon.couponId();
if (coupon.isEnable(dataCache.currencyPrice || 0)) {
$('.coupons .use-check[data-coupon-id=' + couponId + ']').removeClass('disabled');
} else {
var dom = $('.coupons .use-check[data-coupon-id=' + couponId + ']').addClass('disabled');
var couponGroup = dom.attr('data-coupon-group');
if (couponGroup) {
if (dataCache.coupon_groups[couponGroup] == couponId) {
dataCache.coupon_groups[couponGroup] = null;
}
}
var idx = dataCache.coupons.indexOf(couponId);
if (idx >= 0) {
dataCache.coupons.splice(idx, 1);
}
dom.removeClass('checked').addClass('unchecked');
}
})
}
updatePoundageStatus();
$('#coupon-box-toggle').click(function () {
$('.coupons-container').addClass('show');
});
$('.coupons-container>.coupons-mask,.coupons-container #close-coupon-box').click(function () {
$(this).parents('.coupons-container').removeClass('show');
});
$('.paydetail').click(function () {
var config = {
title: 'Payment Detail',
template: '',
initialize: function (dialog) {
var bd = $('.weui_dialog_bd', dialog);
var currencySymbol = window.currency == 'CNY' ? '¥' : '$';
$('<p></p>').html('Input Price 输入金额:' + currencySymbol + dataCache.price).appendTo(bd);
if (parseFloat(dataCache.surcharge) > 0) {
$('<p></p>').html('Surcharge 手续费(' + window.rateValue + '%):+' + currencySymbol + dataCache.surcharge).appendTo(bd);
}
if (parseFloat(dataCache.tax) > 0) {
$('<p></p>').html('GST(10%):' + currencySymbol + dataCache.tax).appendTo(bd);
}
$(dataCache.discounts).each(function () {
$('<p></p>').html(this.title + ':-' + currencySymbol + this.amount).appendTo(bd);
});
$('<p></p>').addClass('final').html('Final 支付金额:' + currencySymbol + (dataCache.finalPrice || 0)).appendTo(bd);
}
};
showWeuiDialog(config);
});
$('#key_P').click(function () {
if (window.requireRemark) {
if (!dataCache.remark) {
var config = {
title: '请先输入备注',
template: ''
};
showWeuiDialog(config);
}
}
});
function addBlurListen() {
$('.remark-input').on('blur', function (event) {
dataCache.remark = $('textarea[name="remark"]').val();
});
}
addBlurListen();
$('#audVal').bind('DOMNodeInserted', function(e) {
if(dataCache.price==0){
$('.pay_button').css({"background-color":"#eee",}).attr('disabled',true);
$('.bank_button').css({"background-color":"#eee",}).attr('disabled',true);
}else{
$('.pay_button').css({"background-color":"#108ee9",}).attr('disabled',false);
$('.bank_button').css({"background-color":"#FF6600",}).attr('disabled',false);
}
});
$('#key_P').bind('touchstart', function () {
if (window.requireRemark) {
if ($('textarea[name="remark"]').val()=="") {
return;
}
}
$('#key_P').addClass('hidden');
$('#key_Loading').removeClass('hidden');
if (dataCache.paying) {
return;
}
dataCache.paying = true;
var data = {price: dataCache.price + '', currency: window.currency};
if (dataCache.remark) {
data.description = dataCache.remark;
}
if (window.extensions.indexOf('preauthorize') >= 0) {
data.preauthorize = true;
}
if (window.extensions.indexOf('qrcodemode') >= 0) {
data.qrmode = true;
}
if (window.extensions.indexOf('customerrate') >= 0) {
data.customerrate = true;
}
data.coupons = dataCache.coupons;
data.qrcodeVersion = window.qrcodeVersion;
$.ajax({
url: '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders',
method: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function (pay) {
if (pay.direct_paid) {
location.href = '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result';
return;
}
if (pay.mweb_url){
location.href = pay.mweb_url;
return;
}
if (window.AlipayJSBridge) {
callPayment();
} else {
// 如果没有注入则监听注入的事件
document.addEventListener('AlipayJSBridgeReady', callPayment, false);
}
function callPayment() {
try {
AlipayJSBridge.call('tradePay', {
tradeNO: pay.trade_no
}, function (res) {
dataCache.paying = false;
if (res.resultCode == '9000') {
AlipayJSBridge.call('startApp', {
appId: '20000056',
param: {
actionType: 'showSuccPage',
payResult: res.result
},
closeCurrentApp: false
});
startCheckOrder(pay.order_id, '/api/v1.0/alipay/partners/' + window.client_moniker + '/orders/' + pay.order_id + '/result');
} else if (res.resultCode == '6001') {
//do nothing
} else {
if (res.memo) {
weuiAlert(res.memo);
}
}
$('#key_P_div').removeClass('hidden');
$('#key_Loading_div').addClass('hidden');
})
} catch (err) {
weuiAlert(err)
}
}
},
error: function (jqXhr) {
weuiAlert(jqXhr.responseJSON.message);
$('#key_P_div').removeClass('hidden');
$('#key_Loading_div').addClass('hidden');
dataCache.paying = false;
}
})
});
function startCheckOrder(orderId, url) {
function checkOrderStd() {
$.ajax({
url: '/api/v1.0/payment/orders/' + orderId + '/status',
method: 'GET',
dataType: 'json',
success: function (res) {
if (res.paid) {
location.href = url;
} else {
setTimeout(checkOrderStd, 500);
}
}
})
}
checkOrderStd();
}
function weuiAlert(msg) {
var config = {
template: msg
};
showWeuiDialog(config);
}
function showWeuiDialog(config) {
if (config.templateUrl) {
$.ajax({
url: config.templateUrl,
dataType: 'html',
success: function (template) {
buildDialog(template);
}
});
} else {
buildDialog(config.template);
}
function buildDialog(template) {
var defaultConfig = {backdrop: true};
config = $.extend({}, defaultConfig, config);
var dialog = $("<div></div>", {class: 'weui_dialog_confirm'});
var mask = $('<div></div>', {class: 'weui_mask'}).appendTo(dialog);
if (config.backdrop) {
mask.click(function () {
dialog.remove();
if ($.isFunction(config.dismiss)) {
config.dismiss();
}
})
}
var dialogBox = $("<div></div>", {class: 'weui_dialog'}).appendTo(dialog);
if (config.title) {
$('<div></div>', {class: 'weui_dialog_hd'}).append($('<strong></strong>', {class: 'weui_dialog_title'}).html(config.title)).appendTo(dialogBox);
}
var dialogBody = $("<div></div>", {class: 'weui_dialog_bd'}).appendTo(dialogBox);
if (template) {
dialogBody.append(template);
}
if ($.isFunction(config.initialize)) {
config.initialize(dialog);
}
var ft = $('<div class="weui_dialog_ft"></div>').appendTo(dialogBox);
if(window.paypad_version !== 'v3'){
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #0bb20c;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #0bb20c;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
} else {
if ($.isFunction(config.confirm)) {
var yes = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
yes.click(function () {
config.confirm(dialog, true);
dialog.remove();
});
var no = $('<a></a>', {class: 'weui_btn_dialog default', text: 'Cancel'}).appendTo(ft);
no.click(function () {
config.confirm(dialog, false);
dialog.remove();
})
} else {
var ok = $('<a></a>', {
class: 'weui_btn_dialog primary',
text: 'OK',
style: 'background: #FF9705;color: #fff;'
}).appendTo(ft);
ok.click(function () {
dialog.remove();
})
}
}
dialog.appendTo($('body'));
addBlurListen();
}
}
});
Loading…
Cancel
Save