...
|
...
|
@@ -22,12 +22,16 @@ var payWay, |
|
|
multiPackage,
|
|
|
coupon,
|
|
|
yohoCoin,
|
|
|
giftCard,
|
|
|
refund;
|
|
|
|
|
|
var lastOrderPrice = $orderPrice.data('price');
|
|
|
|
|
|
var address = require('./order/address'),
|
|
|
invoice = require('./order/invoice'),
|
|
|
esaypayInfo = require('./order/easypay');
|
|
|
|
|
|
var giftCardTpl = require('hbs/cart/ensure-gift-card-list.hbs');
|
|
|
var coinTpl = Hbs.compile($('#yoho-coin-tpl').html());
|
|
|
var promotionTpl = Hbs.compile($('#promotion-list-tpl').html());
|
|
|
|
...
|
...
|
@@ -97,6 +101,11 @@ function compute(coin, cb) { |
|
|
reqData.redEnvelopes = order.redEnvelopes;
|
|
|
}
|
|
|
|
|
|
// 礼品卡
|
|
|
if (order.giftCard) {
|
|
|
reqData.giftCard = order.giftCard;
|
|
|
}
|
|
|
|
|
|
if (esaypayInfo) {
|
|
|
if (order.sku) {
|
|
|
reqData.sku = order.sku;
|
...
|
...
|
@@ -135,11 +144,15 @@ function compute(coin, cb) { |
|
|
yohoCoin.$el.html(coinTpl(res));
|
|
|
|
|
|
// update last order amount
|
|
|
lastOrderPrice = res.last_order_amount;
|
|
|
$orderPrice.html('¥ ' + res.last_order_amount);
|
|
|
|
|
|
// update promotion formula list
|
|
|
$balanceDetail.html(promotionTpl(res));
|
|
|
|
|
|
// update giftCard use status
|
|
|
giftCard.setUseStatus(lastOrderPrice);
|
|
|
|
|
|
}
|
|
|
|
|
|
// callback
|
...
|
...
|
@@ -674,6 +687,93 @@ yohoCoin = { |
|
|
}
|
|
|
};
|
|
|
|
|
|
// 礼品卡
|
|
|
giftCard = {
|
|
|
$el: $('#use-gift-card'),
|
|
|
init: function() {
|
|
|
if (!this.$el.length) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.$giftCardWrap = this.$el.next();
|
|
|
|
|
|
this.getList();
|
|
|
this.eventBind();
|
|
|
},
|
|
|
getList: function() {
|
|
|
var that = this;
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/cart/ensure/giftcards'
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
if (data.data && data.data.usable_giftCards && data.data.usable_giftCards.length) {
|
|
|
that.$el.removeClass('hide').next().removeClass('hide');
|
|
|
$('.can-use-tip', that.$el).text('(' + data.data.usable_giftCards.length + '张可用)');
|
|
|
}
|
|
|
|
|
|
if (data.data.usable_giftCards.length) {
|
|
|
$('tbody', that.$giftCardWrap).html(giftCardTpl(data.data));
|
|
|
|
|
|
that.$radios = $('.gift-card-radio', that.$giftCardWrap);
|
|
|
}
|
|
|
|
|
|
that.checkContent = '<h2>安全验证</h2>' +
|
|
|
'<p class="tip-info">您正在使用礼品卡支付,为了保证您的账户安全,需要进行安全验证。</p>' +
|
|
|
'<p class="receiver-info">验证码已发送至' + (data.data.userMobile || '您绑定的') + '手机号</p>' +
|
|
|
'<p><input type="text" placeholder="短信验证码" maxlength="8"><span class="send-sms">获取验证码</span></p>';
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
eventBind: function() {
|
|
|
var that = this;
|
|
|
|
|
|
this.$giftCardWrap.on('click', '.gift-card-radio', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('disabled')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('on')) {
|
|
|
// 取消使用礼品卡,设置其他礼品卡可用
|
|
|
that.setUseStatus(2);
|
|
|
} else if (+$this.data('price') >= lastOrderPrice * 1) { // 已选礼品卡总价大于订单总价,设置其他礼品卡不可选
|
|
|
that.setUseStatus();
|
|
|
}
|
|
|
|
|
|
$this.toggleClass('on');
|
|
|
that.changeCardUse();
|
|
|
});
|
|
|
},
|
|
|
changeCardUse: function() {
|
|
|
var codes = [];
|
|
|
|
|
|
if (!this.$radios) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.$radios.filter('.on').each(function() {
|
|
|
codes.push($(this).data('id'));
|
|
|
});
|
|
|
|
|
|
order.giftCard = codes.join(',');
|
|
|
compute(order.coin);
|
|
|
},
|
|
|
setUseStatus: function(price) {
|
|
|
if (!this.$radios) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (price && price * 1 > 0) {
|
|
|
this.$radios.filter('.disable').removeClass('disable');
|
|
|
} else {
|
|
|
this.$radios.not('.on').addClass('disable');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 退换货提示
|
|
|
refund = {
|
|
|
$el: $('.special-tip'),
|
...
|
...
|
@@ -691,8 +791,6 @@ refund = { |
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$('.locker-switch').click(function() {
|
|
|
var $this = $(this),
|
|
|
$par = $this.parent();
|
...
|
...
|
@@ -740,58 +838,19 @@ $('.locker-switch').click(function() { |
|
|
});
|
|
|
}());
|
|
|
|
|
|
$('#remark-box').on('keyup', '.note-text', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (val) {
|
|
|
$this.addClass('has-text');
|
|
|
|
|
|
if (val.length > 100) {
|
|
|
val = val.substring(0, 99);
|
|
|
$this.val(val);
|
|
|
}
|
|
|
|
|
|
order.remark = val;
|
|
|
} else {
|
|
|
$this.removeClass('has-text');
|
|
|
}
|
|
|
}).on('click', '.radio-btn', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('on')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('unprint')) {
|
|
|
order.printPrice = 'N';
|
|
|
} else {
|
|
|
order.printPrice = 'Y';
|
|
|
}
|
|
|
|
|
|
$this.siblings('.on').removeClass('on');
|
|
|
$this.addClass('on');
|
|
|
});
|
|
|
|
|
|
$('#order-submit').click(function() {
|
|
|
var invoiceInfo = invoice.getInvoice();
|
|
|
|
|
|
order.addressId = address.getAddress();
|
|
|
|
|
|
// 发票信息
|
|
|
if (invoiceInfo) {
|
|
|
$.extend(order, invoiceInfo);
|
|
|
}
|
|
|
|
|
|
// 订单参数校验
|
|
|
if (!validateOrderInfo(order)) {
|
|
|
return;
|
|
|
}
|
|
|
function sendCkeckSms() {
|
|
|
return $.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/cart/property/checksms',
|
|
|
data: {giftCard: order.giftCard}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function submitOrder(reqData) {
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/cart/ensure/submit',
|
|
|
data: order
|
|
|
data: reqData
|
|
|
}).then(function(data) {
|
|
|
var rdata, subTip, newUser,
|
|
|
tongJi = {
|
...
|
...
|
@@ -800,6 +859,7 @@ $('#order-submit').click(function() { |
|
|
sku: [],
|
|
|
py: []
|
|
|
};
|
|
|
var errAlert;
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
rdata = data.data;
|
...
|
...
|
@@ -877,9 +937,131 @@ $('#order-submit').click(function() { |
|
|
location.href = rdata.url;
|
|
|
}
|
|
|
} else if (data.message) {
|
|
|
new dialog.Alert(data.message).show();
|
|
|
errAlert = new dialog.Alert(data.message);
|
|
|
errAlert.$el.addClass('ensure-alert');
|
|
|
errAlert.show();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
$('#remark-box').on('keyup', '.note-text', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (val) {
|
|
|
$this.addClass('has-text');
|
|
|
|
|
|
if (val.length > 100) {
|
|
|
val = val.substring(0, 99);
|
|
|
$this.val(val);
|
|
|
}
|
|
|
|
|
|
order.remark = val;
|
|
|
} else {
|
|
|
$this.removeClass('has-text');
|
|
|
}
|
|
|
}).on('click', '.radio-btn', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('on')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('unprint')) {
|
|
|
order.printPrice = 'N';
|
|
|
} else {
|
|
|
order.printPrice = 'Y';
|
|
|
}
|
|
|
|
|
|
$this.siblings('.on').removeClass('on');
|
|
|
$this.addClass('on');
|
|
|
});
|
|
|
|
|
|
$('#order-submit').click(function() {
|
|
|
var invoiceInfo = invoice.getInvoice();
|
|
|
var checkDg;
|
|
|
|
|
|
order.addressId = address.getAddress();
|
|
|
|
|
|
// 发票信息
|
|
|
if (invoiceInfo) {
|
|
|
$.extend(order, invoiceInfo);
|
|
|
}
|
|
|
|
|
|
// 订单参数校验
|
|
|
if (!validateOrderInfo(order)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 使用礼品卡时候进行短信校验
|
|
|
if (order.giftCard) {
|
|
|
checkDg = new dialog.Dialog({
|
|
|
content: giftCard.checkContent || '',
|
|
|
className: 'gift-card-check-dialog',
|
|
|
btns: [{
|
|
|
id: 'check-cancel',
|
|
|
btnClass: ['check-cancel'],
|
|
|
name: '取消',
|
|
|
cb: function() {
|
|
|
checkDg.close();
|
|
|
}
|
|
|
}, {
|
|
|
id: 'check-sure',
|
|
|
btnClass: ['check-sure'],
|
|
|
name: '确定',
|
|
|
cb: function() {
|
|
|
order.checkCode = $('input', checkDg.$el).val();
|
|
|
|
|
|
if (order.checkCode) {
|
|
|
submitOrder(order);
|
|
|
checkDg.close();
|
|
|
}
|
|
|
}
|
|
|
}]
|
|
|
});
|
|
|
|
|
|
checkDg.$sendBtn = $('.send-sms', checkDg.$el);
|
|
|
checkDg.sendSms = function() {
|
|
|
var that = this;
|
|
|
|
|
|
if (!this.$sendBtn || this.seconds > 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
sendCkeckSms(); // 发送验证码
|
|
|
|
|
|
if (!this.seconds || this.seconds < 1) {
|
|
|
this.seconds = 59;
|
|
|
}
|
|
|
|
|
|
this.timer && clearInterval(this.timer);
|
|
|
|
|
|
this.$sendBtn.text('重新获取(' + (this.seconds--) + ')').addClass('timer');
|
|
|
|
|
|
this.timer = setInterval(function() {
|
|
|
if (that.seconds > 0) {
|
|
|
that.$sendBtn.text('重新获取(' + (that.seconds--) + ')').addClass('timer');
|
|
|
} else {
|
|
|
that.$sendBtn.text('重新获取').removeClass('timer');
|
|
|
clearInterval(that.timer);
|
|
|
}
|
|
|
}, 1000);
|
|
|
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
checkDg.$sendBtn.click(function() {
|
|
|
checkDg.sendSms();
|
|
|
});
|
|
|
|
|
|
checkDg.sendSms().show();
|
|
|
|
|
|
return;
|
|
|
} else {
|
|
|
order.checkCode && delete order.checkCode;
|
|
|
}
|
|
|
|
|
|
submitOrder(order);
|
|
|
});
|
|
|
|
|
|
payWay.init();
|
...
|
...
|
@@ -887,6 +1069,7 @@ deliveryWay.init(); |
|
|
multiPackage.init();
|
|
|
coupon.init();
|
|
|
yohoCoin.init();
|
|
|
giftCard.init();
|
|
|
refund.init();
|
|
|
|
|
|
// 获取用户是否新客(品众统计)写cookie
|
...
|
...
|
|