Authored by uedxwg

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -939,14 +939,27 @@ @@ -939,14 +939,27 @@
939 ### 我的订单 939 ### 我的订单
940 { 940 {
941 order: { 941 order: {
942 - orders: [ 942 + navs: [
  943 + {
  944 + name: '',
  945 + active: true,
  946 + typeId: 1
  947 + },
943 ... 948 ...
944 - ],  
945 - //没有订单的情况不传orders  
946 - walkWayUrl: '' //随便逛逛url 949 + ]
947 } 950 }
948 } 951 }
949 952
  953 + //订单列表
  954 + {
  955 + orders: [
  956 + {
  957 + ...//订单
  958 + }
  959 + ]
  960 + //当无订单时,不传order,返回walkwayUrl
  961 + walkWayUrl: ''
  962 + }
950 963
951 //订单 964 //订单
952 { 965 {
@@ -11,36 +11,41 @@ var $ = require('jquery'), @@ -11,36 +11,41 @@ var $ = require('jquery'),
11 var $navLi = $('#order-nav > li'), 11 var $navLi = $('#order-nav > li'),
12 $orderContainer = $('#order-container'); 12 $orderContainer = $('#order-container');
13 13
14 -var $curContainer = $orderContainer.children('.orders').first();//保存当前显示的order-container 14 +var $curContainer = $orderContainer.children('.orders:not(.hide)');//保存当前显示的order-container
15 15
16 var winH = $(window).height(); 16 var winH = $(window).height();
17 17
18 -var activeIndex = 0; //当前active的项的index 18 +var activeType = $navLi.filter('.active').data('type'); //当前active的项的index
19 19
20 -var orderPage = [1, 0, 0, 0]; 20 +var orderPage = {};
21 21
22 -var loading = false; 22 +var inAjax = false;
  23 +
  24 +var loading = require('../plugin/loading');
23 25
24 var navHammer, orderHammer; 26 var navHammer, orderHammer;
25 27
26 //加载订单 28 //加载订单
27 function getOrders() { 29 function getOrders() {
28 var opt = { 30 var opt = {
29 - type: activeIndex + 1,  
30 - page: orderPage[activeIndex] + 1  
31 - },  
32 - num; 31 + type: activeType,
  32 + page: orderPage[activeType] ? (orderPage[activeType] + 1) : 1
  33 + };
33 34
34 - if (loading) { 35 + if (inAjax) {
35 return; 36 return;
36 } 37 }
37 38
  39 + inAjax = true;
  40 + loading.show();
38 41
39 $.ajax({ 42 $.ajax({
40 type: 'GET', 43 type: 'GET',
41 url: '/home/getOrders', 44 url: '/home/getOrders',
42 data: opt, 45 data: opt,
43 success: function(data) { 46 success: function(data) {
  47 + var num;
  48 +
44 if (data.code === 200) { 49 if (data.code === 200) {
45 orderPage[opt.type] = opt.page; 50 orderPage[opt.type] = opt.page;
46 51
@@ -55,35 +60,54 @@ function getOrders() { @@ -55,35 +60,54 @@ function getOrders() {
55 lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy')); 60 lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ') .lazy'));
56 } 61 }
57 } 62 }
  63 +
  64 + inAjax = false;
  65 + loading.hide();
58 } 66 }
59 }); 67 });
60 } 68 }
61 69
62 lazyLoad(); 70 lazyLoad();
63 71
  72 +//初始化导航
  73 +(function() {
  74 + var liCount = $navLi.length;
  75 +
  76 + //默认4个导航项
  77 + if (liCount === 4) {
  78 + return;
  79 + }
  80 +
  81 + $navLi.width(100 / liCount + '%');
  82 +}());
  83 +
  84 +loading.init();
  85 +
64 //导航切换 86 //导航切换
65 navHammer = new Hammer(document.getElementById('order-nav')); 87 navHammer = new Hammer(document.getElementById('order-nav'));
66 navHammer.on('tap', function(e) { 88 navHammer.on('tap', function(e) {
67 - var $cur = $(e.target).closest('li'); 89 + var $cur = $(e.target).closest('li'),
  90 + index;
68 91
69 if ($cur.length === 0 || $cur.hasClass('active')) { 92 if ($cur.length === 0 || $cur.hasClass('active')) {
70 return; 93 return;
71 } 94 }
72 95
73 - activeIndex = +$cur.index(); 96 + index = $cur.index();
74 97
75 $navLi.filter('.active').removeClass('active'); 98 $navLi.filter('.active').removeClass('active');
76 $cur.addClass('active'); 99 $cur.addClass('active');
77 100
78 $curContainer.addClass('hide'); 101 $curContainer.addClass('hide');
79 - $curContainer = $orderContainer.children(':eq(' + activeIndex + ')').removeClass('hide'); 102 + $curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
  103 +
  104 + activeType = $cur.data('type');
80 105
81 - if (orderPage[activeIndex] > 0) { 106 + if (orderPage[activeType]) {
82 return; 107 return;
83 } else { 108 } else {
84 getOrders(); 109 getOrders();
85 } 110 }
86 -  
87 }); 111 });
88 112
89 //点击订单区域跳转订单详情页 113 //点击订单区域跳转订单详情页
@@ -109,6 +133,13 @@ orderHammer.on('tap', function(e) { @@ -109,6 +133,13 @@ orderHammer.on('tap', function(e) {
109 url: '/home/delOrder', 133 url: '/home/delOrder',
110 data: { 134 data: {
111 id: id 135 id: id
  136 + },
  137 + success: function(data) {
  138 + if (data.code === 200) {
  139 +
  140 + //删除订单页面刷新
  141 + location.href = location.href;
  142 + }
112 } 143 }
113 }); 144 });
114 } else if ($cur.closest('.cancel').length > 0) { 145 } else if ($cur.closest('.cancel').length > 0) {
@@ -119,6 +150,13 @@ orderHammer.on('tap', function(e) { @@ -119,6 +150,13 @@ orderHammer.on('tap', function(e) {
119 url: '/home/cancelOrder', 150 url: '/home/cancelOrder',
120 data: { 151 data: {
121 id: id 152 id: id
  153 + },
  154 + success: function(data) {
  155 + if (data.code === 200) {
  156 +
  157 + //取消订单
  158 + alert('order cancel');
  159 + }
122 } 160 }
123 }); 161 });
124 } else { 162 } else {
@@ -135,3 +173,6 @@ $(window).scroll(function() { @@ -135,3 +173,6 @@ $(window).scroll(function() {
135 getOrders(); 173 getOrders();
136 } 174 }
137 }); 175 });
  176 +
  177 +//初始化请求第一页数据
  178 +getOrders();
@@ -2,27 +2,17 @@ @@ -2,27 +2,17 @@
2 <div class="order-page yoho-page"> 2 <div class="order-page yoho-page">
3 {{# order}} 3 {{# order}}
4 <ul id="order-nav" class="order-nav clearfix"> 4 <ul id="order-nav" class="order-nav clearfix">
5 - <li class="active">  
6 - 全部  
7 - </li>  
8 - <li>  
9 - 待付款  
10 - </li>  
11 - <li>  
12 - 待发货  
13 - </li>  
14 - <li>  
15 - 待收货 5 + {{#each navs}}
  6 + <li {{#if active}}class="active"{{/if}} data-type="{{typeId}}">
  7 + {{name}}
16 </li> 8 </li>
  9 + {{/each}}
17 </ul> 10 </ul>
18 11
19 <div id="order-container" class="order-container"> 12 <div id="order-container" class="order-container">
20 - <div class="all orders">  
21 - {{> me/order/orders}}  
22 - </div>  
23 - <div class="unpaid orders hide"></div>  
24 - <div class="unshipped orders hide"></div>  
25 - <div class="unreceived orders hide"></div> 13 + {{#each navs}}
  14 + <div class="orders{{#unless active}} hide{{/unless}}"></div>
  15 + {{/each}}
26 </div> 16 </div>
27 {{/ order}} 17 {{/ order}}
28 </div> 18 </div>
@@ -534,12 +534,30 @@ class HomeController extends AbstractAction @@ -534,12 +534,30 @@ class HomeController extends AbstractAction
534 $data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid); 534 $data = OrderModel::getOrder($type, $page, $limit, $gender, $yh_channel, $uid);
535 //如果没有订单数据,就给一个随便逛逛链接 535 //如果没有订单数据,就给一个随便逛逛链接
536 $order = array(); 536 $order = array();
537 - if (!empty($data)) {  
538 - $order['orders'] = $data;  
539 - } else {  
540 - $order['walkwayUrl'] = 'http://www.baidu.com';  
541 - }  
542 - 537 + // if (!empty($data)) {
  538 + // $order['orders'] = $data;
  539 + // } else {
  540 + // $order['walkwayUrl'] = 'http://www.baidu.com';
  541 + // }
  542 + $order['navs'] = array(
  543 + array(
  544 + 'name' => '全部',
  545 + 'active' => true,
  546 + 'typeId' => '1'
  547 + ),
  548 + array(
  549 + 'name' => '待付款',
  550 + 'typeId' => '2'
  551 + ),
  552 + array(
  553 + 'name' => '待发货',
  554 + 'typeId' => '3'
  555 + ),
  556 + array(
  557 + 'name' => '待收货',
  558 + 'typeId' => '4'
  559 + )
  560 + );
543 //渲染模板 561 //渲染模板
544 $this->_view->display('order', array( 562 $this->_view->display('order', array(
545 'order' => $order, 563 'order' => $order,