coupons.page.js
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var $ = require('yoho-jquery');
var yas = require('../common/data-yas'),
dialog = require('../common/dialog');
var $couponCodeUse = $('.code-sure-btn'),
$codeInput = $('.code-input');
require('../common');
$('.use-now-btn').click(function() {
var couponid = $(this).data('couponid');
if (couponid) {
yas.yasEvent('YB_COUPON_IMMEDIATE_USE_C', {COUPON_ID: couponid});
}
});
$codeInput.keyup(function() {
if ($.trim($(this).val())) {
$couponCodeUse.addClass('sure-convert-btn');
} else {
$couponCodeUse.removeClass('sure-convert-btn');
}
});
$couponCodeUse.click(function() {
var code = $.trim($codeInput.val());
if ($(this).hasClass('sure-convert-btn') && code) {
$.ajax({
type: 'GET',
url: '/cart/ensure/couponcode',
data: {code: code}
}).then(function(data) {
if (data.code === 200) {
new dialog.Dialog({
className: 'coupon-code-confirm',
content: '兑换成功',
btns: [
{
id: 'confirm-sure',
btnClass: ['confirm-sure'],
name: '确定',
cb: function() {
window.location.reload();
}
}
]
}).show();
} else {
new dialog.Alert(data.message || '兑换失败,请稍后再试').show();
}
});
}
});