handle merge
Showing
5 changed files
with
142 additions
and
34 deletions
@@ -2,69 +2,105 @@ | @@ -2,69 +2,105 @@ | ||
2 | 2 | ||
3 | const api = global.yoho.API; | 3 | const api = global.yoho.API; |
4 | const camelCase = global.yoho.camelCase; | 4 | const camelCase = global.yoho.camelCase; |
5 | +const moment = require('moment'); | ||
6 | + | ||
7 | +const pageSize = 10; | ||
8 | + | ||
9 | +const typeActiveIndexMap = { | ||
10 | + 1: 0, | ||
11 | + 2: 1, | ||
12 | + 3: 2 | ||
13 | +}; | ||
5 | 14 | ||
6 | const _getUserOrder = (type, page) => { | 15 | const _getUserOrder = (type, page) => { |
16 | + const convertUnitTime = (src) => { | ||
17 | + return moment.unix(src).format('YYYY-MM-DD hh:mm:ss'); | ||
18 | + }; | ||
19 | + | ||
7 | return api.get('', { | 20 | return api.get('', { |
8 | method: 'app.SpaceOrders.get', | 21 | method: 'app.SpaceOrders.get', |
9 | uid: '10931021', | 22 | uid: '10931021', |
10 | - type: type || 1, | ||
11 | - page: page || 1, | ||
12 | - limit: 10 | 23 | + type: type, |
24 | + page: page, | ||
25 | + limit: pageSize | ||
13 | }).then(result => { | 26 | }).then(result => { |
14 | let orderList = []; | 27 | let orderList = []; |
15 | let total = false; | 28 | let total = false; |
16 | let curPage = 1; | 29 | let curPage = 1; |
17 | 30 | ||
18 | if (result && result.data) { | 31 | if (result && result.data) { |
19 | - orderList = result.data.order_list; | 32 | + orderList = camelCase(result.data.order_list); |
20 | total = result.data.total; | 33 | total = result.data.total; |
21 | curPage = result.data.page; | 34 | curPage = result.data.page; |
22 | } | 35 | } |
23 | 36 | ||
37 | + orderList.forEach(function(item) { | ||
38 | + const ot = parseInt(item.orderType, 10); | ||
39 | + | ||
40 | + // 转换订单创建时间 | ||
41 | + item.createTime = convertUnitTime(item.createTime); | ||
42 | + | ||
43 | + // 隐藏为了的剩余时间 | ||
44 | + if (parseInt(item.payLefttime, 10) === 0) { | ||
45 | + item.payLefttime = false; | ||
46 | + } | ||
47 | + | ||
48 | + // 判断是否是手机订单,3, 4, 6对应 iOS, Android, H5 | ||
49 | + // 具体订单类型见 http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E8%AE%A2%E5%8D%95/order.md | ||
50 | + item.showMobile = ot === 3 || ot === 4 || ot === 6; | ||
51 | + }); | ||
52 | + | ||
24 | return { | 53 | return { |
25 | - orderList: camelCase(orderList), | 54 | + orderList: orderList, |
26 | total: total, | 55 | total: total, |
27 | curPage: curPage | 56 | curPage: curPage |
28 | }; | 57 | }; |
29 | }); | 58 | }); |
30 | }; | 59 | }; |
31 | 60 | ||
32 | -const navBar = { | ||
33 | - tabs: [ | ||
34 | - { | ||
35 | - text: '全部订单', | ||
36 | - isActive: true, | ||
37 | - type: 'all' | ||
38 | - }, | ||
39 | - { | ||
40 | - text: '待付款', | ||
41 | - type: 'paying' | ||
42 | - }, | ||
43 | - { | ||
44 | - text: '待发货', | ||
45 | - type: 'delivering' | ||
46 | - } | ||
47 | - ] | ||
48 | -}; | ||
49 | - | ||
50 | const getOrderData = (type, page) => { | 61 | const getOrderData = (type, page) => { |
62 | + const navBar = { | ||
63 | + tabs: [ | ||
64 | + { | ||
65 | + text: '全部订单', | ||
66 | + typeStr: 'all' | ||
67 | + }, | ||
68 | + { | ||
69 | + text: '待付款', | ||
70 | + typeStr: 'paying' | ||
71 | + }, | ||
72 | + { | ||
73 | + text: '待发货', | ||
74 | + typeStr: 'delivering' | ||
75 | + } | ||
76 | + ] | ||
77 | + }; | ||
78 | + | ||
79 | + type = parseInt(type, 10); | ||
80 | + | ||
81 | + type = type < 4 ? type : 1; | ||
82 | + page = page || 1; | ||
83 | + | ||
84 | + | ||
51 | return _getUserOrder(type, page).then(result => { | 85 | return _getUserOrder(type, page).then(result => { |
52 | - const fakeData = { | 86 | + const basicData = { |
53 | title: '我的订单', | 87 | title: '我的订单', |
54 | - showSearch: true | 88 | + showSearch: type === 1 |
55 | }; | 89 | }; |
56 | 90 | ||
57 | - const order = Object.assign(fakeData, { | 91 | + navBar.tabs[typeActiveIndexMap[type]].isActive = true; |
92 | + | ||
93 | + const order = Object.assign(basicData, { | ||
58 | orderList: result.orderList.length && result.orderList || false | 94 | orderList: result.orderList.length && result.orderList || false |
59 | }, navBar); | 95 | }, navBar); |
60 | 96 | ||
61 | - const paginationOpts = { | 97 | + const paginationOpts = result.total > pageSize ? { |
62 | paginationOpts: { | 98 | paginationOpts: { |
63 | total: result.total, | 99 | total: result.total, |
64 | page: result.curPage, | 100 | page: result.curPage, |
65 | - limit: 10 | 101 | + limit: pageSize |
66 | } | 102 | } |
67 | - }; | 103 | + } : false; |
68 | 104 | ||
69 | return { | 105 | return { |
70 | order: Object.assign(order, paginationOpts) | 106 | order: Object.assign(order, paginationOpts) |
1 | <div class="order-nav"> | 1 | <div class="order-nav"> |
2 | <ul class="tabs clearfix"> | 2 | <ul class="tabs clearfix"> |
3 | {{#tabs}} | 3 | {{#tabs}} |
4 | - <li class="{{#if isActive}}active{{/if}}" data-type="{{type}}">{{text}}</li> | 4 | + <li class="{{#if isActive}}active{{/if}}" data-type="{{typeStr}}">{{text}}</li> |
5 | {{/tabs}} | 5 | {{/tabs}} |
6 | </ul> | 6 | </ul> |
7 | - <div class="search-bar"> | 7 | + <div class="search-bar {{#unless showSearch}}vhide{{/unless}}"> |
8 | <input class="search-ctrl" type="text" placeholder="商品名称和订单号"> | 8 | <input class="search-ctrl" type="text" placeholder="商品名称和订单号"> |
9 | <button class="search-ctrl">搜索订单</button> | 9 | <button class="search-ctrl">搜索订单</button> |
10 | </div> | 10 | </div> |
@@ -38,8 +38,8 @@ | @@ -38,8 +38,8 @@ | ||
38 | <p class="subtext">查看详情</p> | 38 | <p class="subtext">查看详情</p> |
39 | </div> | 39 | </div> |
40 | <div class="common-column special-border"> | 40 | <div class="common-column special-border"> |
41 | - {{#if payLeftTime}} | ||
42 | - <p class="left-time">剩余{{payLeftTime}}</p> | 41 | + {{#if payLefttime}} |
42 | + <p class="left-time" data-left="{{payLefttime}}"></p> | ||
43 | {{/if}} | 43 | {{/if}} |
44 | {{#if showPayButton}} | 44 | {{#if showPayButton}} |
45 | <button>立即付款</button> | 45 | <button>立即付款</button> |
@@ -54,7 +54,9 @@ | @@ -54,7 +54,9 @@ | ||
54 | </div> | 54 | </div> |
55 | </div> | 55 | </div> |
56 | {{/orderList}} | 56 | {{/orderList}} |
57 | +{{#if paginationOpts}} | ||
57 | {{{ pagination paginationOpts }}} | 58 | {{{ pagination paginationOpts }}} |
59 | +{{/if}} | ||
58 | {{^}} | 60 | {{^}} |
59 | <div class="bg"></div> | 61 | <div class="bg"></div> |
60 | <div class="msg"> | 62 | <div class="msg"> |
@@ -9,13 +9,66 @@ var tableOperation = { | @@ -9,13 +9,66 @@ var tableOperation = { | ||
9 | $body: $('.table.table-body'), | 9 | $body: $('.table.table-body'), |
10 | removeBody: function() { | 10 | removeBody: function() { |
11 | this.$body = $('.table.table-body'); | 11 | this.$body = $('.table.table-body'); |
12 | - this.$body.remove(); | ||
13 | }, | 12 | }, |
14 | appendBody: function(htmlStr) { | 13 | appendBody: function(htmlStr) { |
14 | + this.$body.remove(); | ||
15 | $(htmlStr).appendTo(this.$header); | 15 | $(htmlStr).appendTo(this.$header); |
16 | } | 16 | } |
17 | }; | 17 | }; |
18 | 18 | ||
19 | +var countDown = { | ||
20 | + count: null, | ||
21 | + intervalTimer: null, | ||
22 | + intervalValue: 60000, | ||
23 | + $element: null, | ||
24 | + selector: '.left-time', | ||
25 | + setTime: function() { | ||
26 | + var that = this; | ||
27 | + | ||
28 | + this.$element.each(function(index, item) { | ||
29 | + var $item = $(item); | ||
30 | + var leftTime = $item.data('left'); | ||
31 | + | ||
32 | + $item.text(that.convertLeftTime(leftTime - that.count * 60)); | ||
33 | + }); | ||
34 | + this.count += 1; | ||
35 | + }, | ||
36 | + convertLeftTime: function(src) { | ||
37 | + var min = parseInt(src / 60, 10) % 60; | ||
38 | + var hour = parseInt(src / 3600, 10); | ||
39 | + var timeStr = min + '分钟'; | ||
40 | + | ||
41 | + if (src <= 0) { | ||
42 | + timeStr = '已失效'; | ||
43 | + return timeStr; | ||
44 | + } | ||
45 | + | ||
46 | + if (hour > 0) { | ||
47 | + timeStr = hour + '小时' + timeStr; | ||
48 | + } | ||
49 | + | ||
50 | + timeStr = '剩余' + timeStr; | ||
51 | + | ||
52 | + return timeStr; | ||
53 | + }, | ||
54 | + getLeftTime: function() { | ||
55 | + var that = this; | ||
56 | + | ||
57 | + if (this.$element.length) { | ||
58 | + this.setTime(); | ||
59 | + this.intervalTimer = setInterval(this.setTime.bind(that), that.intervalValue); | ||
60 | + } | ||
61 | + }, | ||
62 | + start: function() { | ||
63 | + this.count = 0; | ||
64 | + this.$element = $(this.selector); | ||
65 | + if (this.intervalTimer) { | ||
66 | + clearInterval(this.intervalTimer); | ||
67 | + } | ||
68 | + this.getLeftTime(); | ||
69 | + } | ||
70 | +}; | ||
71 | + | ||
19 | require('./me'); | 72 | require('./me'); |
20 | 73 | ||
21 | function getOrderList(type, page) { | 74 | function getOrderList(type, page) { |
@@ -30,6 +83,7 @@ function getOrderList(type, page) { | @@ -30,6 +83,7 @@ function getOrderList(type, page) { | ||
30 | }).done(function(res) { | 83 | }).done(function(res) { |
31 | tableOperation.appendBody(res); | 84 | tableOperation.appendBody(res); |
32 | bindPaginationClick(); // eslint-disable-line | 85 | bindPaginationClick(); // eslint-disable-line |
86 | + countDown.start(); | ||
33 | }).fail(function(err) { | 87 | }).fail(function(err) { |
34 | console.log(err); | 88 | console.log(err); |
35 | }); | 89 | }); |
@@ -49,6 +103,10 @@ function getQueryString() { | @@ -49,6 +103,10 @@ function getQueryString() { | ||
49 | return query; | 103 | return query; |
50 | } | 104 | } |
51 | 105 | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + | ||
52 | function bindPaginationClick() { | 110 | function bindPaginationClick() { |
53 | $('.blk-pagination li').off('click').on('click', function(e) { | 111 | $('.blk-pagination li').off('click').on('click', function(e) { |
54 | var $this = $(this); | 112 | var $this = $(this); |
@@ -60,6 +118,7 @@ function bindPaginationClick() { | @@ -60,6 +118,7 @@ function bindPaginationClick() { | ||
60 | if (!$this.hasClass('active')) { | 118 | if (!$this.hasClass('active')) { |
61 | $('.blk-pagination li.active').removeClass('active'); | 119 | $('.blk-pagination li.active').removeClass('active'); |
62 | $this.addClass('active'); | 120 | $this.addClass('active'); |
121 | + $(window).scrollTop(0); | ||
63 | 122 | ||
64 | getOrderList(type, page); | 123 | getOrderList(type, page); |
65 | } | 124 | } |
@@ -69,11 +128,14 @@ function bindPaginationClick() { | @@ -69,11 +128,14 @@ function bindPaginationClick() { | ||
69 | 128 | ||
70 | $('.tabs li').on('click', function() { | 129 | $('.tabs li').on('click', function() { |
71 | var $this = $(this); | 130 | var $this = $(this); |
131 | + var $searchBar = $('.search-bar'); | ||
132 | + | ||
72 | var typeMap = { | 133 | var typeMap = { |
73 | all: 1, | 134 | all: 1, |
74 | paying: 2, | 135 | paying: 2, |
75 | delivering: 3 | 136 | delivering: 3 |
76 | }; | 137 | }; |
138 | + | ||
77 | var type = typeMap[$this.data('type')]; | 139 | var type = typeMap[$this.data('type')]; |
78 | var page = getQueryString().page; | 140 | var page = getQueryString().page; |
79 | 141 | ||
@@ -81,6 +143,12 @@ $('.tabs li').on('click', function() { | @@ -81,6 +143,12 @@ $('.tabs li').on('click', function() { | ||
81 | $('.tabs li.active').removeClass('active'); | 143 | $('.tabs li.active').removeClass('active'); |
82 | $this.addClass('active'); | 144 | $this.addClass('active'); |
83 | 145 | ||
146 | + if (type !== 1) { | ||
147 | + $searchBar.addClass('vhide'); | ||
148 | + } else { | ||
149 | + $searchBar.removeClass('vhide'); | ||
150 | + } | ||
151 | + | ||
84 | getOrderList(type, page); | 152 | getOrderList(type, page); |
85 | } | 153 | } |
86 | 154 | ||
@@ -88,3 +156,4 @@ $('.tabs li').on('click', function() { | @@ -88,3 +156,4 @@ $('.tabs li').on('click', function() { | ||
88 | 156 | ||
89 | 157 | ||
90 | bindPaginationClick(); | 158 | bindPaginationClick(); |
159 | +countDown.start(); |
-
Please register or login to post a comment