Authored by biao

update for pagination

... ... @@ -38,7 +38,8 @@ const getOrderList = (req, res) => {
layout: false,
page: 'order',
isMe: true,
orderList: result.order.orderList
orderList: result.order.orderList,
paginationOpts: result.order.paginationOpts
});
});
};
... ...
'use strict';
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
... ... @@ -9,9 +11,21 @@ const _getUserOrder = (type, page) => {
page: page || 1,
limit: 10
}).then(result => {
const orderList = result && result.data && result.data.order_list || [];
let orderList = [];
let total = false;
let curPage = 1;
if (result && result.data) {
orderList = result.data.order_list;
total = result.data.total;
curPage = result.data.page;
}
return camelCase(orderList);
return {
orderList: camelCase(orderList),
total: total,
curPage: curPage
};
});
};
... ... @@ -41,11 +55,19 @@ const getOrderData = (type, page) => {
};
const order = Object.assign(fakeData, {
orderList: result.length && result || false
orderList: result.orderList.length && result.orderList || false
}, navBar);
const paginationOpts = {
paginationOpts: {
total: result.total,
page: result.curPage,
limit: 10
}
};
return {
order: order
order: Object.assign(order, paginationOpts)
};
});
};
... ...
... ... @@ -54,6 +54,7 @@
</div>
</div>
{{/orderList}}
{{{ pagination paginationOpts }}}
{{^}}
<div class="bg"></div>
<div class="msg">
... ...
... ... @@ -29,12 +29,12 @@ function getOrderList(type, page) {
}
}).done(function(res) {
tableOperation.appendBody(res);
bindPaginationClick(); // eslint-disable-line
}).fail(function(err) {
console.log(err);
});
}
function getQueryString() {
var queryArr = location.search.substr(1).split('&');
var query = {};
... ... @@ -49,6 +49,24 @@ function getQueryString() {
return query;
}
function bindPaginationClick() {
$('.blk-pagination li').off('click').on('click', function(e) {
var $this = $(this);
var page = $this.find('a').attr('href').split('=')[1];
var type = getQueryString().type;
e.preventDefault();
if (!$this.hasClass('active')) {
$('.blk-pagination li.active').removeClass('active');
$this.addClass('active');
getOrderList(type, page);
}
});
}
$('.tabs li').on('click', function() {
var $this = $(this);
var typeMap = {
... ... @@ -62,7 +80,11 @@ $('.tabs li').on('click', function() {
if (!$this.hasClass('active')) {
$('.tabs li.active').removeClass('active');
$this.addClass('active');
getOrderList(type, page);
}
getOrderList(type, page);
});
bindPaginationClick();
... ...
... ... @@ -207,5 +207,10 @@
}
}
}
.blk-pagination {
margin: $bigSpace auto -$bigSpace;
text-align: center;
}
}
... ...