...
|
...
|
@@ -11,36 +11,41 @@ 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;
|
|
|
var inAjax = false;
|
|
|
|
|
|
var loading = require('../plugin/loading');
|
|
|
|
|
|
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) {
|
|
|
if (inAjax) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
inAjax = true;
|
|
|
loading.show();
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/home/getOrders',
|
|
|
data: opt,
|
|
|
success: function(data) {
|
|
|
var num;
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
orderPage[opt.type] = opt.page;
|
|
|
|
...
|
...
|
@@ -55,35 +60,54 @@ function getOrders() { |
|
|
lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
inAjax = false;
|
|
|
loading.hide();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
lazyLoad();
|
|
|
|
|
|
//初始化导航
|
|
|
(function() {
|
|
|
var liCount = $navLi.length;
|
|
|
|
|
|
//默认4个导航项
|
|
|
if (liCount === 4) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$navLi.width(100 / liCount + '%');
|
|
|
}());
|
|
|
|
|
|
loading.init();
|
|
|
|
|
|
//导航切换
|
|
|
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');
|
|
|
|
|
|
if (orderPage[activeIndex] > 0) {
|
|
|
activeType = $cur.data('type');
|
|
|
|
|
|
if (orderPage[activeType]) {
|
|
|
return;
|
|
|
} else {
|
|
|
getOrders();
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//点击订单区域跳转订单详情页
|
...
|
...
|
@@ -109,6 +133,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 +150,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 +172,7 @@ $(window).scroll(function() { |
|
|
$(document).height() - 0.25 * $orderContainer.height()) {
|
|
|
getOrders();
|
|
|
}
|
|
|
}); |
|
|
\ No newline at end of file |
|
|
});
|
|
|
|
|
|
//初始化请求第一页数据
|
|
|
getOrders(); |
|
|
\ No newline at end of file |
...
|
...
|
|