|
@@ -11,36 +11,41 @@ var $ = require('jquery'), |
|
@@ -11,36 +11,41 @@ var $ = require('jquery'), |
11
|
var $navLi = $('#order-nav > li'),
|
11
|
var $navLi = $('#order-nav > li'),
|
12
|
$orderContainer = $('#order-container');
|
12
|
$orderContainer = $('#order-container');
|
13
|
|
13
|
|
14
|
-var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container
|
14
|
+var $curContainer = $orderContainer.children('.orders:not(.hide)');//保存当前显示的order-container
|
15
|
|
15
|
|
16
|
var winH = $(window).height();
|
16
|
var winH = $(window).height();
|
17
|
|
17
|
|
18
|
-var activeIndex = 0; //当前active的项的index
|
18
|
+var activeType = $navLi.filter('.active').data('type'); //当前active的项的index
|
19
|
|
19
|
|
20
|
-var orderPage = [1, 0, 0, 0];
|
20
|
+var orderPage = {};
|
21
|
|
21
|
|
22
|
-var loading = false;
|
22
|
+var inAjax = false;
|
|
|
23
|
+
|
|
|
24
|
+var loading = require('../plugin/loading');
|
23
|
|
25
|
|
24
|
var navHammer, orderHammer;
|
26
|
var navHammer, orderHammer;
|
25
|
|
27
|
|
26
|
//加载订单
|
28
|
//加载订单
|
27
|
function getOrders() {
|
29
|
function getOrders() {
|
28
|
var opt = {
|
30
|
var opt = {
|
29
|
- type: activeIndex + 1,
|
|
|
30
|
- page: orderPage[activeIndex] + 1
|
|
|
31
|
- },
|
|
|
32
|
- num;
|
31
|
+ type: activeType,
|
|
|
32
|
+ page: orderPage[activeType] ? (orderPage[activeType] + 1) : 1
|
|
|
33
|
+ };
|
33
|
|
34
|
|
34
|
- if (loading) {
|
35
|
+ if (inAjax) {
|
35
|
return;
|
36
|
return;
|
36
|
}
|
37
|
}
|
37
|
|
38
|
|
|
|
39
|
+ inAjax = true;
|
|
|
40
|
+ loading.show();
|
38
|
|
41
|
|
39
|
$.ajax({
|
42
|
$.ajax({
|
40
|
type: 'GET',
|
43
|
type: 'GET',
|
41
|
url: '/home/getOrders',
|
44
|
url: '/home/getOrders',
|
42
|
data: opt,
|
45
|
data: opt,
|
43
|
success: function(data) {
|
46
|
success: function(data) {
|
|
|
47
|
+ var num;
|
|
|
48
|
+
|
44
|
if (data.code === 200) {
|
49
|
if (data.code === 200) {
|
45
|
orderPage[opt.type] = opt.page;
|
50
|
orderPage[opt.type] = opt.page;
|
46
|
|
51
|
|
|
@@ -55,35 +60,54 @@ function getOrders() { |
|
@@ -55,35 +60,54 @@ function getOrders() { |
55
|
lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy'));
|
60
|
lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy'));
|
56
|
}
|
61
|
}
|
57
|
}
|
62
|
}
|
|
|
63
|
+
|
|
|
64
|
+ inAjax = false;
|
|
|
65
|
+ loading.hide();
|
58
|
}
|
66
|
}
|
59
|
});
|
67
|
});
|
60
|
}
|
68
|
}
|
61
|
|
69
|
|
62
|
lazyLoad();
|
70
|
lazyLoad();
|
63
|
|
71
|
|
|
|
72
|
+//初始化导航
|
|
|
73
|
+(function() {
|
|
|
74
|
+ var liCount = $navLi.length;
|
|
|
75
|
+
|
|
|
76
|
+ //默认4个导航项
|
|
|
77
|
+ if (liCount === 4) {
|
|
|
78
|
+ return;
|
|
|
79
|
+ }
|
|
|
80
|
+
|
|
|
81
|
+ $navLi.width(100 / liCount + '%');
|
|
|
82
|
+}());
|
|
|
83
|
+
|
|
|
84
|
+loading.init();
|
|
|
85
|
+
|
64
|
//导航切换
|
86
|
//导航切换
|
65
|
navHammer = new Hammer(document.getElementById('order-nav'));
|
87
|
navHammer = new Hammer(document.getElementById('order-nav'));
|
66
|
navHammer.on('tap', function(e) {
|
88
|
navHammer.on('tap', function(e) {
|
67
|
- var $cur = $(e.target).closest('li');
|
89
|
+ var $cur = $(e.target).closest('li'),
|
|
|
90
|
+ index;
|
68
|
|
91
|
|
69
|
if ($cur.length === 0 || $cur.hasClass('active')) {
|
92
|
if ($cur.length === 0 || $cur.hasClass('active')) {
|
70
|
return;
|
93
|
return;
|
71
|
}
|
94
|
}
|
72
|
|
95
|
|
73
|
- activeIndex = +$cur.index();
|
96
|
+ index = $cur.index();
|
74
|
|
97
|
|
75
|
$navLi.filter('.active').removeClass('active');
|
98
|
$navLi.filter('.active').removeClass('active');
|
76
|
$cur.addClass('active');
|
99
|
$cur.addClass('active');
|
77
|
|
100
|
|
78
|
$curContainer.addClass('hide');
|
101
|
$curContainer.addClass('hide');
|
79
|
- $curContainer = $orderContainer.children(':eq(' + activeIndex + ')').removeClass('hide');
|
102
|
+ $curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
|
80
|
|
103
|
|
81
|
- if (orderPage[activeIndex] > 0) {
|
104
|
+ activeType = $cur.data('type');
|
|
|
105
|
+
|
|
|
106
|
+ if (orderPage[activeType]) {
|
82
|
return;
|
107
|
return;
|
83
|
} else {
|
108
|
} else {
|
84
|
getOrders();
|
109
|
getOrders();
|
85
|
}
|
110
|
}
|
86
|
-
|
|
|
87
|
});
|
111
|
});
|
88
|
|
112
|
|
89
|
//点击订单区域跳转订单详情页
|
113
|
//点击订单区域跳转订单详情页
|
|
@@ -109,6 +133,13 @@ orderHammer.on('tap', function(e) { |
|
@@ -109,6 +133,13 @@ orderHammer.on('tap', function(e) { |
109
|
url: '/home/delOrder',
|
133
|
url: '/home/delOrder',
|
110
|
data: {
|
134
|
data: {
|
111
|
id: id
|
135
|
id: id
|
|
|
136
|
+ },
|
|
|
137
|
+ success: function(data) {
|
|
|
138
|
+ if (data.code === 200) {
|
|
|
139
|
+
|
|
|
140
|
+ //删除订单页面刷新
|
|
|
141
|
+ location.href = location.href;
|
|
|
142
|
+ }
|
112
|
}
|
143
|
}
|
113
|
});
|
144
|
});
|
114
|
} else if ($cur.closest('.cancel').length > 0) {
|
145
|
} else if ($cur.closest('.cancel').length > 0) {
|
|
@@ -119,6 +150,13 @@ orderHammer.on('tap', function(e) { |
|
@@ -119,6 +150,13 @@ orderHammer.on('tap', function(e) { |
119
|
url: '/home/cancelOrder',
|
150
|
url: '/home/cancelOrder',
|
120
|
data: {
|
151
|
data: {
|
121
|
id: id
|
152
|
id: id
|
|
|
153
|
+ },
|
|
|
154
|
+ success: function(data) {
|
|
|
155
|
+ if (data.code === 200) {
|
|
|
156
|
+
|
|
|
157
|
+ //取消订单
|
|
|
158
|
+ alert('order cancel');
|
|
|
159
|
+ }
|
122
|
}
|
160
|
}
|
123
|
});
|
161
|
});
|
124
|
} else {
|
162
|
} else {
|
|
@@ -134,4 +172,7 @@ $(window).scroll(function() { |
|
@@ -134,4 +172,7 @@ $(window).scroll(function() { |
134
|
$(document).height() - 0.25 * $orderContainer.height()) {
|
172
|
$(document).height() - 0.25 * $orderContainer.height()) {
|
135
|
getOrders();
|
173
|
getOrders();
|
136
|
}
|
174
|
}
|
137
|
-}); |
|
|
|
|
175
|
+});
|
|
|
176
|
+
|
|
|
177
|
+//初始化请求第一页数据
|
|
|
178
|
+getOrders(); |