Authored by 姜枫

handle merge

... ... @@ -2,69 +2,105 @@
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const moment = require('moment');
const pageSize = 10;
const typeActiveIndexMap = {
1: 0,
2: 1,
3: 2
};
const _getUserOrder = (type, page) => {
const convertUnitTime = (src) => {
return moment.unix(src).format('YYYY-MM-DD hh:mm:ss');
};
return api.get('', {
method: 'app.SpaceOrders.get',
uid: '10931021',
type: type || 1,
page: page || 1,
limit: 10
type: type,
page: page,
limit: pageSize
}).then(result => {
let orderList = [];
let total = false;
let curPage = 1;
if (result && result.data) {
orderList = result.data.order_list;
orderList = camelCase(result.data.order_list);
total = result.data.total;
curPage = result.data.page;
}
orderList.forEach(function(item) {
const ot = parseInt(item.orderType, 10);
// 转换订单创建时间
item.createTime = convertUnitTime(item.createTime);
// 隐藏为了的剩余时间
if (parseInt(item.payLefttime, 10) === 0) {
item.payLefttime = false;
}
// 判断是否是手机订单,3, 4, 6对应 iOS, Android, H5
// 具体订单类型见 http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E8%AE%A2%E5%8D%95/order.md
item.showMobile = ot === 3 || ot === 4 || ot === 6;
});
return {
orderList: camelCase(orderList),
orderList: orderList,
total: total,
curPage: curPage
};
});
};
const navBar = {
tabs: [
{
text: '全部订单',
isActive: true,
type: 'all'
},
{
text: '待付款',
type: 'paying'
},
{
text: '待发货',
type: 'delivering'
}
]
};
const getOrderData = (type, page) => {
const navBar = {
tabs: [
{
text: '全部订单',
typeStr: 'all'
},
{
text: '待付款',
typeStr: 'paying'
},
{
text: '待发货',
typeStr: 'delivering'
}
]
};
type = parseInt(type, 10);
type = type < 4 ? type : 1;
page = page || 1;
return _getUserOrder(type, page).then(result => {
const fakeData = {
const basicData = {
title: '我的订单',
showSearch: true
showSearch: type === 1
};
const order = Object.assign(fakeData, {
navBar.tabs[typeActiveIndexMap[type]].isActive = true;
const order = Object.assign(basicData, {
orderList: result.orderList.length && result.orderList || false
}, navBar);
const paginationOpts = {
const paginationOpts = result.total > pageSize ? {
paginationOpts: {
total: result.total,
page: result.curPage,
limit: 10
limit: pageSize
}
};
} : false;
return {
order: Object.assign(order, paginationOpts)
... ...
<div class="order-nav">
<ul class="tabs clearfix">
{{#tabs}}
<li class="{{#if isActive}}active{{/if}}" data-type="{{type}}">{{text}}</li>
<li class="{{#if isActive}}active{{/if}}" data-type="{{typeStr}}">{{text}}</li>
{{/tabs}}
</ul>
<div class="search-bar">
<div class="search-bar {{#unless showSearch}}vhide{{/unless}}">
<input class="search-ctrl" type="text" placeholder="商品名称和订单号">
<button class="search-ctrl">搜索订单</button>
</div>
... ...
... ... @@ -38,8 +38,8 @@
<p class="subtext">查看详情</p>
</div>
<div class="common-column special-border">
{{#if payLeftTime}}
<p class="left-time">剩余{{payLeftTime}}</p>
{{#if payLefttime}}
<p class="left-time" data-left="{{payLefttime}}"></p>
{{/if}}
{{#if showPayButton}}
<button>立即付款</button>
... ... @@ -54,7 +54,9 @@
</div>
</div>
{{/orderList}}
{{#if paginationOpts}}
{{{ pagination paginationOpts }}}
{{/if}}
{{^}}
<div class="bg"></div>
<div class="msg">
... ...
... ... @@ -9,13 +9,66 @@ var tableOperation = {
$body: $('.table.table-body'),
removeBody: function() {
this.$body = $('.table.table-body');
this.$body.remove();
},
appendBody: function(htmlStr) {
this.$body.remove();
$(htmlStr).appendTo(this.$header);
}
};
var countDown = {
count: null,
intervalTimer: null,
intervalValue: 60000,
$element: null,
selector: '.left-time',
setTime: function() {
var that = this;
this.$element.each(function(index, item) {
var $item = $(item);
var leftTime = $item.data('left');
$item.text(that.convertLeftTime(leftTime - that.count * 60));
});
this.count += 1;
},
convertLeftTime: function(src) {
var min = parseInt(src / 60, 10) % 60;
var hour = parseInt(src / 3600, 10);
var timeStr = min + '分钟';
if (src <= 0) {
timeStr = '已失效';
return timeStr;
}
if (hour > 0) {
timeStr = hour + '小时' + timeStr;
}
timeStr = '剩余' + timeStr;
return timeStr;
},
getLeftTime: function() {
var that = this;
if (this.$element.length) {
this.setTime();
this.intervalTimer = setInterval(this.setTime.bind(that), that.intervalValue);
}
},
start: function() {
this.count = 0;
this.$element = $(this.selector);
if (this.intervalTimer) {
clearInterval(this.intervalTimer);
}
this.getLeftTime();
}
};
require('./me');
function getOrderList(type, page) {
... ... @@ -30,6 +83,7 @@ function getOrderList(type, page) {
}).done(function(res) {
tableOperation.appendBody(res);
bindPaginationClick(); // eslint-disable-line
countDown.start();
}).fail(function(err) {
console.log(err);
});
... ... @@ -49,6 +103,10 @@ function getQueryString() {
return query;
}
function bindPaginationClick() {
$('.blk-pagination li').off('click').on('click', function(e) {
var $this = $(this);
... ... @@ -60,6 +118,7 @@ function bindPaginationClick() {
if (!$this.hasClass('active')) {
$('.blk-pagination li.active').removeClass('active');
$this.addClass('active');
$(window).scrollTop(0);
getOrderList(type, page);
}
... ... @@ -69,11 +128,14 @@ function bindPaginationClick() {
$('.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;
... ... @@ -81,6 +143,12 @@ $('.tabs li').on('click', function() {
$('.tabs li.active').removeClass('active');
$this.addClass('active');
if (type !== 1) {
$searchBar.addClass('vhide');
} else {
$searchBar.removeClass('vhide');
}
getOrderList(type, page);
}
... ... @@ -88,3 +156,4 @@ $('.tabs li').on('click', function() {
bindPaginationClick();
countDown.start();
... ...
... ... @@ -151,6 +151,7 @@
padding-top: $bigSpace;
.left-time {
min-height: $normalSize;
margin-bottom: 14px !important;
}
... ...