controller.js
3.64 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import $ from 'yoho-jquery';
import Page from 'yoho-page';
import couponValidHbs from 'home/coupon-valid.hbs';
class ConponController extends Page {
constructor() {
super();
this.status = 0;
this.couponType = 'notuse';
this.couponFilter = 0;
this.page = 1;
this.view = {
filterBtn: $('.filter-btn'),
filterItem: $('.filter-item'),
showFilterBtn: $('.show-filter-btn'),
couponList: $('#couponList')
};
this.view.filterBtn.on('click', this.tapChange.bind(this));
this.view.showFilterBtn.on('click', this.showFilter.bind(this));
this.view.filterItem.on('click', 'button', this.filterCoupons.bind(this));
// this.renderCoupons();
}
/**
* 筛选优惠券
*/
filterCoupons(evt) {
let currentTarget = $(evt.currentTarget);
this.view.filterItem.find('button').removeClass('active');
currentTarget.addClass('active');
if (currentTarget.hasClass('all')) {
console.log('all');
} else if (currentTarget.hasClass('shop')) {
console.log('shop');
} else if (currentTarget.hasClass('activity')) {
console.log('activity');
} else if (currentTarget.hasClass('freight')) {
console.log('freight');
} else {
console.log('error');
}
}
/**
* 渲染优惠券列表
*/
renderCoupons() {
this.getCoupons().then(result => {
let couponValidHbsHtml = $(couponValidHbs(result));
couponValidHbsHtml.on('click', '.show-intro-btn', this.showIntro.bind(this));
this.view.couponList.html(couponValidHbsHtml);
});
}
/**
* 获取优惠券
*/
getCoupons() {
return this.ajax({
type: 'POST',
url: '/home/coupons.json',
dataType: 'json',
data: {
type: this.couponType,
filter: this.couponFilter,
page: this.page
},
});
}
/**
* tab 切换
*/
tapChange(event) {
let itemClicked = $(event.currentTarget);
if (itemClicked.hasClass('no-used')) {
this.status = 0;
} else if (itemClicked.hasClass('used')) {
this.status = 1;
} else if (itemClicked.hasClass('invalid')) {
this.status = 2;
}
this.renderCoupons();
if (itemClicked.hasClass('active')) {
itemClicked.removeClass('active');
} else {
this.view.filterBtn.removeClass('active');
itemClicked.addClass('active');
}
}
/**
* 展示筛选器
*/
showFilter() {
if (this.view.filterItem.hasClass('hide')) {
this.view.filterItem.removeClass('hide');
this.view.showFilterBtn.removeClass('icon-down').addClass('icon-up');
} else {
this.view.filterItem.addClass('hide');
this.view.showFilterBtn.removeClass('icon-up').addClass('icon-down');
}
}
/**
* 展示优惠券介绍
*/
showIntro(e) {
let delegateTarget = $(e.delegateTarget);
let couponIntro = delegateTarget.find('.coupon-intro');
let showIntroIcon = delegateTarget.find('.show-intro-icon');
if (couponIntro.hasClass('hide')) {
couponIntro.removeClass('hide');
showIntroIcon.removeClass('icon-down').addClass('icon-up');
} else {
couponIntro.addClass('hide');
showIntroIcon.removeClass('icon-up').addClass('icon-down');
}
}
}
export default ConponController;