Authored by 梁志锋

Merge branch 'feature-orderlist-opt' into release/wap-optim

... ... @@ -24,7 +24,19 @@ exports.order = (req, res, next) => {
uid: req.user.uid
};
orderModel.order(params).then(result => {
// 获取第一页数据做服务端渲染
let initialData = {
type: 1,
page: 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
};
return Promise.all([
orderModel.order(params),
orderModel.getOrders(initialData)
]).then(result => {
res.render('order', {
module: 'home',
page: 'order',
... ... @@ -33,9 +45,11 @@ exports.order = (req, res, next) => {
}),
title: 'Yoho!Buy 有货',
pageFooter: true,
order: result
order: result[0] || [],
firstPageOrdersList: result[1] || []
});
}).catch(next);
};
/**
... ... @@ -45,13 +59,20 @@ exports.order = (req, res, next) => {
* @param next
*/
exports.getOrders = (req, res, next) => {
orderModel.getOrders({
let start = req.query.start || 0;
let params = {
type: req.query.type || 1,
page: req.query.page || 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
}).then(result => {
};
orderModel.getOrders(params).then(result => {
if (result && parseInt(params.page, 10) === 1 && parseInt(start, 10) > 0) {
result = result.slice(start || 0);
}
res.render('order-content', {
layout: false,
orders: result
... ...
... ... @@ -9,6 +9,21 @@
</ul>
<div id="order-container" class="order-container">
{{#if walkwayUrl}}
<div class="no-order">
<div class="icon"></div>
<span>你还没有订单!</span>
<a class="walk-way" href="{{walkwayUrl}}">随便逛逛</a>
</div>
{{^}}
<div class="firstscreen-orders">
{{#each @root.firstPageOrdersList}}
{{> order/order}}
{{/each}}
</div>
{{/if}}
{{#each navs}}
<div class="orders{{#unless active}} hide{{/unless}}"></div>
{{/each}}
... ...
... ... @@ -20,7 +20,7 @@ var winH = $(window).height();
var activeType = $navLi.filter('.active').data('type'); // 当前active的项的index
var order = {
page: 0,
page: 1,
end: false
};
... ... @@ -34,6 +34,9 @@ var orderHammer,
$reaMask = $('.reason-mask'),
reasonSwiper;
// 首屏加载标志
var firstScreen = $('.firstscreen-orders').children().size() > 0;
require('../common');
// 减少计时
... ... @@ -58,8 +61,8 @@ function downCount(item) {
seconds;
// calculate dates
hours = Math.floor((difference % _day) / _hour),
minutes = Math.floor((difference % _hour) / _minute),
hours = Math.floor((difference % _day) / _hour);
minutes = Math.floor((difference % _hour) / _minute);
seconds = Math.floor((difference % _minute) / _second);
// fix dates so that it will show two digets
... ... @@ -106,6 +109,11 @@ function getOrders(option) {
page: order.page + 1
};
if (firstScreen) {
// 如果首屏加载了,则去掉10条记录
opt.start = 10;
}
var show = option && !option.noLoadingMask;
if (inAjax) {
... ... @@ -154,6 +162,9 @@ function getOrders(option) {
setTime();
}
});
// 还原参数
firstScreen = false;
}
lazyLoad({
... ... @@ -265,7 +276,7 @@ $(window).scroll(function() {
});
// 初始化请求第一页数据
getOrders();
//getOrders();
$(function() {
reasonSwiper = new Swiper('.box-main', {
... ... @@ -273,7 +284,7 @@ $(function() {
slidesPerView: 5,
centeredSlides: true,
initialSlide: 0,
onSlideChangeStart: function(reasonSwiper) {
onSlideChangeStart: function(reasonSwiper) {//eslint-disable-line
var activeIndex = reasonSwiper.activeIndex,
slides = reasonSwiper.slides,
i = 0;
... ... @@ -301,7 +312,7 @@ $(function() {
});
});
$reaMask.find('.box-cmp').on('touchend', function(e) {
$reaMask.find('.box-cmp').on('touchend', function() {
var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex],
reason = $(selSolid).text(),
reasonId = $(selSolid).data('reasonId');
... ...