Authored by biao

Merge branch 'feature/my-order' into develop

@@ -9,12 +9,14 @@ @@ -9,12 +9,14 @@
9 const mcHandler = require('../models/menu-crumb-handler'); 9 const mcHandler = require('../models/menu-crumb-handler');
10 const orderModel = require('../models/order'); 10 const orderModel = require('../models/order');
11 11
12 -// fakeuid = '10931021',  
13 /** 12 /**
14 - * 订单 13 + * 我的订单
15 */ 14 */
16 const index = (req, res) => { 15 const index = (req, res) => {
17 - orderModel.getOrderData().then(result => { 16 + const type = req.query.type;
  17 + const page = req.query.page;
  18 +
  19 + orderModel.getOrderData(type, page).then(result => {
18 res.render('index', { 20 res.render('index', {
19 page: 'order', 21 page: 'order',
20 isMe: true, 22 isMe: true,
@@ -27,6 +29,21 @@ const index = (req, res) => { @@ -27,6 +29,21 @@ const index = (req, res) => {
27 }); 29 });
28 }; 30 };
29 31
  32 +const getOrderList = (req, res) => {
  33 + const type = req.query.type;
  34 + const page = req.query.page;
  35 +
  36 + orderModel.getOrderData(type, page).then(result => {
  37 + res.render('order-table', {
  38 + layout: false,
  39 + page: 'order',
  40 + isMe: true,
  41 + orderList: result.order.orderList
  42 + });
  43 + });
  44 +};
  45 +
30 module.exports = { 46 module.exports = {
31 - index 47 + index: index,
  48 + getOrderList: getOrderList
32 }; 49 };
1 const api = global.yoho.API; 1 const api = global.yoho.API;
2 const camelCase = global.yoho.camelCase; 2 const camelCase = global.yoho.camelCase;
3 3
4 -const _getUserOrder = () => { 4 +const _getUserOrder = (type, page) => {
5 return api.get('', { 5 return api.get('', {
6 method: 'app.SpaceOrders.get', 6 method: 'app.SpaceOrders.get',
7 uid: '10931021', 7 uid: '10931021',
8 - type: 1,  
9 - page: 1, 8 + type: type || 1,
  9 + page: page || 1,
10 limit: 10 10 limit: 10
11 }).then(result => { 11 }).then(result => {
12 const orderList = result && result.data && result.data.order_list || []; 12 const orderList = result && result.data && result.data.order_list || [];
@@ -15,31 +15,36 @@ const _getUserOrder = () => { @@ -15,31 +15,36 @@ const _getUserOrder = () => {
15 }); 15 });
16 }; 16 };
17 17
18 -const getOrderData = () => {  
19 - return _getUserOrder().then(result => { 18 +const navBar = {
  19 + tabs: [
  20 + {
  21 + text: '全部订单',
  22 + isActive: true,
  23 + type: 'all'
  24 + },
  25 + {
  26 + text: '待付款',
  27 + type: 'paying'
  28 + },
  29 + {
  30 + text: '待发货',
  31 + type: 'delivering'
  32 + }
  33 + ]
  34 +};
  35 +
  36 +const getOrderData = (type, page) => {
  37 + return _getUserOrder(type, page).then(result => {
20 const fakeData = { 38 const fakeData = {
21 title: '我的订单', 39 title: '我的订单',
22 - tabs: [  
23 - {  
24 - text: '全部订单',  
25 - isActive: true,  
26 - type: 'all'  
27 - },  
28 - {  
29 - text: '待付款',  
30 - type: 'paying'  
31 - },  
32 - {  
33 - text: '待发货',  
34 - type: 'delivering'  
35 - }  
36 - ],  
37 showSearch: true 40 showSearch: true
38 }; 41 };
39 42
40 const order = Object.assign(fakeData, { 43 const order = Object.assign(fakeData, {
41 - orderList: result  
42 - }); 44 + orderList: result && result.length && result || false
  45 + }, navBar);
  46 +
  47 + console.log(order.orderList);
43 48
44 return { 49 return {
45 order: order 50 order: order
@@ -14,5 +14,6 @@ const order = require(`${cRoot}/order`); @@ -14,5 +14,6 @@ const order = require(`${cRoot}/order`);
14 14
15 // 个人中心首页/订单 15 // 个人中心首页/订单
16 router.get(['/', '/order'], order.index); 16 router.get(['/', '/order'], order.index);
  17 +router.get('/getOrderList', order.getOrderList);
17 18
18 module.exports = router; 19 module.exports = router;
  1 +{{> order/table-body}}
@@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
3 {{> common/subtitle}} 3 {{> common/subtitle}}
4 {{> order/nav}} 4 {{> order/nav}}
5 {{> order/table-header}} 5 {{> order/table-header}}
6 - {{#if orderList}}  
7 - {{> order/table-body}}  
8 - {{/if}} 6 + {{> order/table-body}}
9 {{/order}} 7 {{/order}}
10 </div> 8 </div>
  1 +<div class="table table-body">
  2 +{{#if orderList}}
1 {{#orderList}} 3 {{#orderList}}
2 -<div class="table">  
3 - <ul class="header">  
4 - <li class="content">下单时间:{{createTime}}</li>  
5 - <li class="content">订单编号:{{orderCode}}</li>  
6 - {{#if showMobile}}  
7 - <li class="content">手机订单</li>  
8 - {{/if}}  
9 - </ul>  
10 - <div class="table-body">  
11 - <div class="goods-container special-border">  
12 - {{#orderGoods}}  
13 - <div class="good-info {{#if @last}}last{{/if}}">  
14 - <img src="{{image goodsImage 65 90}}">  
15 - <div class="detail">  
16 - <p class="with-bottom-space">{{productName}}</p>  
17 - <span class="with-space">颜色:{{colorName}}</span>  
18 - <span>尺码:  
19 - <span class="bold">{{sizeName}}</span>  
20 - </span>  
21 - <p class="bold">{{> icon/error-round}}{{buyNumber}}</p> 4 + <div class="order">
  5 + <ul class="header">
  6 + <li class="content">下单时间:{{createTime}}</li>
  7 + <li class="content">订单编号:{{orderCode}}</li>
  8 + {{#if showMobile}}
  9 + <li class="content">手机订单</li>
  10 + {{/if}}
  11 + </ul>
  12 + <div class="table-body">
  13 + <div class="goods-container special-border">
  14 + {{#orderGoods}}
  15 + <div class="good-info {{#if @last}}last{{/if}}">
  16 + <img src="{{image goodsImage 65 90}}">
  17 + <div class="detail">
  18 + <p class="with-bottom-space">{{productName}}</p>
  19 + <span class="with-space">颜色:{{colorName}}</span>
  20 + <span>尺码:
  21 + <span class="bold">{{sizeName}}</span>
  22 + </span>
  23 + <p class="bold">{{> icon/error-round}}{{buyNumber}}</p>
22 24
  25 + </div>
  26 + </div>
  27 + <div class="price bold">
  28 + <p class="{{#if @last}}last{{/if}}">{{goodsAmount}}</p>
23 </div> 29 </div>
  30 + {{/orderGoods}}
24 </div> 31 </div>
25 - <div class="price bold">  
26 - <p>{{goodsAmount}}</p> 32 + <div class="common-column special-border">
  33 + <p class="bold">{{amount}}</p>
  34 + <p class="subtext">{{paymentTypeStr}}</p>
  35 + </div>
  36 + <div class="common-column special-border">
  37 + <p class="bold">{{statusStr}}</p>
  38 + <p class="subtext">查看详情</p>
  39 + </div>
  40 + <div class="common-column special-border">
  41 + {{#if payLeftTime}}
  42 + <p class="left-time">剩余{{payLeftTime}}</p>
  43 + {{/if}}
  44 + {{#if showPayButton}}
  45 + <button>立即付款</button>
  46 + {{/if}}
  47 + {{#if showEditOption}}
  48 + <p class="subtext">修改订单</p>
  49 + <p class="subtext no-space">删除订单</p>
  50 + {{^}}
  51 + <p class="subtext">查看详情</p>
  52 + {{/if}}
27 </div> 53 </div>
28 - {{/orderGoods}}  
29 - </div>  
30 - <div class="common-column special-border">  
31 - <p class="bold">{{amount}}</p>  
32 - <p class="subtext">{{paymentTypeStr}}</p>  
33 - </div>  
34 - <div class="common-column special-border">  
35 - <p>{{statusStr}}</p>  
36 - <p class="subtext">查看详情</p>  
37 - </div>  
38 - <div class="common-column special-border">  
39 - {{#if payLeftTime}}  
40 - <p class="left-time">剩余{{payLeftTime}}</p>  
41 - {{/if}}  
42 - {{#if showPayButton}}  
43 - <button>立即付款</button>  
44 - {{/if}}  
45 - {{#if showEditOption}}  
46 - <p class="subtext">修改订单</p>  
47 - <p class="subtext no-space">删除订单</p>  
48 - {{^}}  
49 - <p class="subtext">查看详情</p>  
50 - {{/if}}  
51 </div> 54 </div>
52 </div> 55 </div>
53 -</div>  
54 {{/orderList}} 56 {{/orderList}}
  57 +{{^}}
  58 +数据为空
  59 +{{/if}}
  60 +</div>
1 -<div class="table"> 1 +<div class="table column-category">
2 <ul class="table-header header"> 2 <ul class="table-header header">
3 <li class="big-width">商品信息</li> 3 <li class="big-width">商品信息</li>
4 <li class="normal-width">单价</li> 4 <li class="normal-width">单价</li>
@@ -4,13 +4,65 @@ @@ -4,13 +4,65 @@
4 * @date: 2016/07/04 4 * @date: 2016/07/04
5 */ 5 */
6 6
  7 +var tableOperation = {
  8 + $header: $('.table.column-category'),
  9 + $body: $('.table.table-body'),
  10 + removeBody: function() {
  11 + this.$body = $('.table.table-body');
  12 + this.$body.remove();
  13 + },
  14 + appendBody: function(htmlStr) {
  15 + $(htmlStr).appendTo(this.$header);
  16 + }
  17 +};
  18 +
7 require('./me'); 19 require('./me');
8 20
  21 +function getOrderList(type, page) {
  22 + tableOperation.removeBody();
  23 +
  24 + $.ajax({
  25 + url: 'getOrderList',
  26 + data: {
  27 + type: type,
  28 + page: page
  29 + }
  30 + }).done(function(res) {
  31 + tableOperation.appendBody(res);
  32 + }).fail(function(err) {
  33 + console.log(err);
  34 + });
  35 +}
  36 +
  37 +
  38 +function getQueryString() {
  39 + var queryArr = location.search.substr(1).split('&');
  40 + var query = {};
  41 +
  42 + queryArr.forEach(function(pair) {
  43 + var arr = pair.split('=');
  44 +
  45 + query[arr[0]] = arr[1];
  46 +
  47 + });
  48 +
  49 + return query;
  50 +}
  51 +
9 $('.tabs li').on('click', function() { 52 $('.tabs li').on('click', function() {
10 var $this = $(this); 53 var $this = $(this);
  54 + var typeMap = {
  55 + all: 1,
  56 + paying: 2,
  57 + delivering: 3
  58 + };
  59 + var type = typeMap[$this.data('type')];
  60 + var page = getQueryString().page;
11 61
12 if (!$this.hasClass('active')) { 62 if (!$this.hasClass('active')) {
13 $('.tabs li.active').removeClass('active'); 63 $('.tabs li.active').removeClass('active');
14 $this.addClass('active'); 64 $this.addClass('active');
15 } 65 }
  66 +
  67 + getOrderList(type, page);
16 }); 68 });
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 $bigWidth: 355px; 7 $bigWidth: 355px;
8 $normalWidth: 138px; 8 $normalWidth: 138px;
9 $goodImgWidth: 65px; 9 $goodImgWidth: 65px;
  10 + $goodImgHeight: 90px;
10 11
11 $normalSize: 14px; 12 $normalSize: 14px;
12 13
@@ -65,7 +66,7 @@ @@ -65,7 +66,7 @@
65 66
66 img { 67 img {
67 width: $goodImgWidth; 68 width: $goodImgWidth;
68 - height: 90px; 69 + height: $goodImgHeight;
69 display: inline-block; 70 display: inline-block;
70 box-sizing: border-box; 71 box-sizing: border-box;
71 margin: $bigSpace $space; 72 margin: $bigSpace $space;
@@ -119,9 +120,20 @@ @@ -119,9 +120,20 @@
119 .price { 120 .price {
120 width: calc($normalWidth - 4px); 121 width: calc($normalWidth - 4px);
121 display: inline-block; 122 display: inline-block;
122 - margin-top: $bigSpace;  
123 text-align: center; 123 text-align: center;
124 vertical-align: top; 124 vertical-align: top;
  125 +
  126 + p {
  127 + width: $normalWidth;
  128 + height: calc(2 * $bigSpace + $goodImgHeight + 4px);
  129 + float: right;
  130 + padding-top: $bigSpace;
  131 + border-bottom: 1px solid $borderColor;
  132 +
  133 + &.last {
  134 + border-bottom: none;
  135 + }
  136 + }
125 } 137 }
126 } 138 }
127 139