Authored by biao

Merge branch 'feature/my-order' into develop

... ... @@ -44,7 +44,20 @@ const getOrderList = (req, res) => {
});
};
const getOrderTotal = (req, res) => {
const type = req.query.type;
orderModel.getOrderData(type).then(result => {
res.json({
total: result.order.total,
type: result.order.type
});
});
};
module.exports = {
index: index,
getOrderList: getOrderList
getOrderList: getOrderList,
getOrderTotal: getOrderTotal
};
... ...
... ... @@ -85,7 +85,9 @@ const getOrderData = (type, page) => {
return _getUserOrder(type, page).then(result => {
const basicData = {
title: '我的订单',
showSearch: type === 1
showSearch: type === 1,
total: result.total,
type: type
};
navBar.tabs[typeActiveIndexMap[type]].isActive = true;
... ...
... ... @@ -16,6 +16,7 @@ const address = require(`${cRoot}/address`);
// 个人中心首页/订单
router.get(['/', '/order'], order.index);
router.get('/getOrderList', order.getOrderList);
router.get('/getOrderTotal', order.getOrderTotal);
// 个人中心首页/收货地址
router.get('/address', address.index);
... ...
<div class="order-nav">
<ul class="tabs clearfix">
{{#tabs}}
<li class="{{#if isActive}}active{{/if}}" data-type="{{typeStr}}">{{text}}</li>
<li class="{{#if isActive}}active{{/if}}" data-type="{{typeStr}}"><span class="badge"></span>{{text}}</li>
{{/tabs}}
</ul>
<div class="search-bar {{#unless showSearch}}vhide{{/unless}}">
... ...
... ... @@ -36,7 +36,7 @@ var countDown = {
convertLeftTime: function(src) {
var min = parseInt(src / 60, 10) % 60;
var hour = parseInt(src / 3600, 10);
var timeStr = min + '分';
var timeStr = min + '分';
if (src <= 0) {
timeStr = '已失效';
... ... @@ -44,7 +44,7 @@ var countDown = {
}
if (hour > 0) {
timeStr = hour + '时' + timeStr;
timeStr = hour + '时' + timeStr;
}
timeStr = '剩余' + timeStr;
... ... @@ -69,6 +69,12 @@ var countDown = {
}
};
var typeMap = {
all: 1,
paying: 2,
delivering: 3
};
require('./me');
function getOrderList(type, page) {
... ... @@ -104,9 +110,6 @@ function getQueryString() {
}
function bindPaginationClick() {
$('.blk-pagination li').off('click').on('click', function(e) {
var $this = $(this);
... ... @@ -126,15 +129,36 @@ function bindPaginationClick() {
});
}
function getOrderTotal(type, key) {
$.ajax({
url: 'getOrderTotal',
data: {
type: type
}
}).done(function(result) {
var $navItme = $('*[data-type="' + key + '"]');
if (!$navItme.hasClass('active') && result.total !== 0) {
$navItme.find('.badge').text(result.total);
}
});
}
function setOrderTotal() {
var key;
for (key in typeMap) {
if (key !== 'all') {
getOrderTotal(typeMap[key], key);
}
}
}
$('.tabs li').on('click', function() {
var $this = $(this);
var $searchBar = $('.search-bar');
var typeMap = {
all: 1,
paying: 2,
delivering: 3
};
var type = typeMap[$this.data('type')];
var page = getQueryString().page;
... ... @@ -142,6 +166,7 @@ $('.tabs li').on('click', function() {
if (!$this.hasClass('active')) {
$('.tabs li.active').removeClass('active');
$this.addClass('active');
$this.find('.badge').text('');
if (type !== 1) {
$searchBar.addClass('vhide');
... ... @@ -157,3 +182,5 @@ $('.tabs li').on('click', function() {
bindPaginationClick();
countDown.start();
setOrderTotal();
... ...
... ... @@ -9,6 +9,20 @@
border-bottom: 1px solid $liBorderColor;
z-index: 0;
.badge {
min-width: 16px;
line-height: 16px;
display: inline-block;
padding: 0px 5px;
position: absolute;
top: 0;
right: 14px;
background-color: #379ed6;
color: #fff;
border-radius: 9px;
font-size: 12px;
}
.tabs {
display: inline-block;
height: $liHeight;
... ... @@ -23,12 +37,12 @@
background-color: #fff;
color: $fontColor;
cursor: pointer;
position: relative;
&.active {
border: 1px solid $liBorderColor;
height: calc($liHeight + 1px);
line-height: calc($liHeight - 2px);
position: relative;
top: 1px;
border-bottom: none;
color: #515151;
... ...