...
|
...
|
@@ -13,19 +13,11 @@ var $pdUsed = $('#pay-delivery-used'); |
|
|
var $balance = $('#balance-detail');
|
|
|
|
|
|
var couponsTpl = Hbs.compile($('#coupons-tpl').html());
|
|
|
var coinTpl = Hbs.compile($('#yoho-coin-tpl').html());
|
|
|
var promotionTpl = Hbs.compile($('#promotion-list-tpl').html());
|
|
|
|
|
|
var $coin = $('#coin-used');
|
|
|
var $coinTip = $('#coin-tip');
|
|
|
var $coinSure = $('#coin-sure');
|
|
|
var coinMax = +$coin.data('max');
|
|
|
var coinStatus = {
|
|
|
err: '请输入一个正整数',
|
|
|
max: '您的有货币不足',
|
|
|
success: '抵扣',
|
|
|
maxUse: '您最多使用',
|
|
|
muPostfix: '个有货币'
|
|
|
};
|
|
|
|
|
|
var queryInfo;
|
|
|
var pkgCache = {};
|
...
|
...
|
@@ -67,16 +59,18 @@ function updateUsedPdShow(info) { |
|
|
}
|
|
|
|
|
|
// 订单计算
|
|
|
function compute() {
|
|
|
var coinUsed = $coin.data('coin');
|
|
|
// 传有货币数量则使用有货币,否者不使用,更改订单总价有货币使用数量重置为0
|
|
|
function compute(coin) {
|
|
|
var d = {
|
|
|
cartType: window.queryString().type,
|
|
|
deliveryWay: $('input[name="delivery-way-radio"]:checked').val(),
|
|
|
paymentType: $('#payment-way').data('id'),
|
|
|
coin: coinUsed ? parseInt(coinUsed, 10) : 0
|
|
|
coin: coin ? parseInt(coin, 10) : 0
|
|
|
};
|
|
|
var couponCode = $('#coupons-sure').data('coupons');
|
|
|
|
|
|
$coin.data('coin', d.coin);
|
|
|
|
|
|
if (couponCode) {
|
|
|
d.couponCode = couponCode;
|
|
|
}
|
...
|
...
|
@@ -106,6 +100,9 @@ function compute() { |
|
|
|
|
|
res = data.data;
|
|
|
|
|
|
// update yoho coin using
|
|
|
$('#using-coin-cont').html(coinTpl(res));
|
|
|
|
|
|
// update last order amount
|
|
|
$('#sum-row em').html(res.last_order_amount);
|
|
|
|
...
|
...
|
@@ -178,63 +175,32 @@ if ($('#use-coupons').length) { |
|
|
}
|
|
|
|
|
|
// 有货币
|
|
|
if ($coin) {
|
|
|
$coin.data($coin.data()); // 防止人为页面更改有货币使用数量
|
|
|
}
|
|
|
|
|
|
$('#use-coin, #coin-sure, #coin-cancel').click(function() {
|
|
|
$('.coin-trigger').toggleClass('hide');
|
|
|
});
|
|
|
|
|
|
$coin.on('propertychange input', function() {
|
|
|
var c = $.trim($coin.val());
|
|
|
var err = true;
|
|
|
|
|
|
if (c === '') {
|
|
|
|
|
|
// 输入框为空,确定按钮不可点
|
|
|
$coinTip.addClass('vhide');
|
|
|
$coinTip.text(coinStatus.err);
|
|
|
return;
|
|
|
} else if (!/^[1-9]\d*$/.test(c)) {
|
|
|
|
|
|
// 验证输入不为正整数
|
|
|
$coinTip.text(coinStatus.err);
|
|
|
} else if (+c > coinMax) {
|
|
|
|
|
|
// 有货币不足
|
|
|
$coinTip.text(coinStatus.max);
|
|
|
} else if (+c > $('#sum-row').data('amount') * 100) {
|
|
|
|
|
|
// 输入的有货币大于订单额度
|
|
|
$coinTip.text(coinStatus.maxUse + ($('#sum-row').data('amount') * 100) + coinStatus.muPostfix);
|
|
|
} else {
|
|
|
err = false;
|
|
|
$coinTip.text(coinStatus.success + (c / 100).toFixed(2) + '元');
|
|
|
|
|
|
// 已使用面板的数据显示更新
|
|
|
// $coinUsed.html(c);
|
|
|
// $coinDeduction.html((c / 100).toFixed(2));
|
|
|
}
|
|
|
|
|
|
if (err) {
|
|
|
$coinSure.addClass('disable');
|
|
|
$coinTip.removeClass('vhide');
|
|
|
} else {
|
|
|
$coinSure.removeClass('disable');
|
|
|
$coinTip.addClass('vhide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$coinSure.click(function() {
|
|
|
if ($coinSure.hasClass('disable')) {
|
|
|
var data = $coin.data();
|
|
|
|
|
|
if ($coinSure.hasClass('disable') ||
|
|
|
data.coin === data.max) {
|
|
|
return;
|
|
|
}
|
|
|
$coin.data('coin', $.trim($coin.val()));
|
|
|
|
|
|
// coin change trigger compute
|
|
|
compute();
|
|
|
compute(data.max);
|
|
|
});
|
|
|
|
|
|
$('#coin-cancel').click(function() {
|
|
|
$coin.val('').data('coin', '');
|
|
|
$coinTip.addClass('vhide').text('');
|
|
|
var data = $coin.data();
|
|
|
|
|
|
if (data.coin * 1 === 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// coin cancel trigger compute
|
|
|
compute();
|
...
|
...
|
@@ -242,7 +208,7 @@ $('#coin-cancel').click(function() { |
|
|
|
|
|
// 结算信息列表中修改有货币按钮
|
|
|
$('.balance-detail').on('click', '.modify-coin', function() {
|
|
|
$('.coin-trigger').filter('.use-coin').addClass('hide').end().filter('.using-coin').removeClass('hide');
|
|
|
$('#use-coin').trigger('click');
|
|
|
});
|
|
|
|
|
|
// delivery way change trigger compute
|
...
|
...
|
|