Authored by xuqi

order list rebuild

@@ -11,13 +11,13 @@ var $ = require('jquery'), @@ -11,13 +11,13 @@ 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 loading = false;
23 23
@@ -26,21 +26,21 @@ var navHammer, orderHammer; @@ -26,21 +26,21 @@ var navHammer, orderHammer;
26 //加载订单 26 //加载订单
27 function getOrders() { 27 function getOrders() {
28 var opt = { 28 var opt = {
29 - type: activeIndex + 1,  
30 - page: orderPage[activeIndex] + 1  
31 - },  
32 - num; 29 + type: activeType,
  30 + page: orderPage[activeType] ? (orderPage[activeType] + 1) : 1
  31 + };
33 32
34 if (loading) { 33 if (loading) {
35 return; 34 return;
36 } 35 }
37 36
38 -  
39 $.ajax({ 37 $.ajax({
40 type: 'GET', 38 type: 'GET',
41 url: '/home/getOrders', 39 url: '/home/getOrders',
42 data: opt, 40 data: opt,
43 success: function(data) { 41 success: function(data) {
  42 + var num;
  43 +
44 if (data.code === 200) { 44 if (data.code === 200) {
45 orderPage[opt.type] = opt.page; 45 orderPage[opt.type] = opt.page;
46 46
@@ -61,29 +61,43 @@ function getOrders() { @@ -61,29 +61,43 @@ function getOrders() {
61 61
62 lazyLoad(); 62 lazyLoad();
63 63
  64 +//初始化导航
  65 +(function() {
  66 + var liCount = $navLi.length;
  67 +
  68 + //默认4个导航项
  69 + if (liCount === 4) {
  70 + return;
  71 + }
  72 +
  73 + $navLi.width(100 / liCount + '%');
  74 +}());
  75 +
64 //导航切换 76 //导航切换
65 navHammer = new Hammer(document.getElementById('order-nav')); 77 navHammer = new Hammer(document.getElementById('order-nav'));
66 navHammer.on('tap', function(e) { 78 navHammer.on('tap', function(e) {
67 - var $cur = $(e.target).closest('li'); 79 + var $cur = $(e.target).closest('li'),
  80 + index;
68 81
69 if ($cur.length === 0 || $cur.hasClass('active')) { 82 if ($cur.length === 0 || $cur.hasClass('active')) {
70 return; 83 return;
71 } 84 }
72 85
73 - activeIndex = +$cur.index(); 86 + index = $cur.index();
74 87
75 $navLi.filter('.active').removeClass('active'); 88 $navLi.filter('.active').removeClass('active');
76 $cur.addClass('active'); 89 $cur.addClass('active');
77 90
78 $curContainer.addClass('hide'); 91 $curContainer.addClass('hide');
79 - $curContainer = $orderContainer.children(':eq(' + activeIndex + ')').removeClass('hide'); 92 + $curContainer = $orderContainer.children(':eq(' + index + ')').removeClass('hide');
  93 +
  94 + activeType = $cur.data('type');
80 95
81 - if (orderPage[activeIndex] > 0) { 96 + if (orderPage[activeType]) {
82 return; 97 return;
83 } else { 98 } else {
84 getOrders(); 99 getOrders();
85 } 100 }
86 -  
87 }); 101 });
88 102
89 //点击订单区域跳转订单详情页 103 //点击订单区域跳转订单详情页
@@ -109,6 +123,13 @@ orderHammer.on('tap', function(e) { @@ -109,6 +123,13 @@ orderHammer.on('tap', function(e) {
109 url: '/home/delOrder', 123 url: '/home/delOrder',
110 data: { 124 data: {
111 id: id 125 id: id
  126 + },
  127 + success: function(data) {
  128 + if (data.code === 200) {
  129 +
  130 + //删除订单页面刷新
  131 + location.href = location.href;
  132 + }
112 } 133 }
113 }); 134 });
114 } else if ($cur.closest('.cancel').length > 0) { 135 } else if ($cur.closest('.cancel').length > 0) {
@@ -119,6 +140,13 @@ orderHammer.on('tap', function(e) { @@ -119,6 +140,13 @@ orderHammer.on('tap', function(e) {
119 url: '/home/cancelOrder', 140 url: '/home/cancelOrder',
120 data: { 141 data: {
121 id: id 142 id: id
  143 + },
  144 + success: function(data) {
  145 + if (data.code === 200) {
  146 +
  147 + //取消订单
  148 + alert('order cancel');
  149 + }
122 } 150 }
123 }); 151 });
124 } else { 152 } else {
@@ -135,3 +163,6 @@ $(window).scroll(function() { @@ -135,3 +163,6 @@ $(window).scroll(function() {
135 getOrders(); 163 getOrders();
136 } 164 }
137 }); 165 });
  166 +
  167 +//初始化请求第一页数据
  168 +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,12 @@ class HomeController extends AbstractAction @@ -534,12 +534,12 @@ 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['walkwayUrl'] = 'http://m.yohobuy.com';
543 //渲染模板 543 //渲染模板
544 $this->_view->display('order', array( 544 $this->_view->display('order', array(
545 'order' => $order, 545 'order' => $order,