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');
// var $page = $('.yoho-page');
var $num,
$chosed;
$chosed,
re = /\d+/,
leftNum,
$colorList = $('.color-list ul>li'),
$sizeList = $('.size-list ul>li'),
firstColorId = $colorList.eq(0).data('id'),
colorIndex;
//初始化购物车面板显示
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === firstColorId) {
$(this).removeClass('hide');
}
});
// confirm;
// var tpl;
... ... @@ -35,8 +53,11 @@ var $num,
// $num = $('#good-num');
// }
function show() {
$('.chose-panel').show();
$('body').css('overflow', 'hidden');
$num = $('#good-num');
}
... ... @@ -58,10 +79,43 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
remove();
}).on('touchstart', '#chose-btn-sure', function() {
//确定
}).on('touchstart', '.block', function(e) {
// var productSku,
// buyNumber = $('#good-num') - 0;
// promotionId,
// goodsType,
// isEdit;
// //确定
// $chosed = $('.block-list>ul>li.chosed');
// if (2 === $chosed.length && 2 !== $chosed.closest('.zero-stock').length) {
// if (confirm) {
// return false;
// }
// confirm = true;
// loading.showLoadingMask();
// $.ajax({
// method: 'POST',
// url: '/cart/index/add',
// data: {
// product_id: productId,
// content: content
// }
// }).done(function(res) {
// if (res.code === 200) {
// loading.hideLoadingMask();
// confirm = false;
// remove();
// }
// }).fail(function() {
// tip.show('网络出了点问题~');
// confirm = false;
// });
// }
//尺寸颜色点选
}).on('touchstart', '.block', function(e) {
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
numArray,
... ... @@ -96,6 +150,19 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}
});
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
if ($this.closest('.block-list').hasClass('color-list')) {
$sizeList.addClass('hide');
//切换尺码信息
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === $this.data('id')) {
$(this).removeClass('hide');
}
});
}
numArray = ($chosed.data('numstr') + '').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
... ... @@ -104,6 +171,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}
}
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if (0 === $(this).data('num') - 0) {
... ... @@ -123,19 +193,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
}
}).on('touchstart', '.btn-minus', function() {
var num = +$num.val(),
$chosed = $('.block-list>ul>li.chosed');
$chosed = $('.block-list>ul>li.chosed'),
leftNum = re.exec($('.num .left-num').html());
//若颜色和尺码没有被同时选中,则不能点击
if ($chosed.length < 2) {
return;
}
if (num === 0) {
if (num === 1 || 0 === leftNum - 0) {
return;
}
... ... @@ -147,6 +221,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
leftNum = re.exec($('.num .left-num').html());
if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
return;
}
//TODO:库存数验证
$num.val(num + 1);
... ...
... ... @@ -36,6 +36,9 @@ function getProductInfo(skn, promotionId) {
return;
}
console.log(res);
if (!panelTmpl) {
return;
}
if (res.code === 200) {
$chosePanel.html(panelTmpl(res.data));
chosePanel.show();
... ...
... ... @@ -13,7 +13,10 @@ var dialog = require('../me/dialog'),
tip = require('../plugin/tip');
var $names;
var $names,
$selectAllBtn = $('.balance .iconfont');
var requesting = false;
//var $curDelPanel;
... ... @@ -167,6 +170,122 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
// });
//})
function requestUpdateAllGoodsCheckStatus(theGoods, successHandeler) {
if (requesting) {
return;
}
requesting = true;
$.ajax({
url: 'select',
type: 'post',
data: {
skuList: JSON.stringify(theGoods)
},
success: function(res) {
if (res.code === 200) {
successHandeler();
} else {
tip.show(res.message);
}
},
error: function(err) {
tip.show('网络异常');
},
complete: function() {
requesting = false;
}
});
}
function didUpdateAllGoodsCheckStatus() {
var $checkedBoxs = $('.shopping-cart-good .icon-cb-checked'),
$uncheckedBoxs = $('.shopping-cart-good .icon-checkbox');
var shouldSelectAll;
if ($selectAllBtn.hasClass('icon-cb-checked')) {
$selectAllBtn.removeClass('icon-cb-checked').addClass('icon-checkbox');
shouldSelectAll = true;
} else {
$selectAllBtn.removeClass('icon-checkbox').addClass('icon-cb-checked');
shouldSelectAll = false;
}
if (!shouldSelectAll) {
$uncheckedBoxs.each(function(idx, uncheckedBox) {
$(uncheckedBox).removeClass('icon-checkbox').addClass('icon-cb-checked');
});
} else {
$checkedBoxs.each(function(idx, checkedBox) {
$(checkedBox).removeClass('icon-cb-checked').addClass('icon-checkbox');
});
}
}
function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
var goodInfo = {};
var $goods = $('.cart-content:not(.hide) .shopping-cart-good');
var $good = null;
var goodsList = [];
function GoodInfo(properties) {
this.goods_type = properties.goods_type;
this.buy_number = properties.buy_number;
this.product_sku = properties.product_sku;
this.selected = properties.selected;
}
goodInfo.goods_type = type;
goodInfo.selected = isSelected ? 'Y' : 'N';
$goods.each(function(idx, good) {
$good = $(good);
goodInfo.product_sku = $(good).data('id');
goodInfo.buy_number = $good.find('.count').eq(0).text().trim().replace('×', '');
goodsList.push(new GoodInfo(goodInfo));
});
console.log(goodsList);
requestUpdateAllGoodsCheckStatus(goodsList, handlerAfterTouch);
}
//获取当前购物车类型
function getCartType() {
var $navItem = $('.cart-nav ').find('li'),
type = 'ordinary';
if ($navItem.eq(0).hasClass('active')) {
type = 'ordinary';
} else {
type = 'advance';
}
return type;
}
//是否要全选
function willBeSelected() {
var isSelected = true;
var $this = $(this);
if ($this.hasClass('icon-cb-checked')) {
isSelected = true;
} else {
isSelected = false;
}
return isSelected;
}
//全选按钮点击事件
$selectAllBtn.on('touchend', function() {
bottomCheckBoxHandeler(willBeSelected(), getCartType(), didUpdateAllGoodsCheckStatus);
});
$('.down').on('touchend', function() {
chosePanel.show();
});
... ...
... ... @@ -80,7 +80,7 @@ optHammer.on('tap', function(e) {
} else {
tip.show(res.message || '网络错误');
}
window.location.reload();
window.location.href = '/home/orders';
}).fail(function() {
tip.show('网络错误');
});
... ...
... ... @@ -8,7 +8,8 @@
right: 0;
background: rgba(0,0,0,.3);
z-index:3;
.main {
position: absolute;
height: pxToRem(610px);
... ... @@ -85,6 +86,10 @@
top: 20rem / $pxConvertRem;
}
}
.size-list li.hide {
display: none;
}
.block {
float: left;
... ...
... ... @@ -40,10 +40,10 @@
height: 25rem / $pxConvertRem;
color: #fff;
text-align: center;
background: #a1ce4e;
background: #eb76aa;
&:before {
content: '赠品';
content: '加价购';
display: block;
font-size: 12px;
line-height: 25rem / $pxConvertRem;
... ... @@ -56,6 +56,7 @@
}
.name {
margin-bottom: 20rem / $pxConvertRem;
width: 440rem / $pxConvertRem;
font-size: 28rem / $pxConvertRem;
}
... ... @@ -114,10 +115,10 @@
background: #f8f8f8;
}
.advance-block .tag {
background: #eb76aa;
.gift-block .tag {
background: #a1ce4e;
&:before {
content: '加价购';
content: '赠品';
}
}
}
... ...
... ... @@ -11,7 +11,12 @@
{{/ advanceBuy}}
{{else}}
{{# freebie}}
{{> cart/gift-advance-good}}
<div class="advance-block gift-block" data-promotion-id="{{promotionId}}">
<p class="title">{{title}}</p>
{{#goods}}
{{> cart/gift-advance-good}}
{{/goods}}
</div>
{{/ freebie}}
{{/if}}
... ...
{{#cartInfo}}
<div class="chose-panel">
<div class="main">
<div class="infos">
<div class="basic-info">
<div class="basic-info" >
{{#thumbs}}
{{#if @first}}
<img class="thumb" src={{img}}>
... ... @@ -25,17 +25,18 @@
<span>颜色</span>
<ul class="clearfix" data-type="color">
{{# colors}}
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}">
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-id="{{id}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}">
{{name}}
</li>
{{/ colors}}
</ul>
</div>
<div class="size-list block-list">
<span>尺码</span>
<span>尺码</span>
<ul class="clearfix" data-type="size" >
{{# sizes}}
<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}}">
<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}}">
{{name}}
</li>
{{/ sizes}}
... ... @@ -47,7 +48,7 @@
<a class="btn btn-minus" href="javascript:void(0);">
<span class="iconfont">&#xe625;</span>
</a>
<input id="good-num" class="good-num" type="text" value={{num}}>
<input id="good-num" class="good-num" type="text" value="1">
<a class="btn btn-plus" href="javascript:void(0);">
<span class="iconfont">&#xe624;</span>
</a>
... ... @@ -57,7 +58,8 @@
</div>
</div>
<div class="btn-wrap">
<button id="chose-btn-sure" class="btn btn-sure">加入购物车</button>
<button id="chose-btn-sure" class="btn btn-sure">确定</button>
</div>
</div>
</div>
{{/cartInfo}}
\ No newline at end of file
... ...
... ... @@ -7,11 +7,13 @@
<p class="name row">{{name}}</p>
<p class="row">
<span class="price">
¥{{price}}
¥{{#if price}}{{price}}{{else}}{{marketPrice}}{{/if}}
</span>
{{#if price}}
<span class="price market-price">
¥{{marketPrice}}
</span>
{{/if}}
<span class="count">
×{{count}}
</span>
... ...
... ... @@ -75,6 +75,7 @@
×{{count}}
</span>
</div>
</div>
<!--<div class="opt-panel hide">
<div class="put-in-favorite">
<span class="iconfont">&#xe622;</span>
... ...
... ... @@ -6,6 +6,9 @@
{{#navHome}}
<a href="{{.}}" class="iconfont nav-home">&#xe611;</a>
{{/navHome}}
{{#navPhone}}
<a href="{{.}}" class="iconfont nav-home">&#xe63e;</a>
{{/navPhone}}
{{#navTitle}}
<p class="nav-title">{{.}}</p>
{{/navTitle}}
... ... @@ -34,4 +37,4 @@
</li>
</ul>
</div>
{{/pageHeader}}
\ No newline at end of file
{{/pageHeader}}
... ...
... ... @@ -849,10 +849,11 @@ class HomeController extends AbstractAction
}
$this->setTitle('订单详情');
$this->setNavHeader('订单详情');
$this->setNavHeader('订单详情', true, false);
$this->_view->display('order-detail', array(
'orderDetailPage' => true,
'navPhone' => 'tel:400-889-9646',
'orderDetail' => $orderDetail,
));
}
... ...
... ... @@ -78,7 +78,7 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$productId = $this->post('skuList', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
... ...