|
@@ -29,10 +29,14 @@ var colTxt = { |
|
@@ -29,10 +29,14 @@ var colTxt = { |
29
|
hover: '取消收藏'
|
29
|
hover: '取消收藏'
|
30
|
};
|
30
|
};
|
31
|
|
31
|
|
|
|
32
|
+var oldtatus = {
|
|
|
33
|
+ txt: '已领取',
|
|
|
34
|
+ html: '<a class="coupon-btn">去使用</a>'
|
|
|
35
|
+};
|
|
|
36
|
+
|
32
|
var $saleReturn = $('#saleReturn');
|
37
|
var $saleReturn = $('#saleReturn');
|
33
|
|
38
|
|
34
|
var dialogTpl = require('hbs/product/coupon-dialog.hbs');
|
39
|
var dialogTpl = require('hbs/product/coupon-dialog.hbs');
|
35
|
-var couponItemTpl = require('hbs/product/coupon-item.hbs');
|
|
|
36
|
|
40
|
|
37
|
bindEvent.add(function() {
|
41
|
bindEvent.add(function() {
|
38
|
var $imgShow = $('#img-show'),
|
42
|
var $imgShow = $('#img-show'),
|
|
@@ -61,6 +65,8 @@ bindEvent.add(function() { |
|
@@ -61,6 +65,8 @@ bindEvent.add(function() { |
61
|
|
65
|
|
62
|
var maxStock = -1; // 记录当前选中的颜色-尺码的库存量,若为-1,代表未选择尺码
|
66
|
var maxStock = -1; // 记录当前选中的颜色-尺码的库存量,若为-1,代表未选择尺码
|
63
|
|
67
|
|
|
|
68
|
+ var brandDomain = $('.home').attr('href');
|
|
|
69
|
+
|
64
|
var Alert = require('../common/dialog').Alert;
|
70
|
var Alert = require('../common/dialog').Alert;
|
65
|
|
71
|
|
66
|
var Dialog = require('../common/dialog').Dialog;
|
72
|
var Dialog = require('../common/dialog').Dialog;
|
|
@@ -69,65 +75,78 @@ bindEvent.add(function() { |
|
@@ -69,65 +75,78 @@ bindEvent.add(function() { |
69
|
|
75
|
|
70
|
var $couponItem = $('.coupon-item');
|
76
|
var $couponItem = $('.coupon-item');
|
71
|
|
77
|
|
72
|
- var $coupons = $couponItem.map(function(i) {
|
|
|
73
|
- var $this = $(this);
|
|
|
74
|
-
|
|
|
75
|
- return {
|
|
|
76
|
- couponId: $this.data('id'),
|
|
|
77
|
- couponName: $this.data('name'),
|
|
|
78
|
- amount: $this.data('amount'),
|
|
|
79
|
- acquireStatus: $this.data('status'),
|
|
|
80
|
- rule4ShortName: $this.data('rule'),
|
|
|
81
|
- i: i
|
|
|
82
|
- };
|
|
|
83
|
- }).get();
|
|
|
84
|
-
|
|
|
85
|
- var newCoupons = $.grep($coupons, function(val) {
|
|
|
86
|
- return val.acquireStatus === 1;
|
|
|
87
|
- });
|
78
|
+ function openCouponDialog(e) {
|
|
|
79
|
+ var $coupons = $couponItem.map(function(i) {
|
|
|
80
|
+ var $this = $(this);
|
|
|
81
|
+
|
|
|
82
|
+ return {
|
|
|
83
|
+ couponId: $this.data('id'),
|
|
|
84
|
+ couponName: $this.data('name'),
|
|
|
85
|
+ amount: $this.data('amount'),
|
|
|
86
|
+ acquireStatus: $this.data('status'),
|
|
|
87
|
+ rule4ShortName: $this.data('rule'),
|
|
|
88
|
+ i: i
|
|
|
89
|
+ };
|
|
|
90
|
+ }).get();
|
|
|
91
|
+
|
|
|
92
|
+ var newCoupons = $.grep($coupons, function(val) {
|
|
|
93
|
+ return val.acquireStatus === 1;
|
|
|
94
|
+ });
|
88
|
|
95
|
|
89
|
- var oldCoupons = $.grep($coupons, function(val) {
|
|
|
90
|
- return val.acquireStatus === 3;
|
|
|
91
|
- });
|
96
|
+ var oldCoupons = $.grep($coupons, function(val) {
|
|
|
97
|
+ return val.acquireStatus === 3;
|
|
|
98
|
+ });
|
92
|
|
99
|
|
93
|
- var json = {
|
|
|
94
|
- newList: {
|
|
|
95
|
- title: '可以领取的券',
|
|
|
96
|
- body: newCoupons
|
100
|
+ var couponData = {
|
|
|
101
|
+ newList: {
|
|
|
102
|
+ title: '可以领取的券',
|
|
|
103
|
+ body: newCoupons
|
97
|
|
104
|
|
98
|
- },
|
|
|
99
|
- oldList: {
|
|
|
100
|
- title: '已领取的券',
|
|
|
101
|
- body: oldCoupons
|
|
|
102
|
- }
|
|
|
103
|
- };
|
105
|
+ },
|
|
|
106
|
+ oldList: {
|
|
|
107
|
+ title: '已领取的券',
|
|
|
108
|
+ body: oldCoupons
|
|
|
109
|
+ }
|
|
|
110
|
+ };
|
104
|
|
111
|
|
105
|
- $moreCoupon.on('click', function() {
|
|
|
106
|
new Dialog({
|
112
|
new Dialog({
|
107
|
- content: dialogTpl({coupon: json}),
|
113
|
+ content: dialogTpl({coupon: couponData}),
|
108
|
className: 'coupon-big'
|
114
|
className: 'coupon-big'
|
109
|
}).show();
|
115
|
}).show();
|
110
|
- });
|
|
|
111
|
-
|
|
|
112
|
- $(document).on('click', '.status', function() {
|
|
|
113
|
- var $this = $(this);
|
|
|
114
|
- var id = $this.data('id');
|
|
|
115
|
- var i = $this.data('i');
|
|
|
116
|
- var status = $this.data('status');
|
|
|
117
|
|
116
|
|
118
|
- console.log(i);
|
117
|
+ e.stopPropagation();
|
|
|
118
|
+ }
|
119
|
|
119
|
|
120
|
- $this.data('status', 9);
|
|
|
121
|
- });
|
|
|
122
|
|
120
|
|
123
|
function imgShow(src) {
|
121
|
function imgShow(src) {
|
124
|
$imgShow.attr('src', src);
|
122
|
$imgShow.attr('src', src);
|
125
|
}
|
123
|
}
|
126
|
|
124
|
|
|
|
125
|
+ function getCouponAsync(cid) {
|
|
|
126
|
+ var uid = getUid(); // eslint-disable-line
|
|
|
127
|
+
|
|
|
128
|
+ if (!uid || !cid) {
|
|
|
129
|
+ return $.Deferred().reject().promise(); // eslint-disable-line
|
|
|
130
|
+ }
|
|
|
131
|
+
|
|
|
132
|
+ return $.getJSON('/product/detail/coupon', {
|
|
|
133
|
+ couponId: cid
|
|
|
134
|
+ }).then(function(result) {
|
|
|
135
|
+ var defer = $.Deferred(); //eslint-disable-line
|
|
|
136
|
+ result.code === 200 ? defer.resolve() : defer.reject();
|
|
|
137
|
+ return defer.promise();
|
|
|
138
|
+ });
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ function jumpUrl(url) {
|
|
|
142
|
+ window.location.href = url;
|
|
|
143
|
+ }
|
|
|
144
|
+
|
127
|
/**
|
145
|
/**
|
128
|
* 获取当前选择的商品数目
|
146
|
* 获取当前选择的商品数目
|
129
|
* @return [Number]
|
147
|
* @return [Number]
|
130
|
*/
|
148
|
*/
|
|
|
149
|
+
|
131
|
function getNum() {
|
150
|
function getNum() {
|
132
|
return +$num.text();
|
151
|
return +$num.text();
|
133
|
}
|
152
|
}
|
|
@@ -557,6 +576,29 @@ bindEvent.add(function() { |
|
@@ -557,6 +576,29 @@ bindEvent.add(function() { |
557
|
}
|
576
|
}
|
558
|
}());
|
577
|
}());
|
559
|
|
578
|
|
|
|
579
|
+ // 打开优惠券列表
|
|
|
580
|
+ $moreCoupon.on('click', openCouponDialog);
|
|
|
581
|
+
|
|
|
582
|
+ // 优惠券的领取
|
|
|
583
|
+ $(document).on('click', '.status', function() {
|
|
|
584
|
+ var $this = $(this);
|
|
|
585
|
+ var couponId = $this.data('id');
|
|
|
586
|
+ var status = $this.data('status');
|
|
|
587
|
+ var i = $this.data('i');
|
|
|
588
|
+ var $item = $($couponItem.get(i));
|
|
|
589
|
+
|
|
|
590
|
+ switch (status) {
|
|
|
591
|
+ case 1:
|
|
|
592
|
+ getCouponAsync(couponId).then(function() {
|
|
|
593
|
+ $this.find('.coupon-status').text(oldtatus.txt);
|
|
|
594
|
+ $this.find('.coupon-go').empty().append(oldtatus.html);
|
|
|
595
|
+ $item.data('status', 3);
|
|
|
596
|
+ });
|
|
|
597
|
+ break;
|
|
|
598
|
+ default:
|
|
|
599
|
+ jumpUrl(brandDomain);
|
|
|
600
|
+ }
|
|
|
601
|
+ });
|
560
|
});
|
602
|
});
|
561
|
|
603
|
|
562
|
// yas
|
604
|
// yas
|