order.js
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
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,
page: page,
limit: pageSize
}).then(result => {
let orderList = [];
let total = false;
let curPage = 1;
if (result && result.data) {
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: orderList,
total: total,
curPage: curPage
};
});
};
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 basicData = {
title: '我的订单',
showSearch: type === 1,
total: result.total,
type: type
};
navBar.tabs[typeActiveIndexMap[type]].isActive = true;
const order = Object.assign(basicData, {
orderList: result.orderList.length && result.orderList || false
}, navBar);
const paginationOpts = result.total > pageSize ? {
paginationOpts: {
total: result.total,
page: result.curPage,
limit: pageSize
}
} : false;
return {
order: Object.assign(order, paginationOpts)
};
});
};
module.exports = {
getOrderData: getOrderData
};