Authored by uedxwg

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

... ... @@ -939,14 +939,27 @@
### 我的订单
{
order: {
orders: [
navs: [
{
name: '',
active: true,
typeId: 1
},
...
],
//没有订单的情况不传orders
walkWayUrl: '' //随便逛逛url
]
}
}
//订单列表
{
orders: [
{
...//订单
}
]
//当无订单时,不传order,返回walkwayUrl
walkWayUrl: ''
}
//订单
{
... ...
... ... @@ -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');
activeType = $cur.data('type');
if (orderPage[activeIndex] > 0) {
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 {
... ... @@ -135,3 +173,6 @@ $(window).scroll(function() {
getOrders();
}
});
//初始化请求第一页数据
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>
待收货
{{#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,30 @@ 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['navs'] = array(
array(
'name' => '全部',
'active' => true,
'typeId' => '1'
),
array(
'name' => '待付款',
'typeId' => '2'
),
array(
'name' => '待发货',
'typeId' => '3'
),
array(
'name' => '待收货',
'typeId' => '4'
)
);
//渲染模板
$this->_view->display('order', array(
'order' => $order,
... ...