1
|
-/* global define */
|
|
|
2
|
-// amd
|
|
|
3
|
-define(function(require) {
|
|
|
4
|
- 'use strict';
|
|
|
5
|
-
|
|
|
6
|
- /**
|
|
|
7
|
- * 商品详情: 品牌券
|
|
|
8
|
- */
|
|
|
9
|
- var tip = require('plugin/tip');
|
|
|
10
|
- var $ = require('yoho-jquery');
|
|
|
11
|
- var $body = $(document.body);
|
|
|
12
|
-
|
|
|
13
|
- var brandCoupon = {
|
|
|
14
|
- skn: null,
|
|
|
15
|
- brandId: null,
|
|
|
16
|
- $entry: null,
|
|
|
17
|
- $couponDrawer: null,
|
|
|
18
|
-
|
|
|
19
|
- template: require('product/detail/coupon-list.hbs'),
|
|
|
20
|
-
|
|
|
21
|
- init: function(skn, brandId) {
|
|
|
22
|
- var self = this;
|
|
|
23
|
-
|
|
|
24
|
- this.skn = skn;
|
|
|
25
|
- this.brandId = brandId;
|
|
|
26
|
-
|
|
|
27
|
- if (!(skn && brandId)) {
|
|
|
28
|
- return;
|
|
|
29
|
- }
|
1
|
+'use strict';
|
30
|
|
2
|
|
31
|
- this.fetchCoupons(this.skn, this.brandId)
|
|
|
32
|
- .done(function(data) {
|
|
|
33
|
- if (data.length) {
|
|
|
34
|
- self.render(data);
|
|
|
35
|
- self.domInit();
|
|
|
36
|
- self.bindEvents();
|
|
|
37
|
-
|
|
|
38
|
- self.$entry.removeClass('hide');
|
|
|
39
|
- }
|
|
|
40
|
- })
|
|
|
41
|
- .fail();
|
|
|
42
|
- },
|
|
|
43
|
-
|
|
|
44
|
- domInit: function() {
|
|
|
45
|
- this.$entry = $('.brand-coupon').removeClass('hide');
|
|
|
46
|
- },
|
|
|
47
|
-
|
|
|
48
|
- bindEvents: function() {
|
|
|
49
|
- var self = this;
|
|
|
50
|
-
|
|
|
51
|
- this.$entry.on('click', function() {
|
|
|
52
|
- self.toggleDrawer(true);
|
|
|
53
|
- });
|
|
|
54
|
-
|
|
|
55
|
- this.$couponDrawer
|
|
|
56
|
- .on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false))
|
|
|
57
|
- .on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this));
|
|
|
58
|
- },
|
|
|
59
|
-
|
|
|
60
|
- render: function(data) {
|
|
|
61
|
- this.$couponDrawer = $(this.template({
|
|
|
62
|
- coupons: data
|
|
|
63
|
- }));
|
|
|
64
|
- this.$couponDrawer.appendTo('.good-detail-page');
|
|
|
65
|
-
|
|
|
66
|
- return this;
|
|
|
67
|
- },
|
|
|
68
|
-
|
|
|
69
|
- // 获取 品牌券
|
|
|
70
|
- fetchCoupons: function(skn, brandId) {
|
|
|
71
|
- return $.get('/product/detail/coupon.json', {
|
|
|
72
|
- skn: skn,
|
|
|
73
|
- brandId: brandId
|
|
|
74
|
- });
|
|
|
75
|
- },
|
|
|
76
|
-
|
|
|
77
|
- saveCoupon: function(couponId, callback) {
|
|
|
78
|
- $.post('/product/detail/coupon/save.json', {
|
|
|
79
|
- couponId: couponId
|
|
|
80
|
- }).done(function(res) {
|
|
|
81
|
- tip.show(res.message);
|
|
|
82
|
-
|
|
|
83
|
- if (res.code === 200) {
|
|
|
84
|
- callback(); // eslint-disable-line
|
|
|
85
|
- } else {
|
|
|
86
|
- tip.show(
|
|
|
87
|
- res.message || '抱歉,您不符合领用条件'
|
|
|
88
|
- );
|
|
|
89
|
-
|
|
|
90
|
- if (res.redirect) {
|
|
|
91
|
- setTimeout(function() {
|
|
|
92
|
- location.href = res.redirect;
|
|
|
93
|
- }, 1000);
|
|
|
94
|
- }
|
|
|
95
|
- }
|
|
|
96
|
- }).fail(function() {
|
|
|
97
|
- tip.show('网络异常,请稍后再试');
|
|
|
98
|
- });
|
|
|
99
|
- },
|
|
|
100
|
-
|
|
|
101
|
- // 收藏 品牌券
|
|
|
102
|
- saveCouponHandler: function(event) {
|
|
|
103
|
- var $btn = $(event.target);
|
|
|
104
|
- var couponId = $btn.closest('.coupon').data('coupon');
|
|
|
105
|
-
|
|
|
106
|
- this.saveCoupon(couponId, function() {
|
|
|
107
|
- $btn.prop('disabled', true)
|
|
|
108
|
- .removeClass('coupon-btn-valid')
|
|
|
109
|
- .text('已领取');
|
|
|
110
|
- });
|
|
|
111
|
-
|
|
|
112
|
- event.stopPropagation();
|
|
|
113
|
- },
|
|
|
114
|
-
|
|
|
115
|
- toggleDrawer: function(bool) {
|
|
|
116
|
- this.$couponDrawer.toggleClass('open', bool);
|
|
|
117
|
- $body.toggleClass('coupon-drawer-open', bool);
|
3
|
+/**
|
|
|
4
|
+ * 商品详情: 品牌券
|
|
|
5
|
+ */
|
|
|
6
|
+var tip = require('plugin/tip');
|
|
|
7
|
+var $ = require('yoho-jquery');
|
|
|
8
|
+var $body = $(document.body);
|
|
|
9
|
+
|
|
|
10
|
+var brandCoupon = {
|
|
|
11
|
+ skn: null,
|
|
|
12
|
+ brandId: null,
|
|
|
13
|
+ $entry: null,
|
|
|
14
|
+ $couponDrawer: null,
|
|
|
15
|
+
|
|
|
16
|
+ template: require('product/detail/coupon-list.hbs'),
|
|
|
17
|
+
|
|
|
18
|
+ init: function(skn, brandId) {
|
|
|
19
|
+ var self = this;
|
|
|
20
|
+
|
|
|
21
|
+ this.skn = skn;
|
|
|
22
|
+ this.brandId = brandId;
|
|
|
23
|
+
|
|
|
24
|
+ if (!(skn && brandId)) {
|
|
|
25
|
+ return;
|
118
|
}
|
26
|
}
|
119
|
- };
|
|
|
120
|
|
27
|
|
121
|
- brandCoupon.init(
|
|
|
122
|
- $('#productSkn').val(),
|
|
|
123
|
- $('#brand-id').val()
|
|
|
124
|
- );
|
|
|
125
|
-}); |
28
|
+ this.fetchCoupons(this.skn, this.brandId)
|
|
|
29
|
+ .done(function(data) {
|
|
|
30
|
+ if (data.length) {
|
|
|
31
|
+ self.render(data);
|
|
|
32
|
+ self.domInit();
|
|
|
33
|
+ self.bindEvents();
|
|
|
34
|
+
|
|
|
35
|
+ self.$entry.removeClass('hide');
|
|
|
36
|
+ }
|
|
|
37
|
+ })
|
|
|
38
|
+ .fail();
|
|
|
39
|
+ },
|
|
|
40
|
+
|
|
|
41
|
+ domInit: function() {
|
|
|
42
|
+ this.$entry = $('.brand-coupon').removeClass('hide');
|
|
|
43
|
+ },
|
|
|
44
|
+
|
|
|
45
|
+ bindEvents: function() {
|
|
|
46
|
+ var self = this;
|
|
|
47
|
+
|
|
|
48
|
+ this.$entry.on('click', function() {
|
|
|
49
|
+ self.toggleDrawer(true);
|
|
|
50
|
+ });
|
|
|
51
|
+
|
|
|
52
|
+ this.$couponDrawer
|
|
|
53
|
+ .on('click', '.coupon-drawer-mask', $.proxy(this.toggleDrawer, this, false))
|
|
|
54
|
+ .on('click', '.coupon-btn-valid', $.proxy(this.saveCouponHandler, this));
|
|
|
55
|
+ },
|
|
|
56
|
+
|
|
|
57
|
+ render: function(data) {
|
|
|
58
|
+ this.$couponDrawer = $(this.template({
|
|
|
59
|
+ coupons: data
|
|
|
60
|
+ }));
|
|
|
61
|
+ this.$couponDrawer.appendTo('.good-detail-page');
|
|
|
62
|
+
|
|
|
63
|
+ return this;
|
|
|
64
|
+ },
|
|
|
65
|
+
|
|
|
66
|
+ // 获取 品牌券
|
|
|
67
|
+ fetchCoupons: function(skn, brandId) {
|
|
|
68
|
+ return $.get('/product/detail/coupon.json', {
|
|
|
69
|
+ skn: skn,
|
|
|
70
|
+ brandId: brandId
|
|
|
71
|
+ });
|
|
|
72
|
+ },
|
|
|
73
|
+
|
|
|
74
|
+ saveCoupon: function(couponId, callback) {
|
|
|
75
|
+ $.post('/product/detail/coupon/save.json', {
|
|
|
76
|
+ couponId: couponId
|
|
|
77
|
+ }).done(function(res) {
|
|
|
78
|
+ tip.show(res.message);
|
|
|
79
|
+
|
|
|
80
|
+ if (res.code === 200) {
|
|
|
81
|
+ callback(); // eslint-disable-line
|
|
|
82
|
+ } else {
|
|
|
83
|
+ tip.show(
|
|
|
84
|
+ res.message || '抱歉,您不符合领用条件'
|
|
|
85
|
+ );
|
|
|
86
|
+
|
|
|
87
|
+ if (res.redirect) {
|
|
|
88
|
+ setTimeout(function() {
|
|
|
89
|
+ location.href = res.redirect;
|
|
|
90
|
+ }, 1000);
|
|
|
91
|
+ }
|
|
|
92
|
+ }
|
|
|
93
|
+ }).fail(function() {
|
|
|
94
|
+ tip.show('网络异常,请稍后再试');
|
|
|
95
|
+ });
|
|
|
96
|
+ },
|
|
|
97
|
+
|
|
|
98
|
+ // 收藏 品牌券
|
|
|
99
|
+ saveCouponHandler: function(event) {
|
|
|
100
|
+ var $btn = $(event.target);
|
|
|
101
|
+ var couponId = $btn.closest('.coupon').data('coupon');
|
|
|
102
|
+
|
|
|
103
|
+ this.saveCoupon(couponId, function() {
|
|
|
104
|
+ $btn.prop('disabled', true)
|
|
|
105
|
+ .removeClass('coupon-btn-valid')
|
|
|
106
|
+ .text('已领取');
|
|
|
107
|
+ });
|
|
|
108
|
+
|
|
|
109
|
+ event.stopPropagation();
|
|
|
110
|
+ },
|
|
|
111
|
+
|
|
|
112
|
+ toggleDrawer: function(bool) {
|
|
|
113
|
+ this.$couponDrawer.toggleClass('open', bool);
|
|
|
114
|
+ $body.toggleClass('coupon-drawer-open', bool);
|
|
|
115
|
+ }
|
|
|
116
|
+};
|
|
|
117
|
+
|
|
|
118
|
+brandCoupon.init(
|
|
|
119
|
+ $('#productSkn').val(),
|
|
|
120
|
+ $('#brand-id').val()
|
|
|
121
|
+); |