|
@@ -13,32 +13,85 @@ var $navLi = $('#order-nav > li'), |
|
@@ -13,32 +13,85 @@ var $navLi = $('#order-nav > li'), |
13
|
|
13
|
|
14
|
var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container
|
14
|
var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container
|
15
|
|
15
|
|
|
|
16
|
+var winH = $(window).height();
|
|
|
17
|
+
|
|
|
18
|
+var activeIndex = 0; //当前active的项的index
|
|
|
19
|
+
|
|
|
20
|
+var orderPage = [1, 0, 0, 0];
|
|
|
21
|
+
|
|
|
22
|
+var loading = false;
|
|
|
23
|
+
|
16
|
var navHammer, orderHammer;
|
24
|
var navHammer, orderHammer;
|
17
|
|
25
|
|
|
|
26
|
+//加载订单
|
|
|
27
|
+function getOrders() {
|
|
|
28
|
+ var opt = {
|
|
|
29
|
+ type: activeIndex + 1,
|
|
|
30
|
+ page: orderPage[activeIndex] + 1
|
|
|
31
|
+ },
|
|
|
32
|
+ num;
|
|
|
33
|
+
|
|
|
34
|
+ if (loading) {
|
|
|
35
|
+ return;
|
|
|
36
|
+ }
|
|
|
37
|
+
|
|
|
38
|
+
|
|
|
39
|
+ $.ajax({
|
|
|
40
|
+ type: 'GET',
|
|
|
41
|
+ url: '/home/getOrders',
|
|
|
42
|
+ data: opt,
|
|
|
43
|
+ success: function(data) {
|
|
|
44
|
+ if (data.code === 200) {
|
|
|
45
|
+ orderPage[opt.type] = opt.page;
|
|
|
46
|
+
|
|
|
47
|
+ if (opt.page === 1) {
|
|
|
48
|
+ $curContainer.html(data.data);
|
|
|
49
|
+ lazyLoad($curContainer.find('.lazy'));
|
|
|
50
|
+ } else {
|
|
|
51
|
+ num = $curContainer.children('.order').length;
|
|
|
52
|
+ $curContainer.append(data.data);
|
|
|
53
|
+
|
|
|
54
|
+ //lazyload
|
|
|
55
|
+ lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy'));
|
|
|
56
|
+ }
|
|
|
57
|
+ }
|
|
|
58
|
+ }
|
|
|
59
|
+ });
|
|
|
60
|
+}
|
|
|
61
|
+
|
18
|
lazyLoad();
|
62
|
lazyLoad();
|
19
|
|
63
|
|
|
|
64
|
+//导航切换
|
20
|
navHammer = new Hammer(document.getElementById('order-nav'));
|
65
|
navHammer = new Hammer(document.getElementById('order-nav'));
|
21
|
navHammer.on('tap', function(e) {
|
66
|
navHammer.on('tap', function(e) {
|
22
|
- var $cur = $(e.target).closest('li'),
|
|
|
23
|
- index;
|
67
|
+ var $cur = $(e.target).closest('li');
|
24
|
|
68
|
|
25
|
if ($cur.length === 0 || $cur.hasClass('active')) {
|
69
|
if ($cur.length === 0 || $cur.hasClass('active')) {
|
26
|
return;
|
70
|
return;
|
27
|
}
|
71
|
}
|
28
|
|
72
|
|
29
|
- index = $cur.index();
|
73
|
+ activeIndex = +$cur.index();
|
30
|
|
74
|
|
31
|
$navLi.filter('.active').removeClass('active');
|
75
|
$navLi.filter('.active').removeClass('active');
|
32
|
$cur.addClass('active');
|
76
|
$cur.addClass('active');
|
33
|
|
77
|
|
34
|
$curContainer.addClass('hide');
|
78
|
$curContainer.addClass('hide');
|
35
|
- $curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
|
79
|
+ $curContainer = $orderContainer.children(':eq(' + activeIndex + ')').removeClass('hide');
|
|
|
80
|
+
|
|
|
81
|
+ if (orderPage[activeIndex] > 0) {
|
|
|
82
|
+ return;
|
|
|
83
|
+ } else {
|
|
|
84
|
+ getOrders();
|
|
|
85
|
+ }
|
|
|
86
|
+
|
36
|
});
|
87
|
});
|
37
|
|
88
|
|
|
|
89
|
+//点击订单区域跳转订单详情页
|
38
|
orderHammer = new Hammer(document.getElementById('order-container'));
|
90
|
orderHammer = new Hammer(document.getElementById('order-container'));
|
39
|
orderHammer.on('tap', function(e) {
|
91
|
orderHammer.on('tap', function(e) {
|
40
|
var $cur = $(e.target),
|
92
|
var $cur = $(e.target),
|
41
|
$order,
|
93
|
$order,
|
|
|
94
|
+ id,
|
42
|
url;
|
95
|
url;
|
43
|
|
96
|
|
44
|
if ($cur.closest('.locHref').length > 0) {
|
97
|
if ($cur.closest('.locHref').length > 0) {
|
|
@@ -46,7 +99,39 @@ orderHammer.on('tap', function(e) { |
|
@@ -46,7 +99,39 @@ orderHammer.on('tap', function(e) { |
46
|
}
|
99
|
}
|
47
|
|
100
|
|
48
|
$order = $cur.closest('.order');
|
101
|
$order = $cur.closest('.order');
|
49
|
- url = $order.data('href');
|
102
|
+ id = $order.data('id');
|
|
|
103
|
+
|
|
|
104
|
+ if ($cur.closest('.del').length > 0) {
|
|
|
105
|
+
|
|
|
106
|
+ //Order delete
|
|
|
107
|
+ $.ajax({
|
|
|
108
|
+ type: 'GET',
|
|
|
109
|
+ url: '/home/delOrder',
|
|
|
110
|
+ data: {
|
|
|
111
|
+ id: id
|
|
|
112
|
+ }
|
|
|
113
|
+ });
|
|
|
114
|
+ } else if ($cur.closest('.cancel').length > 0) {
|
50
|
|
115
|
|
|
|
116
|
+ //Order cancel
|
|
|
117
|
+ $.ajax({
|
|
|
118
|
+ type: 'GET',
|
|
|
119
|
+ url: '/home/cancelOrder',
|
|
|
120
|
+ data: {
|
|
|
121
|
+ id: id
|
|
|
122
|
+ }
|
|
|
123
|
+ });
|
|
|
124
|
+ } else {
|
|
|
125
|
+
|
|
|
126
|
+ //Location to order detail
|
|
|
127
|
+ url = $order.data('href');
|
51
|
location.href = url;
|
128
|
location.href = url;
|
|
|
129
|
+ }
|
|
|
130
|
+});
|
|
|
131
|
+
|
|
|
132
|
+$(window).scroll(function() {
|
|
|
133
|
+ if ($(window).scrollTop() + winH >
|
|
|
134
|
+ $(document).height() - 0.25 * $orderContainer.height()) {
|
|
|
135
|
+ getOrders();
|
|
|
136
|
+ }
|
52
|
}); |
137
|
}); |