Authored by 梁志锋

购物车功能修改

framework @ e9d066dd
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
... ...
... ... @@ -123,7 +123,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
i;
var $siblingBlock = $this.closest('.block-list').siblings(':first'),
currentNumArray = $this.data('numstr').split('/');
currentNumArray = ($this.data('numstr') + '').split('/');
$this.siblings('.chosed').removeClass('chosed');
$this.toggleClass('chosed');
... ... @@ -163,7 +163,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
});
}
numArray = $chosed.data('numstr').split('/');
numArray = ($chosed.data('numstr') + '').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
if (0 === numArray[i] - 0) {
... ...
... ... @@ -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();
... ...
... ... @@ -12,17 +12,10 @@ var $ = require('jquery'),
var dialog = require('../me/dialog'),
tip = require('../plugin/tip');
var $names;
var $names,
$selectAllBtn = $('.balance .iconfont');
//var $curDelPanel;
////删除面板显示后任何点击行为都将触发隐藏面板
//function docTouchEvt() {
// $curDelPanel && $curDelPanel.addClass('hide');
//
// //
// $(document).off('touchstart', docTouchEvt);
//}
var requesting = false;
ellipsis.init();
... ... @@ -167,30 +160,122 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
// });
//})
$('.down').on('touchend', function() {
chosePanel.show();
});
$('.cut').on('touchend', function() {
var id = $(this).closest('.shopping-cart-good').data('id');
function requestUpdateAllGoodsCheckStatus(theGoods, successHandeler) {
if (requesting) {
return;
}
requesting = true;
$.ajax({
type: 'GET',
url: '/cart/index/modify',
data: {
old_product_sku: id,
new_product_sku: id,
buy_number: '0',
selected: 'Y'
},
success: function(data) {
if (data.code === 200) {
window.history.go(0);
}
},
error: function() {
tip.show('网络错误');
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('网络错误');
});
... ...
... ... @@ -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}}
... ...
... ... @@ -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>
... ...
... ... @@ -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,
));
}
... ...
... ... @@ -582,18 +582,14 @@ class CartModel
{
$data = array();
// 品牌信息
if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {
$data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);
}
$data['name'] = $productData['product_name'];
$data['price'] = $productData['market_price'];
$data['salePrice'] = $productData['sales_price'];
$data['price'] = Helpers::transPrice($productData['market_price']);
$data['salePrice'] = Helpers::transPrice($productData['sales_price']);
if (isset($productData['storage_sum'])) {
$data['storage'] = $productData['storage_sum'];
}
$data['num'] = 1;
if ($num !== null) {
$data['num'] = $num;
}
... ... @@ -606,25 +602,62 @@ class CartModel
$oneColor = array();
$sizes = array();
$oneSize = array();
$thumbImageList = array();
$colorNum = 0;
$totalStorageNum = 0; // 总库存数
$colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
foreach ($goodsList as $val) {
// 颜色
$oneColor = array();
$oneColor['id'] = $val['color_id'];
$oneColor['name'] = $val['color_name'];
$colorNum = 0;
$sizeStorageStr = '';
// 尺码
foreach ($val['size_list'] as $one) {
$oneSize = array();
$oneSize['id'] = $one['size_id'];
$oneSize['skuId'] = $one['product_sku'];
$oneSize['goodsId'] = $val['goods_id'];
$oneSize['colorId'] = $val['color_id'];
$oneSize['name'] = $one['size_name'];
$oneSize['sizeNum'] = $one['storage_number'];
$colorNum += $one['storage_number'];
$sizeStorageStr .= $one['storage_number'] . '/';
$sizes[] = $oneSize;
$colorStorageGroup[$one['size_name']][$val['color_name']] = $one['storage_number'];
}
$sizes[] = $oneSize;
$oneColor['sizes'] = $sizes;
// 统计尺码对应的各个颜色的库存量
foreach ($sizes as &$sizeArr) {
$sizeArr['colorNumStr'] = implode('/', array_values($colorStorageGroup[ $sizeArr['name'] ]) );
}
// 颜色
$oneColor = array();
$oneColor['id'] = $val['color_id'];
$oneColor['skcId'] = $val['product_skc'];
$oneColor['name'] = $val['color_name'];
$oneColor['goodsName'] = $productData['product_name'];
$oneColor['colorNum'] = $colorNum;
$oneColor['sizeNumStr'] = rtrim($sizeStorageStr, '/');
$colors[] = $oneColor;
// 缩略图
foreach ($val['images_list'] as $image) {
$thumbImageList[] = array(
'img' => Helpers::getImageUrl($image['image_url'], 60, 60)
);
}
// 商品库存总数
$totalStorageNum += $colorNum;
}
$data['thumbs'] = $thumbImageList;
$data['colors'] = $colors;
$data['sizes'] = $sizes;
$data['totalNum'] = $totalStorageNum;
}
return $data;
... ... @@ -668,7 +701,7 @@ class CartModel
// 失效商品列表
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
if (!empty($notValidGoods)) {
$result['$notValidGoods'] = $notValidGoods;
$result['notValidGoods'] = $notValidGoods;
}
// 赠品和加价购商品
... ...
... ... @@ -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);
... ... @@ -207,11 +207,11 @@ class IndexController extends AbstractAction
{
$result = array();
if ($this->isAjax()) {
// if ($this->isAjax()) {
$skn = $this->get('skn', null);
$promotionId = $this->get('promotionId', null);
$result = CartModel::giftProductData($skn, $promotionId);
}
// }
if (empty($result)) {
echo ' ';
... ...