...
|
...
|
@@ -11,9 +11,14 @@ var yas = require('../common/data-yas'), |
|
|
var $orderPrice = $('#order-price');
|
|
|
var order = {};
|
|
|
|
|
|
var yohoCoin;
|
|
|
var yohoCoin,
|
|
|
giftCard;
|
|
|
|
|
|
var lastOrderPrice = $orderPrice.data('price');
|
|
|
var submitting = false;
|
|
|
|
|
|
var giftCardTpl = require('hbs/cart/ensure-gift-card-list.hbs');
|
|
|
|
|
|
require('../common');
|
|
|
require('../simple-header');
|
|
|
|
...
|
...
|
@@ -85,7 +90,11 @@ function compute(coin) { |
|
|
order.coin = result.data.usedCoinNum;
|
|
|
yohoCoin.maxCoin = result.data.canUseCoinNum;
|
|
|
|
|
|
$orderPrice.html('¥ ' + result.data.last_order_amount);
|
|
|
lastOrderPrice = result.data.last_order_amount;
|
|
|
|
|
|
$orderPrice.html('¥ ' + lastOrderPrice);
|
|
|
|
|
|
giftCard.setUseStatus(lastOrderPrice);
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -133,44 +142,212 @@ yohoCoin = { |
|
|
}
|
|
|
};
|
|
|
|
|
|
$('.locker-switch').click(function() {
|
|
|
var $this = $(this),
|
|
|
$par = $this.parent();
|
|
|
// 礼品卡
|
|
|
giftCard = {
|
|
|
$el: $('#use-gift-card'),
|
|
|
init: function() {
|
|
|
if (!this.$el.length) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$par.toggleClass('open');
|
|
|
});
|
|
|
this.$giftCardWrap = this.$el.next();
|
|
|
|
|
|
this.getList();
|
|
|
this.eventBind();
|
|
|
},
|
|
|
getList: function() {
|
|
|
var that = this;
|
|
|
|
|
|
$('#order-submit').on('click', function() {
|
|
|
var $this = $(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) {
|
|
|
$('.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;
|
|
|
|
|
|
if (submitting) {
|
|
|
return;
|
|
|
}
|
|
|
this.$giftCardWrap.on('click', '.gift-card-radio', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
order = handleOrderInfo(order);
|
|
|
if ($this.hasClass('disabled')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!validateUserInfo(order)) {
|
|
|
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');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
function submitOrder(reqData, url) {
|
|
|
submitting = true;
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/cart/ticketSubmit',
|
|
|
data: order
|
|
|
data: reqData
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
window.location.href = data.data.refer;
|
|
|
} else if (data.code === 500) {
|
|
|
errorInfo(data.message, $this.data('url'));
|
|
|
errorInfo(data.message, url);
|
|
|
} else {
|
|
|
new dialog.Alert(data.message || '网络异常~').show();
|
|
|
}
|
|
|
}).always(function() {
|
|
|
submitting = false;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function sendCkeckSms() {
|
|
|
return $.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/cart/property/checksms',
|
|
|
data: {giftCard: order.giftCard}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
$('.locker-switch').click(function() {
|
|
|
var $this = $(this),
|
|
|
$par = $this.parent();
|
|
|
|
|
|
$par.toggleClass('open');
|
|
|
});
|
|
|
|
|
|
$('#order-submit').on('click', function() {
|
|
|
var errUrl = $(this).data('url'),
|
|
|
checkDg;
|
|
|
|
|
|
if (submitting) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
order = handleOrderInfo(order);
|
|
|
|
|
|
if (!validateUserInfo(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, errUrl);
|
|
|
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--) + 's').addClass('timer');
|
|
|
|
|
|
this.timer = setInterval(function() {
|
|
|
if (that.seconds > 0) {
|
|
|
that.$sendBtn.text((that.seconds--) + 's').addClass('timer');
|
|
|
} else {
|
|
|
that.$sendBtn.text('重新获取').removeClass('timer');
|
|
|
clearInterval(that.timer);
|
|
|
}
|
|
|
}, 1000);
|
|
|
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
checkDg.$sendBtn.click(function() {
|
|
|
checkDg.sendSms();
|
|
|
});
|
|
|
|
|
|
checkDg.sendSms().show();
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
order.checkCode && delete order.checkCode;
|
|
|
submitOrder(order, errUrl);
|
|
|
});
|
|
|
|
|
|
yohoCoin.init();
|
|
|
giftCard.init();
|
|
|
|
|
|
// 获取用户是否新客(品众统计)写cookie
|
|
|
$.ajax({type: 'GET', url: '/home/newuser'});
|
...
|
...
|
|