...
|
...
|
@@ -11,13 +11,13 @@ var $ = require('jquery'), |
|
|
var $navLi = $('#order-nav > li'),
|
|
|
$orderContainer = $('#order-container');
|
|
|
|
|
|
var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container
|
|
|
var $curContainer = $orderContainer.children('.orders:not(.hide)');//保存当前显示的order-container
|
|
|
|
|
|
var winH = $(window).height();
|
|
|
|
|
|
var activeIndex = 0; //当前active的项的index
|
|
|
var activeType = $navLi.filter('.active').data('type'); //当前active的项的index
|
|
|
|
|
|
var orderPage = [1, 0, 0, 0];
|
|
|
var orderPage = {};
|
|
|
|
|
|
var loading = false;
|
|
|
|
...
|
...
|
@@ -26,21 +26,21 @@ var navHammer, orderHammer; |
|
|
//加载订单
|
|
|
function getOrders() {
|
|
|
var opt = {
|
|
|
type: activeIndex + 1,
|
|
|
page: orderPage[activeIndex] + 1
|
|
|
},
|
|
|
num;
|
|
|
type: activeType,
|
|
|
page: orderPage[activeType] ? (orderPage[activeType] + 1) : 1
|
|
|
};
|
|
|
|
|
|
if (loading) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/home/getOrders',
|
|
|
data: opt,
|
|
|
success: function(data) {
|
|
|
var num;
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
orderPage[opt.type] = opt.page;
|
|
|
|
...
|
...
|
@@ -61,29 +61,43 @@ function getOrders() { |
|
|
|
|
|
lazyLoad();
|
|
|
|
|
|
//初始化导航
|
|
|
(function() {
|
|
|
var liCount = $navLi.length;
|
|
|
|
|
|
//默认4个导航项
|
|
|
if (liCount === 4) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$navLi.width(100 / liCount + '%');
|
|
|
}());
|
|
|
|
|
|
//导航切换
|
|
|
navHammer = new Hammer(document.getElementById('order-nav'));
|
|
|
navHammer.on('tap', function(e) {
|
|
|
var $cur = $(e.target).closest('li');
|
|
|
var $cur = $(e.target).closest('li'),
|
|
|
index;
|
|
|
|
|
|
if ($cur.length === 0 || $cur.hasClass('active')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
activeIndex = +$cur.index();
|
|
|
index = $cur.index();
|
|
|
|
|
|
$navLi.filter('.active').removeClass('active');
|
|
|
$cur.addClass('active');
|
|
|
|
|
|
$curContainer.addClass('hide');
|
|
|
$curContainer = $orderContainer.children(':eq(' + activeIndex + ')').removeClass('hide');
|
|
|
$curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
|
|
|
|
|
|
activeType = $cur.data('type');
|
|
|
|
|
|
if (orderPage[activeIndex] > 0) {
|
|
|
if (orderPage[activeType]) {
|
|
|
return;
|
|
|
} else {
|
|
|
getOrders();
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//点击订单区域跳转订单详情页
|
...
|
...
|
@@ -109,6 +123,13 @@ orderHammer.on('tap', function(e) { |
|
|
url: '/home/delOrder',
|
|
|
data: {
|
|
|
id: id
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
//删除订单页面刷新
|
|
|
location.href = location.href;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else if ($cur.closest('.cancel').length > 0) {
|
...
|
...
|
@@ -119,6 +140,13 @@ orderHammer.on('tap', function(e) { |
|
|
url: '/home/cancelOrder',
|
|
|
data: {
|
|
|
id: id
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
//取消订单
|
|
|
alert('order cancel');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else {
|
...
|
...
|
@@ -134,4 +162,7 @@ $(window).scroll(function() { |
|
|
$(document).height() - 0.25 * $orderContainer.height()) {
|
|
|
getOrders();
|
|
|
}
|
|
|
}); |
|
|
\ No newline at end of file |
|
|
});
|
|
|
|
|
|
//初始化请求第一页数据
|
|
|
getOrders(); |
|
|
\ No newline at end of file |
...
|
...
|
|