order.page.js
3.42 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* [个人中心]首页/我的订单
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/07/04
*/
var tableOperation = {
$header: $('.table.column-category'),
$body: $('.table.table-body'),
removeBody: function() {
this.$body = $('.table.table-body');
},
appendBody: function(htmlStr) {
this.$body.remove();
$(htmlStr).appendTo(this.$header);
}
};
var countDown = {
count: null,
intervalTimer: null,
intervalValue: 60000,
$element: null,
selector: '.left-time',
setTime: function() {
var that = this;
this.$element.each(function(index, item) {
var $item = $(item);
var leftTime = $item.data('left');
$item.text(that.convertLeftTime(leftTime - that.count * 60));
});
this.count += 1;
},
convertLeftTime: function(src) {
var min = parseInt(src / 60, 10) % 60;
var hour = parseInt(src / 3600, 10);
var timeStr = min + '分钟';
if (src <= 0) {
timeStr = '已失效';
return timeStr;
}
if (hour > 0) {
timeStr = hour + '小时' + timeStr;
}
timeStr = '剩余' + timeStr;
return timeStr;
},
getLeftTime: function() {
var that = this;
if (this.$element.length) {
this.setTime();
this.intervalTimer = setInterval(this.setTime.bind(that), that.intervalValue);
}
},
start: function() {
this.count = 0;
this.$element = $(this.selector);
if (this.intervalTimer) {
clearInterval(this.intervalTimer);
}
this.getLeftTime();
}
};
require('./me');
function getOrderList(type, page) {
tableOperation.removeBody();
$.ajax({
url: 'getOrderList',
data: {
type: type,
page: page
}
}).done(function(res) {
tableOperation.appendBody(res);
bindPaginationClick(); // eslint-disable-line
countDown.start();
}).fail(function(err) {
console.log(err);
});
}
function getQueryString() {
var queryArr = location.search.substr(1).split('&');
var query = {};
queryArr.forEach(function(pair) {
var arr = pair.split('=');
query[arr[0]] = arr[1];
});
return query;
}
function bindPaginationClick() {
$('.blk-pagination li').off('click').on('click', function(e) {
var $this = $(this);
var page = $this.find('a').attr('href').split('=')[1];
var type = getQueryString().type;
e.preventDefault();
if (!$this.hasClass('active')) {
$('.blk-pagination li.active').removeClass('active');
$this.addClass('active');
$(window).scrollTop(0);
getOrderList(type, page);
}
});
}
$('.tabs li').on('click', function() {
var $this = $(this);
var $searchBar = $('.search-bar');
var typeMap = {
all: 1,
paying: 2,
delivering: 3
};
var type = typeMap[$this.data('type')];
var page = getQueryString().page;
if (!$this.hasClass('active')) {
$('.tabs li.active').removeClass('active');
$this.addClass('active');
if (type !== 1) {
$searchBar.addClass('vhide');
} else {
$searchBar.removeClass('vhide');
}
getOrderList(type, page);
}
});
bindPaginationClick();
countDown.start();