...
|
...
|
@@ -14,26 +14,14 @@ var minusPlus = { |
|
|
plus: ''
|
|
|
};
|
|
|
|
|
|
var $coin = $('#input-coin'),
|
|
|
$coinTip = $('#coin-tip'),
|
|
|
$coinSure = $('#coin-sure'),
|
|
|
$coinUsed = $('#coin-used'),
|
|
|
$coinDeduction = $('#coin-deduction'),
|
|
|
coinMax = +$coin.data('max'),
|
|
|
coinStatus = {
|
|
|
err: '请输入一个正整数',
|
|
|
max: '您的有货币不足',
|
|
|
success: '抵扣¥',
|
|
|
maxUse: '您最多使用',
|
|
|
muPostfix: '个有货币'
|
|
|
};
|
|
|
var $balanceCost = $('#balance-cost');
|
|
|
|
|
|
var $printPrice = $('#print-price');
|
|
|
|
|
|
var $invoice = $('#invoice-content');
|
|
|
|
|
|
var balanceTpl = require('../../tpl/shopping/balance.hbs');
|
|
|
var $coinRemarkContent = $('.coin-and-remark .coin .content');
|
|
|
|
|
|
var balanceTpl = require('../../tpl/shopping/balance.hbs'),
|
|
|
yohoCoinTpl = require('../../tpl/shopping/yoho-coin.hbs');
|
|
|
|
|
|
var pkgCache = {};
|
|
|
|
...
|
...
|
@@ -140,57 +128,9 @@ $('.coin-ctrl, .remark-ctrl').click(function() { |
|
|
$this.parent('.title').siblings('.content').toggleClass('hide');
|
|
|
});
|
|
|
|
|
|
// 使用有货币输入框联动
|
|
|
$coin.on('propertychange input', function() {
|
|
|
var c = $.trim($coin.val());
|
|
|
var err = true;
|
|
|
|
|
|
if (c === '') {
|
|
|
|
|
|
// 输入框为空,确定按钮不可点
|
|
|
$coinTip.addClass('vhide');
|
|
|
$coinSure.addClass('disable');
|
|
|
return;
|
|
|
} else if (!/^[1-9]\d*$/.test(c)) {
|
|
|
|
|
|
// 验证输入不为正整数
|
|
|
$coinTip.text(coinStatus.err);
|
|
|
} else if (+c > coinMax) {
|
|
|
|
|
|
// 有货币不足
|
|
|
$coinTip.text(coinStatus.max);
|
|
|
} else if (+c > $balanceCost.data('cost') * 100) {
|
|
|
|
|
|
// 输入的有货币大于订单额度
|
|
|
$coinTip.text(coinStatus.maxUse + ($balanceCost.data('cost') * 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');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 切换使用有货币面板显示
|
|
|
*/
|
|
|
function toggleCoinPanel() {
|
|
|
$('.using-coin, .used-coin').toggleClass('hide');
|
|
|
}
|
|
|
|
|
|
function compute(coin) {
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
type: 'POST',
|
|
|
url: '/shopping/order/compute',
|
|
|
data: {
|
|
|
coin: coin
|
...
|
...
|
@@ -204,46 +144,18 @@ function compute(coin) { |
|
|
cost = cost.toFixed(2);
|
|
|
|
|
|
$('#balance-list').html(balanceTpl(data.data));
|
|
|
$coinRemarkContent.html(yohoCoinTpl(data.data));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 获取已使用的有货币
|
|
|
function getCoinUsed() {
|
|
|
var coin = $coinUsed.text();
|
|
|
var coin = $('.coin-and-remark').find('#coin-sure').data('yoho_coin_num') || 0;
|
|
|
|
|
|
return coin === '' ? 0 : parseInt(coin, 10); // 使用parseInt可以排除异常情况的转化影响
|
|
|
}
|
|
|
|
|
|
$coinSure.click(function() {
|
|
|
if ($coinSure.hasClass('disable')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
suredCoin = getCoinUsed();
|
|
|
|
|
|
// 切换显示
|
|
|
compute(suredCoin);
|
|
|
|
|
|
toggleCoinPanel();
|
|
|
});
|
|
|
|
|
|
$('.used-coin').on('click', '.modify', function() {
|
|
|
toggleCoinPanel();
|
|
|
}).on('click', '.cancel', function() {
|
|
|
$coin.val('').trigger('input');
|
|
|
|
|
|
// reset used coin panel show
|
|
|
$coinUsed.html('0');
|
|
|
$coinDeduction.html('0');
|
|
|
|
|
|
compute(0);
|
|
|
|
|
|
// 隐藏有货币面板并重置子面板显示
|
|
|
$('.coin-ctrl.iconfont').trigger('click');
|
|
|
toggleCoinPanel();
|
|
|
});
|
|
|
|
|
|
// 添加备注-是否打印价格
|
|
|
$printPrice.printPrice = 'N'; // 默认为false
|
|
|
|
...
|
...
|
@@ -273,8 +185,10 @@ $('#balance-list').on('click', '#submit-order', function() { |
|
|
$invoiceDetail = $invoice.find('.invoice-detail');
|
|
|
|
|
|
$.extend(reqParam, {
|
|
|
invoices_type: $invoiceDetail.data('type'),
|
|
|
invoices_mobile: $invoiceDetail.data('mobile'),
|
|
|
invoices_title: $invoiceDetail.data('title'),
|
|
|
invoices_type_id: $invoiceDetail.data('content')
|
|
|
invoice_content: $invoiceDetail.data('content')
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -290,3 +204,33 @@ $('#balance-list').on('click', '#submit-order', function() { |
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$coinRemarkContent.on('mouseover mouseout', '.yoho-coin-help', function(event) {
|
|
|
|
|
|
if (event.type === 'mouseover') {
|
|
|
$('.coin-help-dialog').removeClass('hide');
|
|
|
} else if (event.type === 'mouseout') {
|
|
|
$('.coin-help-dialog').addClass('hide');
|
|
|
}
|
|
|
|
|
|
}).on('click', '#coin-sure', function() { // 确定有货币按钮
|
|
|
|
|
|
if ($(this).hasClass('disable')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
suredCoin = getCoinUsed();
|
|
|
|
|
|
// 切换显示
|
|
|
compute(suredCoin);
|
|
|
|
|
|
// 隐藏有货币面板并重置子面板显示
|
|
|
$('.coin-ctrl.iconfont').trigger('click');
|
|
|
}).on('click', '.cancel', function() { // 取消有货币按钮
|
|
|
|
|
|
suredCoin = 0;
|
|
|
compute(suredCoin);
|
|
|
|
|
|
// 隐藏有货币面板并重置子面板显示
|
|
|
$('.coin-ctrl.iconfont').trigger('click');
|
|
|
}); |
...
|
...
|
|