Authored by xuqi

order list rebuild

... ... @@ -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
... ...
... ... @@ -2,27 +2,17 @@
<div class="order-page yoho-page">
{{# order}}
<ul id="order-nav" class="order-nav clearfix">
<li class="active">
全部
</li>
<li>
待付款
</li>
<li>
待发货
</li>
<li>
待收货
</li>
{{#each navs}}
<li {{#if active}}class="active"{{/if}} data-type="{{typeId}}">
{{name}}
</li>
{{/each}}
</ul>
<div id="order-container" class="order-container">
<div class="all orders">
{{> me/order/orders}}
</div>
<div class="unpaid orders hide"></div>
<div class="unshipped orders hide"></div>
<div class="unreceived orders hide"></div>
{{#each navs}}
<div class="orders{{#unless active}} hide{{/unless}}"></div>
{{/each}}
</div>
{{/ order}}
</div>
... ...
... ... @@ -534,12 +534,12 @@ class HomeController extends AbstractAction
$data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);
//如果没有订单数据,就给一个随便逛逛链接
$order = array();
if (!empty($data)) {
$order['orders'] = $data;
} else {
$order['walkwayUrl'] = 'http://www.baidu.com';
}
// if (!empty($data)) {
// $order['orders'] = $data;
// } else {
// $order['walkwayUrl'] = 'http://www.baidu.com';
// }
$order['walkwayUrl'] = 'http://m.yohobuy.com';
//渲染模板
$this->_view->display('order', array(
'order' => $order,
... ...