|
|
1
|
+/**
|
|
|
2
|
+ * 优惠券选择
|
|
|
3
|
+ * @author: bikai<kai.bi@yoho.cn>
|
|
|
4
|
+ * @date: 2015/12/10
|
|
|
5
|
+ */
|
|
|
6
|
+
|
1
|
var $ = require('jquery'),
|
7
|
var $ = require('jquery'),
|
2
|
Handlebars = require('yoho.handlebars'),
|
8
|
Handlebars = require('yoho.handlebars'),
|
3
|
ellipsis = require('mlellipsis'),
|
9
|
ellipsis = require('mlellipsis'),
|
4
|
loading = require('../plugin/loading'),
|
10
|
loading = require('../plugin/loading'),
|
5
|
- tip = require('../plugin/tip');
|
11
|
+ tip = require('../plugin/tip'),
|
|
|
12
|
+ orderInfo = require('./order-info');
|
6
|
|
13
|
|
7
|
var page = 1,
|
14
|
var page = 1,
|
8
|
canGetCoupon = true,
|
15
|
canGetCoupon = true,
|
|
@@ -16,43 +23,48 @@ ellipsis.init(); |
|
@@ -16,43 +23,48 @@ ellipsis.init(); |
16
|
$('#search-coupon').on('submit', function() {
|
23
|
$('#search-coupon').on('submit', function() {
|
17
|
$.ajax({
|
24
|
$.ajax({
|
18
|
method: 'POST',
|
25
|
method: 'POST',
|
19
|
- url: '',
|
26
|
+ url: '/shoppingCart/coupon',
|
20
|
data: $(this).serialize()
|
27
|
data: $(this).serialize()
|
21
|
}).then(function(res) {
|
28
|
}).then(function(res) {
|
22
|
- if (res.avaliable) {
|
|
|
23
|
- $('#coupon-list').html(conponTmpl({
|
|
|
24
|
- coupons: res.coupons
|
|
|
25
|
- }));
|
|
|
26
|
- $('#coupon-list-not').html('');
|
29
|
+ if (res.code === 200) {
|
|
|
30
|
+ tip.show('优惠券可用');
|
|
|
31
|
+ orderInfo('couponCode', res.data.coupon_code);
|
|
|
32
|
+ window.location.href = '/shoppingCart/orderEnsure?coupon_code=' + res.data.coupon_code;
|
27
|
} else {
|
33
|
} else {
|
28
|
- tip.show(res.msg);
|
34
|
+ tip.show(res.message);
|
29
|
}
|
35
|
}
|
|
|
36
|
+ }).fail(function() {
|
|
|
37
|
+ tip.show('网络错误');
|
30
|
});
|
38
|
});
|
31
|
return false;
|
39
|
return false;
|
32
|
});
|
40
|
});
|
33
|
|
41
|
|
|
|
42
|
+$('#coupon-list').on('touchend', 'employ-main', function() {
|
|
|
43
|
+ orderInfo('couponCode', $(this).data('coupon-code'));
|
|
|
44
|
+});
|
|
|
45
|
+
|
34
|
function getCouponHandle(coupons) {
|
46
|
function getCouponHandle(coupons) {
|
35
|
var notAvailableCoupons = [];
|
47
|
var notAvailableCoupons = [];
|
36
|
|
48
|
|
37
|
// 后端需要返回一个 coupons 列表,如下
|
49
|
// 后端需要返回一个 coupons 列表,如下
|
38
|
// notAvailable 表示不可用的优惠券
|
50
|
// notAvailable 表示不可用的优惠券
|
39
|
- coupons = [{
|
|
|
40
|
- money: '99',
|
|
|
41
|
- coupon_name: '满XX-减去吴悠右腿有益于有2222',
|
|
|
42
|
- couponValidity: '20150129-20150430',
|
|
|
43
|
- coupon_id: '22222'
|
|
|
44
|
- }, {
|
|
|
45
|
- money: '99',
|
|
|
46
|
- coupon_name: '满XX-减去吴悠右腿有益于有2222',
|
|
|
47
|
- couponValidity: '20150129-20150430',
|
|
|
48
|
- coupon_id: '2222233'
|
|
|
49
|
- }, {
|
|
|
50
|
- money: '99',
|
|
|
51
|
- coupon_name: 'NONO满XX-减去吴悠右腿有益于有2222',
|
|
|
52
|
- couponValidity: '20150129-20150430',
|
|
|
53
|
- coupon_id: '2222233',
|
|
|
54
|
- notAvailable: 1
|
|
|
55
|
- }];
|
51
|
+ // coupons = [{
|
|
|
52
|
+ // money: '99',
|
|
|
53
|
+ // coupon_name: '满XX-减去吴悠右腿有益于有2222',
|
|
|
54
|
+ // couponValidity: '20150129-20150430',
|
|
|
55
|
+ // coupon_id: '22222'
|
|
|
56
|
+ // }, {
|
|
|
57
|
+ // money: '99',
|
|
|
58
|
+ // coupon_name: '满XX-减去吴悠右腿有益于有2222',
|
|
|
59
|
+ // couponValidity: '20150129-20150430',
|
|
|
60
|
+ // coupon_id: '2222233'
|
|
|
61
|
+ // }, {
|
|
|
62
|
+ // money: '99',
|
|
|
63
|
+ // coupon_name: 'NONO满XX-减去吴悠右腿有益于有2222',
|
|
|
64
|
+ // couponValidity: '20150129-20150430',
|
|
|
65
|
+ // coupon_id: '2222233',
|
|
|
66
|
+ // notAvailable: 1
|
|
|
67
|
+ // }];
|
56
|
|
68
|
|
57
|
// coupons 是个列表,如果不是列表,可能是服务器错误,这次翻页加载不算
|
69
|
// coupons 是个列表,如果不是列表,可能是服务器错误,这次翻页加载不算
|
58
|
if (!$.isArray(coupons)) {
|
70
|
if (!$.isArray(coupons)) {
|
|
@@ -106,9 +118,8 @@ function getCouponDate() { |
|
@@ -106,9 +118,8 @@ function getCouponDate() { |
106
|
$.ajax({
|
118
|
$.ajax({
|
107
|
type: 'POST',
|
119
|
type: 'POST',
|
108
|
url: '/home/couponData',
|
120
|
url: '/home/couponData',
|
109
|
- dataType: 'html',
|
121
|
+ dataType: 'json',
|
110
|
data: {
|
122
|
data: {
|
111
|
- statuss: status,
|
|
|
112
|
page: page
|
123
|
page: page
|
113
|
}
|
124
|
}
|
114
|
}).then(getCouponHandle).fail(function() {
|
125
|
}).then(getCouponHandle).fail(function() {
|