Authored by Rock Zhang

Merge branch 'feature/cart' of git.dev.yoho.cn:web/yohobuy into feature/cart

Conflicts:
	static/js/cart/chose-panel.js
@@ -12,7 +12,25 @@ var $ = require('jquery'); @@ -12,7 +12,25 @@ var $ = require('jquery');
12 // var $page = $('.yoho-page'); 12 // var $page = $('.yoho-page');
13 13
14 var $num, 14 var $num,
15 - $chosed; 15 + $chosed,
  16 + re = /\d+/,
  17 + leftNum,
  18 + $colorList = $('.color-list ul>li'),
  19 + $sizeList = $('.size-list ul>li'),
  20 + firstColorId = $colorList.eq(0).data('id'),
  21 + colorIndex;
  22 +
  23 +//初始化购物车面板显示
  24 +$sizeList.each(function() {
  25 + colorIndex = $(this).data('colorid');
  26 +
  27 +
  28 + if (colorIndex === firstColorId) {
  29 + $(this).removeClass('hide');
  30 + }
  31 +});
  32 +
  33 +// confirm;
16 34
17 // var tpl; 35 // var tpl;
18 36
@@ -35,8 +53,11 @@ var $num, @@ -35,8 +53,11 @@ var $num,
35 // $num = $('#good-num'); 53 // $num = $('#good-num');
36 // } 54 // }
37 55
  56 +
  57 +
38 function show() { 58 function show() {
39 $('.chose-panel').show(); 59 $('.chose-panel').show();
  60 +
40 $('body').css('overflow', 'hidden'); 61 $('body').css('overflow', 'hidden');
41 $num = $('#good-num'); 62 $num = $('#good-num');
42 } 63 }
@@ -58,10 +79,43 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -58,10 +79,43 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
58 remove(); 79 remove();
59 }).on('touchstart', '#chose-btn-sure', function() { 80 }).on('touchstart', '#chose-btn-sure', function() {
60 81
61 - //确定  
62 -}).on('touchstart', '.block', function(e) { 82 + // var productSku,
  83 + // buyNumber = $('#good-num') - 0;
  84 + // promotionId,
  85 + // goodsType,
  86 + // isEdit;
  87 +
  88 + // //确定
  89 + // $chosed = $('.block-list>ul>li.chosed');
  90 +
  91 + // if (2 === $chosed.length && 2 !== $chosed.closest('.zero-stock').length) {
  92 +
  93 + // if (confirm) {
  94 + // return false;
  95 + // }
  96 +
  97 + // confirm = true;
  98 + // loading.showLoadingMask();
  99 + // $.ajax({
  100 + // method: 'POST',
  101 + // url: '/cart/index/add',
  102 + // data: {
  103 + // product_id: productId,
  104 + // content: content
  105 + // }
  106 + // }).done(function(res) {
  107 + // if (res.code === 200) {
  108 + // loading.hideLoadingMask();
  109 + // confirm = false;
  110 + // remove();
  111 + // }
  112 + // }).fail(function() {
  113 + // tip.show('网络出了点问题~');
  114 + // confirm = false;
  115 + // });
  116 + // }
63 117
64 - //尺寸颜色点选 118 +}).on('touchstart', '.block', function(e) {
65 var $this = $(this), 119 var $this = $(this),
66 $that = $(e.target).closest('.chose-items'), 120 $that = $(e.target).closest('.chose-items'),
67 numArray, 121 numArray,
@@ -96,6 +150,19 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -96,6 +150,19 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
96 } 150 }
97 }); 151 });
98 } else if ($chosed.length === 1 && $this.hasClass('chosed')) { 152 } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
  153 + if ($this.closest('.block-list').hasClass('color-list')) {
  154 +
  155 + $sizeList.addClass('hide');
  156 +
  157 + //切换尺码信息
  158 + $sizeList.each(function() {
  159 + colorIndex = $(this).data('colorid');
  160 + if (colorIndex === $this.data('id')) {
  161 + $(this).removeClass('hide');
  162 + }
  163 + });
  164 + }
  165 +
99 numArray = ($chosed.data('numstr') + '').split('/'); 166 numArray = ($chosed.data('numstr') + '').split('/');
100 $siblingBlock.find('.block').removeClass('zero-stock'); 167 $siblingBlock.find('.block').removeClass('zero-stock');
101 for (i = 0; i < numArray.length; i++) { 168 for (i = 0; i < numArray.length; i++) {
@@ -104,6 +171,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -104,6 +171,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
104 } 171 }
105 } 172 }
106 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) { 173 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
  174 + $('#chose-btn-sure').css('background-color', '#eb0313');
  175 + $('#chose-btn-sure').html('确定');
  176 +
107 $siblingBlock.find('ul>li').each(function() { 177 $siblingBlock.find('ul>li').each(function() {
108 $(this).removeClass('zero-stock'); 178 $(this).removeClass('zero-stock');
109 if (0 === $(this).data('num') - 0) { 179 if (0 === $(this).data('num') - 0) {
@@ -123,19 +193,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -123,19 +193,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
123 if (2 === $chosed.closest('.zero-stock').length) { 193 if (2 === $chosed.closest('.zero-stock').length) {
124 $('#chose-btn-sure').css('background-color', '#c0c0c0'); 194 $('#chose-btn-sure').css('background-color', '#c0c0c0');
125 $('#chose-btn-sure').html('已售罄'); 195 $('#chose-btn-sure').html('已售罄');
  196 + } else {
  197 + $('#chose-btn-sure').css('background-color', '#eb0313');
  198 + $('#chose-btn-sure').html('确定');
126 } 199 }
127 } 200 }
128 201
129 }).on('touchstart', '.btn-minus', function() { 202 }).on('touchstart', '.btn-minus', function() {
130 var num = +$num.val(), 203 var num = +$num.val(),
131 - $chosed = $('.block-list>ul>li.chosed'); 204 + $chosed = $('.block-list>ul>li.chosed'),
  205 + leftNum = re.exec($('.num .left-num').html());
132 206
133 //若颜色和尺码没有被同时选中,则不能点击 207 //若颜色和尺码没有被同时选中,则不能点击
134 if ($chosed.length < 2) { 208 if ($chosed.length < 2) {
135 return; 209 return;
136 } 210 }
137 211
138 - if (num === 0) { 212 + if (num === 1 || 0 === leftNum - 0) {
139 return; 213 return;
140 } 214 }
141 215
@@ -147,6 +221,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -147,6 +221,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
147 if ($('.block-list>ul>li.chosed').length < 2) { 221 if ($('.block-list>ul>li.chosed').length < 2) {
148 return; 222 return;
149 } 223 }
  224 + leftNum = re.exec($('.num .left-num').html());
  225 + if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
  226 + return;
  227 + }
150 228
151 //TODO:库存数验证 229 //TODO:库存数验证
152 $num.val(num + 1); 230 $num.val(num + 1);
@@ -36,6 +36,9 @@ function getProductInfo(skn, promotionId) { @@ -36,6 +36,9 @@ function getProductInfo(skn, promotionId) {
36 return; 36 return;
37 } 37 }
38 console.log(res); 38 console.log(res);
  39 + if (!panelTmpl) {
  40 + return;
  41 + }
39 if (res.code === 200) { 42 if (res.code === 200) {
40 $chosePanel.html(panelTmpl(res.data)); 43 $chosePanel.html(panelTmpl(res.data));
41 chosePanel.show(); 44 chosePanel.show();
@@ -13,7 +13,10 @@ var dialog = require('../me/dialog'), @@ -13,7 +13,10 @@ var dialog = require('../me/dialog'),
13 tip = require('../plugin/tip'); 13 tip = require('../plugin/tip');
14 14
15 15
16 -var $names; 16 +var $names,
  17 + $selectAllBtn = $('.balance .iconfont');
  18 +
  19 +var requesting = false;
17 20
18 //var $curDelPanel; 21 //var $curDelPanel;
19 22
@@ -167,6 +170,122 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { @@ -167,6 +170,122 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
167 // }); 170 // });
168 //}) 171 //})
169 172
  173 +function requestUpdateAllGoodsCheckStatus(theGoods, successHandeler) {
  174 + if (requesting) {
  175 + return;
  176 + }
  177 + requesting = true;
  178 + $.ajax({
  179 + url: 'select',
  180 + type: 'post',
  181 + data: {
  182 + skuList: JSON.stringify(theGoods)
  183 + },
  184 + success: function(res) {
  185 + if (res.code === 200) {
  186 + successHandeler();
  187 + } else {
  188 + tip.show(res.message);
  189 + }
  190 + },
  191 + error: function(err) {
  192 + tip.show('网络异常');
  193 + },
  194 + complete: function() {
  195 + requesting = false;
  196 + }
  197 + });
  198 +}
  199 +
  200 +function didUpdateAllGoodsCheckStatus() {
  201 + var $checkedBoxs = $('.shopping-cart-good .icon-cb-checked'),
  202 + $uncheckedBoxs = $('.shopping-cart-good .icon-checkbox');
  203 +
  204 + var shouldSelectAll;
  205 +
  206 + if ($selectAllBtn.hasClass('icon-cb-checked')) {
  207 + $selectAllBtn.removeClass('icon-cb-checked').addClass('icon-checkbox');
  208 + shouldSelectAll = true;
  209 + } else {
  210 + $selectAllBtn.removeClass('icon-checkbox').addClass('icon-cb-checked');
  211 + shouldSelectAll = false;
  212 + }
  213 +
  214 + if (!shouldSelectAll) {
  215 + $uncheckedBoxs.each(function(idx, uncheckedBox) {
  216 + $(uncheckedBox).removeClass('icon-checkbox').addClass('icon-cb-checked');
  217 + });
  218 + } else {
  219 + $checkedBoxs.each(function(idx, checkedBox) {
  220 + $(checkedBox).removeClass('icon-cb-checked').addClass('icon-checkbox');
  221 + });
  222 + }
  223 +}
  224 +
  225 +function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
  226 + var goodInfo = {};
  227 + var $goods = $('.cart-content:not(.hide) .shopping-cart-good');
  228 + var $good = null;
  229 + var goodsList = [];
  230 +
  231 + function GoodInfo(properties) {
  232 + this.goods_type = properties.goods_type;
  233 + this.buy_number = properties.buy_number;
  234 + this.product_sku = properties.product_sku;
  235 + this.selected = properties.selected;
  236 + }
  237 +
  238 + goodInfo.goods_type = type;
  239 + goodInfo.selected = isSelected ? 'Y' : 'N';
  240 +
  241 + $goods.each(function(idx, good) {
  242 + $good = $(good);
  243 +
  244 + goodInfo.product_sku = $(good).data('id');
  245 + goodInfo.buy_number = $good.find('.count').eq(0).text().trim().replace('×', '');
  246 +
  247 + goodsList.push(new GoodInfo(goodInfo));
  248 + });
  249 + console.log(goodsList);
  250 +
  251 + requestUpdateAllGoodsCheckStatus(goodsList, handlerAfterTouch);
  252 +}
  253 +
  254 +//获取当前购物车类型
  255 +function getCartType() {
  256 + var $navItem = $('.cart-nav ').find('li'),
  257 + type = 'ordinary';
  258 +
  259 + if ($navItem.eq(0).hasClass('active')) {
  260 + type = 'ordinary';
  261 + } else {
  262 + type = 'advance';
  263 + }
  264 +
  265 + return type;
  266 +}
  267 +
  268 +//是否要全选
  269 +function willBeSelected() {
  270 + var isSelected = true;
  271 + var $this = $(this);
  272 +
  273 + if ($this.hasClass('icon-cb-checked')) {
  274 + isSelected = true;
  275 + } else {
  276 + isSelected = false;
  277 + }
  278 +
  279 + return isSelected;
  280 +}
  281 +
  282 +//全选按钮点击事件
  283 +$selectAllBtn.on('touchend', function() {
  284 + bottomCheckBoxHandeler(willBeSelected(), getCartType(), didUpdateAllGoodsCheckStatus);
  285 +});
  286 +
  287 +
  288 +
170 $('.down').on('touchend', function() { 289 $('.down').on('touchend', function() {
171 chosePanel.show(); 290 chosePanel.show();
172 }); 291 });
@@ -80,7 +80,7 @@ optHammer.on('tap', function(e) { @@ -80,7 +80,7 @@ optHammer.on('tap', function(e) {
80 } else { 80 } else {
81 tip.show(res.message || '网络错误'); 81 tip.show(res.message || '网络错误');
82 } 82 }
83 - window.location.reload(); 83 + window.location.href = '/home/orders';
84 }).fail(function() { 84 }).fail(function() {
85 tip.show('网络错误'); 85 tip.show('网络错误');
86 }); 86 });
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 background: rgba(0,0,0,.3); 9 background: rgba(0,0,0,.3);
10 z-index:3; 10 z-index:3;
11 11
  12 +
12 .main { 13 .main {
13 position: absolute; 14 position: absolute;
14 height: pxToRem(610px); 15 height: pxToRem(610px);
@@ -86,6 +87,10 @@ @@ -86,6 +87,10 @@
86 } 87 }
87 } 88 }
88 89
  90 + .size-list li.hide {
  91 + display: none;
  92 + }
  93 +
89 .block { 94 .block {
90 float: left; 95 float: left;
91 display: block; 96 display: block;
@@ -40,10 +40,10 @@ @@ -40,10 +40,10 @@
40 height: 25rem / $pxConvertRem; 40 height: 25rem / $pxConvertRem;
41 color: #fff; 41 color: #fff;
42 text-align: center; 42 text-align: center;
43 - background: #a1ce4e; 43 + background: #eb76aa;
44 44
45 &:before { 45 &:before {
46 - content: '赠品'; 46 + content: '加价购';
47 display: block; 47 display: block;
48 font-size: 12px; 48 font-size: 12px;
49 line-height: 25rem / $pxConvertRem; 49 line-height: 25rem / $pxConvertRem;
@@ -56,6 +56,7 @@ @@ -56,6 +56,7 @@
56 } 56 }
57 57
58 .name { 58 .name {
  59 + margin-bottom: 20rem / $pxConvertRem;
59 width: 440rem / $pxConvertRem; 60 width: 440rem / $pxConvertRem;
60 font-size: 28rem / $pxConvertRem; 61 font-size: 28rem / $pxConvertRem;
61 } 62 }
@@ -114,10 +115,10 @@ @@ -114,10 +115,10 @@
114 background: #f8f8f8; 115 background: #f8f8f8;
115 } 116 }
116 117
117 - .advance-block .tag {  
118 - background: #eb76aa; 118 + .gift-block .tag {
  119 + background: #a1ce4e;
119 &:before { 120 &:before {
120 - content: '加价购'; 121 + content: '赠品';
121 } 122 }
122 } 123 }
123 } 124 }
@@ -11,7 +11,12 @@ @@ -11,7 +11,12 @@
11 {{/ advanceBuy}} 11 {{/ advanceBuy}}
12 {{else}} 12 {{else}}
13 {{# freebie}} 13 {{# freebie}}
  14 + <div class="advance-block gift-block" data-promotion-id="{{promotionId}}">
  15 + <p class="title">{{title}}</p>
  16 + {{#goods}}
14 {{> cart/gift-advance-good}} 17 {{> cart/gift-advance-good}}
  18 + {{/goods}}
  19 + </div>
15 {{/ freebie}} 20 {{/ freebie}}
16 {{/if}} 21 {{/if}}
17 22
1 - 1 +{{#cartInfo}}
2 <div class="chose-panel"> 2 <div class="chose-panel">
3 <div class="main"> 3 <div class="main">
4 <div class="infos"> 4 <div class="infos">
5 - <div class="basic-info"> 5 + <div class="basic-info" >
6 {{#thumbs}} 6 {{#thumbs}}
7 {{#if @first}} 7 {{#if @first}}
8 <img class="thumb" src={{img}}> 8 <img class="thumb" src={{img}}>
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <span>颜色</span> 25 <span>颜色</span>
26 <ul class="clearfix" data-type="color"> 26 <ul class="clearfix" data-type="color">
27 {{# colors}} 27 {{# colors}}
28 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}"> 28 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-id="{{id}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}">
29 {{name}} 29 {{name}}
30 </li> 30 </li>
31 {{/ colors}} 31 {{/ colors}}
@@ -33,9 +33,10 @@ @@ -33,9 +33,10 @@
33 </div> 33 </div>
34 <div class="size-list block-list"> 34 <div class="size-list block-list">
35 <span>尺码</span> 35 <span>尺码</span>
  36 +
36 <ul class="clearfix" data-type="size" > 37 <ul class="clearfix" data-type="size" >
37 {{# sizes}} 38 {{# sizes}}
38 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodId}}"> 39 + <li class="block hide {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">
39 {{name}} 40 {{name}}
40 </li> 41 </li>
41 {{/ sizes}} 42 {{/ sizes}}
@@ -47,7 +48,7 @@ @@ -47,7 +48,7 @@
47 <a class="btn btn-minus" href="javascript:void(0);"> 48 <a class="btn btn-minus" href="javascript:void(0);">
48 <span class="iconfont">&#xe625;</span> 49 <span class="iconfont">&#xe625;</span>
49 </a> 50 </a>
50 - <input id="good-num" class="good-num" type="text" value={{num}}> 51 + <input id="good-num" class="good-num" type="text" value="1">
51 <a class="btn btn-plus" href="javascript:void(0);"> 52 <a class="btn btn-plus" href="javascript:void(0);">
52 <span class="iconfont">&#xe624;</span> 53 <span class="iconfont">&#xe624;</span>
53 </a> 54 </a>
@@ -57,7 +58,8 @@ @@ -57,7 +58,8 @@
57 </div> 58 </div>
58 </div> 59 </div>
59 <div class="btn-wrap"> 60 <div class="btn-wrap">
60 - <button id="chose-btn-sure" class="btn btn-sure">加入购物车</button> 61 + <button id="chose-btn-sure" class="btn btn-sure">确定</button>
61 </div> 62 </div>
62 </div> 63 </div>
63 </div> 64 </div>
  65 +{{/cartInfo}}
@@ -7,11 +7,13 @@ @@ -7,11 +7,13 @@
7 <p class="name row">{{name}}</p> 7 <p class="name row">{{name}}</p>
8 <p class="row"> 8 <p class="row">
9 <span class="price"> 9 <span class="price">
10 - ¥{{price}} 10 + ¥{{#if price}}{{price}}{{else}}{{marketPrice}}{{/if}}
11 </span> 11 </span>
  12 + {{#if price}}
12 <span class="price market-price"> 13 <span class="price market-price">
13 ¥{{marketPrice}} 14 ¥{{marketPrice}}
14 </span> 15 </span>
  16 + {{/if}}
15 <span class="count"> 17 <span class="count">
16 ×{{count}} 18 ×{{count}}
17 </span> 19 </span>
@@ -75,6 +75,7 @@ @@ -75,6 +75,7 @@
75 ×{{count}} 75 ×{{count}}
76 </span> 76 </span>
77 </div> 77 </div>
  78 + </div>
78 <!--<div class="opt-panel hide"> 79 <!--<div class="opt-panel hide">
79 <div class="put-in-favorite"> 80 <div class="put-in-favorite">
80 <span class="iconfont">&#xe622;</span> 81 <span class="iconfont">&#xe622;</span>
@@ -6,6 +6,9 @@ @@ -6,6 +6,9 @@
6 {{#navHome}} 6 {{#navHome}}
7 <a href="{{.}}" class="iconfont nav-home">&#xe611;</a> 7 <a href="{{.}}" class="iconfont nav-home">&#xe611;</a>
8 {{/navHome}} 8 {{/navHome}}
  9 + {{#navPhone}}
  10 + <a href="{{.}}" class="iconfont nav-home">&#xe63e;</a>
  11 + {{/navPhone}}
9 {{#navTitle}} 12 {{#navTitle}}
10 <p class="nav-title">{{.}}</p> 13 <p class="nav-title">{{.}}</p>
11 {{/navTitle}} 14 {{/navTitle}}
@@ -849,10 +849,11 @@ class HomeController extends AbstractAction @@ -849,10 +849,11 @@ class HomeController extends AbstractAction
849 } 849 }
850 850
851 $this->setTitle('订单详情'); 851 $this->setTitle('订单详情');
852 - $this->setNavHeader('订单详情'); 852 + $this->setNavHeader('订单详情', true, false);
853 853
854 $this->_view->display('order-detail', array( 854 $this->_view->display('order-detail', array(
855 'orderDetailPage' => true, 855 'orderDetailPage' => true,
  856 + 'navPhone' => 'tel:400-889-9646',
856 'orderDetail' => $orderDetail, 857 'orderDetail' => $orderDetail,
857 )); 858 ));
858 } 859 }
@@ -78,7 +78,7 @@ class IndexController extends AbstractAction @@ -78,7 +78,7 @@ class IndexController extends AbstractAction
78 $result = array(); 78 $result = array();
79 79
80 if ($this->isAjax()) { 80 if ($this->isAjax()) {
81 - $productId = $this->post('id', 0); 81 + $productId = $this->post('skuList', 0);
82 $uid = $this->getUid(true); 82 $uid = $this->getUid(true);
83 $shoppingKey = $this->getSession('shoppingKey'); 83 $shoppingKey = $this->getSession('shoppingKey');
84 $result = CartModel::selectGoods($uid, $productId, $shoppingKey); 84 $result = CartModel::selectGoods($uid, $productId, $shoppingKey);