Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
jinhu.tung
9 years ago
Commit
3b9a19b39a39aaaf72700cb07d48b8a0f6d239f7
2 parents
a87a52f5
bcaac4d2
Merge branch 'feature/shopping' into release/1.0
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
286 additions
and
192 deletions
apps/shopping/controllers/cart.js
apps/shopping/models/cart.js
apps/shopping/router.js
apps/shopping/views/action/cart.hbs
apps/shopping/views/partial/cart-list.hbs
apps/shopping/views/partial/cart/cart-list-body.hbs
apps/shopping/views/partial/cart/stepper.hbs
public/js/shopping/cart.page.js
public/js/shopping/cart/cart.js
public/js/shopping/cart/stepper.js
public/js/shopping/cart/util.js
public/scss/shopping/_cart-products.css
public/scss/shopping/_statement.css
apps/shopping/controllers/cart.js
View file @
3b9a19b
...
...
@@ -14,6 +14,7 @@ exports.index = (req, res) => {
const
uid
=
req
.
user
.
uid
||
null
;
cartModel
.
getCartData
(
shoppingKey
,
uid
).
then
((
result
)
=>
{
// console.log(JSON.stringify(result, '', 4))
if
(
result
.
code
===
200
)
{
res
.
display
(
'cart'
,
_
.
merge
({
module
:
'shopping'
,
...
...
@@ -31,64 +32,62 @@ exports.index = (req, res) => {
});
};
// 检查库存
exports
.
checkInventory
=
(
req
,
res
)
=>
{
let
chkResult
,
invalidProIds
=
[],
productId
=
req
.
query
.
productId
,
result
=
{};
if
(
productId
===
'ALL'
)
{
chkResult
=
false
;
invalidProIds
.
push
(
'286143'
);
}
else
{
if
(
req
.
query
.
productId
===
'286143'
)
{
chkResult
=
false
;
}
else
{
chkResult
=
true
;
}
}
if
(
invalidProIds
.
length
)
{
_
.
merge
(
result
,
{
invalidProIds
:
invalidProIds
});
}
_
.
merge
(
result
,
{
valid
:
chkResult
});
res
.
json
(
result
);
};
// 修改数量
exports
.
changeProductNum
=
(
req
,
res
)
=>
{
const
changeType
=
req
.
body
.
changeType
;
const
changeTo
=
req
.
body
.
changeTo
;
// const changeTo = req.body.changeTo;
const
uid
=
req
.
user
.
uid
;
const
shoppingKey
=
req
.
cookies
.
_SPK
;
const
sku
=
req
.
body
.
sku
;
const
goodTpye
=
req
.
body
.
goodType
;
if
(
changeType
===
'INCREASE'
)
{
// TODO
if
(
changeTo
===
'4'
)
{
res
.
json
({
code
:
'1000'
,
num
:
parseInt
(
changeTo
,
10
)
-
1
,
changed
:
false
});
}
else
{
res
.
json
({
code
:
'0'
,
num
:
changeTo
,
changed
:
true
});
}
cartModel
.
modifyProductNum
({
increaseNum
:
1
,
// 默认是1
uid
,
shoppingKey
,
sku
,
goodTpye
}).
then
(
result
=>
{
console
.
log
(
'changeProductNum-INCREASE-result:'
,
result
);
if
(
result
.
code
===
200
)
{
cartModel
.
getCartData
(
shoppingKey
,
uid
).
then
(
cartData
=>
{
res
.
json
(
_
.
merge
(
cartModel
.
filterCartData
(
cartData
,
uid
),
{
code
:
cartData
.
code
,
message
:
result
.
message
})
);
});
}
else
{
res
.
json
(
result
);
}
});
// res.json({
// code: '1000',
// num: parseInt(changeTo, 10) - 1,
// changed: false
// });
}
else
if
(
changeType
===
'DECREASE'
)
{
// TODO
res
.
json
({
code
:
'0'
,
num
:
changeTo
,
changed
:
true
cartModel
.
modifyProductNum
({
decreaseNum
:
1
,
// 默认是1
uid
,
shoppingKey
,
sku
,
goodTpye
}).
then
(
result
=>
{
console
.
log
(
'changeProductNum-DECREASE-result:'
,
result
);
if
(
result
.
code
===
200
)
{
cartModel
.
getCartData
(
shoppingKey
,
uid
).
then
(
cartData
=>
{
res
.
json
(
_
.
merge
(
cartModel
.
filterCartData
(
cartData
,
uid
),
{
code
:
cartData
.
code
,
message
:
result
.
message
})
);
});
}
else
{
res
.
json
(
result
);
}
});
}
};
...
...
@@ -122,9 +121,23 @@ exports.removeProduct = (req, res) => {
// 收藏商品
exports
.
sendToFavorite
=
(
req
,
res
)
=>
{
// TODO
res
.
json
({
code
:
'0'
const
params
=
{};
const
uid
=
req
.
user
.
uid
;
const
productSkuList
=
req
.
body
.
skuList
;
if
(
uid
)
{
_
.
merge
(
params
,
{
uid
});
}
if
(
productSkuList
)
{
_
.
merge
(
params
,
{
product_sku_list
:
productSkuList
});
}
console
.
log
(
'transferToFavorite---params:'
,
params
);
cartModel
.
transferToFavorite
(
params
).
then
(
result
=>
{
console
.
log
(
'transferToFavorite-result:'
,
result
);
res
.
json
(
_
.
merge
(
cartModel
.
filterCartData
(
result
,
uid
),
{
code
:
result
.
code
,
message
:
result
.
message
}));
});
};
...
...
@@ -159,6 +172,7 @@ exports.addToCart = (req, res) => {
shoppingKey
:
req
.
cookies
.
_SPK
||
null
,
uid
:
req
.
user
.
uid
}).
then
((
result
)
=>
{
res
.
cookie
(
'_SPK'
,
result
.
data
.
shopping_key
);
res
.
json
(
result
);
});
};
...
...
@@ -194,39 +208,5 @@ exports.toggleSelectGoods = (req, res) => {
});
};
// 购物车商品选择与取消选择
exports
.
modifyProductNum
=
(
req
,
res
)
=>
{
const
uid
=
req
.
user
.
uid
;
const
shoppingKey
=
req
.
cookies
.
_SPK
;
const
changeType
=
req
.
body
.
changeType
;
const
changeNum
=
req
.
body
.
changeNum
;
const
sku
=
req
.
body
.
sku
;
let
params
=
{
uid
,
shoppingKey
,
sku
};
if
(
changeType
===
'INCREASE'
)
{
_
.
merge
(
params
,
{
increaseNum
:
changeNum
});
}
else
if
(
changeType
===
'DECREASE'
)
{
_
.
merge
(
params
,
{
decreaseNum
:
changeNum
});
}
else
{
// TODO
// CHANGE
}
cartModel
.
modifyProductNum
(
params
).
then
(
result
=>
{
res
.
json
(
_
.
merge
(
cartModel
.
filterCartData
(
result
,
uid
),
{
code
:
result
.
code
,
message
:
result
.
message
}));
});
};
...
...
apps/shopping/models/cart.js
View file @
3b9a19b
...
...
@@ -112,16 +112,10 @@ const getCartData = (shoppingKey, uid) => {
* @param { Boolean } hasPromotion 是否有促销ID, 默认值是false
* @return { Array }
*/
const
transferToFavorite
=
(
uid
,
sku
,
hasPromotion
)
=>
{
let
method
=
hasPromotion
?
'app.Shopping.addfavoriteAndCart'
:
'app.Shopping.addfavorite'
;
let
params
=
{
method
};
_
.
merge
(
params
,
{
product_sku_list
:
sku
,
uid
// 用户必须登录吗 TODO
});
const
transferToFavorite
=
(
params
)
=>
{
let
method
=
'app.Shopping.addfavoriteAndCart'
;
_
.
merge
(
params
,
{
method
});
return
api
.
get
(
''
,
params
);
};
...
...
@@ -271,7 +265,7 @@ const filterCartData = (result, uid) => {
* @param { Number } increaseNum 增加的数目
* @param { Number } decreaseNum 减少的数目
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Array } 接口返回
的
数据
* @return { Array } 接口返回
单个商品的增减
数据
*/
const
modifyProductNum
=
(
options
)
=>
{
const
increaseNum
=
options
.
increaseNum
;
...
...
@@ -279,6 +273,7 @@ const modifyProductNum = (options) => {
const
uid
=
options
.
uid
;
const
shoppingKey
=
options
.
shoppingKey
;
const
sku
=
options
.
sku
;
const
goodType
=
options
.
goodType
;
let
params
=
{
product_sku
:
options
.
sku
...
...
@@ -310,13 +305,22 @@ const modifyProductNum = (options) => {
});
}
if
(
sku
)
{
_
.
merge
(
params
,
{
product_sku
:
sku
});
}
_
.
merge
(
params
,
{
product_sku
:
sku
});
return
getCartData
(
shoppingKey
,
uid
).
then
(
function
(
result
)
{
console
.
log
(
'getCartData--pre-callback-result:'
,
result
);
console
.
log
(
'modifyProductNum---params:'
,
params
);
if
(
goodType
===
'advance'
)
{
// 检查库存量
}
else
if
(
goodType
===
'ordinary'
)
{
// 检查库存量
}
return
api
.
get
(
''
,
params
);
});
return
api
.
get
(
''
,
params
);
};
module
.
exports
=
{
...
...
apps/shopping/router.js
View file @
3b9a19b
...
...
@@ -15,10 +15,9 @@ const order = require(`${cRoot}/order`); // 下单
// 购物车
router
.
get
(
'/cart'
,
cartCtrl
.
index
);
router
.
get
(
'/cart/product/check_inventory'
,
cartCtrl
.
checkInventory
);
router
.
post
(
'/cart/product/:productId/change_num'
,
cartCtrl
.
changeProductNum
);
router
.
post
(
'/cart/product/change_num'
,
cartCtrl
.
changeProductNum
);
router
.
delete
(
'/cart/product/remove'
,
cartCtrl
.
removeProduct
);
router
.
post
(
'/cart/product/
:productId/
send_to_favorite'
,
cartCtrl
.
sendToFavorite
);
router
.
post
(
'/cart/product/send_to_favorite'
,
cartCtrl
.
sendToFavorite
);
router
.
get
(
'/cart/product/:productId/edit'
,
cartCtrl
.
editProduct
);
router
.
post
(
'/cart/add'
,
cartCtrl
.
addToCart
);
router
.
post
(
'/cart/toggleSelectGoods'
,
cartCtrl
.
toggleSelectGoods
);
...
...
apps/shopping/views/action/cart.hbs
View file @
3b9a19b
...
...
@@ -7,8 +7,7 @@
{{^}}
{{>
cart
/
empty-cart
}}
{{/if}}
{{!-- <button id="add_to_cart1">添加到购物车 980874 number 1</button>
<button id="add_to_cart2">添加到购物车 980870 number 2</button> --}}
{{!-- <button id="add_to_cart1">添加到购物车 1413600 number 1</button> --}}
</div>
</div>
<script
id=
"edit-color-size-tpl"
type=
"text/html"
>
...
...
apps/shopping/views/partial/cart-list.hbs
View file @
3b9a19b
...
...
@@ -40,11 +40,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
\{{!-- <div class="brand-name">\{{brand_name}}</div> --}}
<div class="pro-name">
\{{product_name}}
</div>
<div class="pro-name">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a>
</div>
<div class="size">
\{{#if size_name}}
<span>尺寸: \{{size_name}}</span>
...
...
@@ -101,11 +103,13 @@
<input type="hidden" name="product_ids[]"/>
</li>
<li>
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
\{{!-- <div class="brand-name">\{{brandName}}</div> --}}
<div class="pro-name">
\{{product_name}}
</div>
<div class="pro-name">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a>
</div>
<div class="color-size editable" data-product_id=\{{product_id}} id="edit_\{{product_id}}">
\{{#if color_name}}
<span class="mr20">颜色: \{{color_name}}</span>
...
...
@@ -154,13 +158,20 @@
<span class="iconfont warning"></span>
</li>
<li>
<img src="\{{image defaultImages 100 134}}" alt="\{{productName}}">
<a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">
<img src="\{{image goods_images 100 134}}" alt="\{{product_name}}">
</a>
</li>
<li class="pro-info">
<div class="brand-name">\{{brandName}}</div>
<div class="pro-name">\{{productName}}</div>
<div class="size">尺寸: USB</div>
<div class="published-at">上市期: 2016年8月</div>
<div class="pro-name"><a href="/product/pro_\{{goods_id}}_\{{product_id}}/\{{cn_alphabet}}.html">\{{product_name}}</a></div>
<div>
\{{#if color_name}}
<span class="mr20">颜色: \{{color_name}}</span>
\{{/if}}
\{{#if size_name}}
<span>尺寸: \{{size_name}}</span>
\{{/if}}
</div>
</li>
<li class="price-num">
<span class="price sale-price">¥\{{salesPrice}}</span>
...
...
apps/shopping/views/partial/cart/cart-list-body.hbs
View file @
3b9a19b
...
...
@@ -17,11 +17,13 @@
<input
type=
"hidden"
name=
"product_ids[]"
/>
</li>
<li>
<img
src=
"
{{
image
goods_images
100
134
}}
"
alt=
"
{{
product_name
}}
"
>
<a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
<img
src=
"
{{
image
goods_images
100
134
}}
"
alt=
"
{{
product_name
}}
"
>
</a>
</li>
<li
class=
"pro-info"
>
{{!-- <div class="brand-name">{{brand_name}}</div> --}}
<div
class=
"pro-name"
>
{{
product_name
}}
</div>
<div
class=
"pro-name"
>
<a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
{{
product_name
}}
</a>
</div>
<div
class=
"size"
>
{{#if
size_name
}}
<span>
尺寸:
{{
size_name
}}
</span>
...
...
@@ -68,11 +70,13 @@
<input
type=
"hidden"
name=
"product_ids[]"
/>
</li>
<li>
<img
src=
"
{{
image
goods_images
100
134
}}
"
alt=
"
{{
product_name
}}
"
>
<a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
<img
src=
"
{{
image
goods_images
100
134
}}
"
alt=
"
{{
product_name
}}
"
>
</a>
</li>
<li
class=
"pro-info"
>
{{!-- <div class="brand-name">{{brandName}}</div> --}}
<div
class=
"pro-name"
>
{{
product_name
}}
</div>
<div
class=
"pro-name"
>
<a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
{{
product_name
}}
</a>
</div>
<div
class=
"color-size editable"
data-product_id=
{{
product_id
}}
id="edit_
{{
product_id
}}
"
>
{{#if
color_name
}}
<span
class=
"mr20"
>
颜色:
{{
color_name
}}
</span>
...
...
@@ -111,13 +115,20 @@
<span
class=
"iconfont warning"
>

</span>
</li>
<li>
<img
src=
"
{{
image
defaultImages
100
134
}}
"
alt=
"
{{
productName
}}
"
>
<a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
<img
src=
"
{{
image
goods_images
100
134
}}
"
alt=
"
{{
product_name
}}
"
>
</a>
</li>
<li
class=
"pro-info"
>
<div
class=
"brand-name"
>
{{
brandName
}}
</div>
<div
class=
"pro-name"
>
{{
productName
}}
</div>
<div
class=
"size"
>
尺寸: USB
</div>
<div
class=
"published-at"
>
上市期: 2016年8月
</div>
<div
class=
"pro-name"
><a
href=
"/product/pro_
{{
goods_id
}}
_
{{
product_id
}}
/
{{
cn_alphabet
}}
.html"
>
{{
product_name
}}
</a></div>
<div>
{{#if
color_name
}}
<span
class=
"mr20"
>
颜色:
{{
color_name
}}
</span>
{{/if}}
{{#if
size_name
}}
<span>
尺寸:
{{
size_name
}}
</span>
{{/if}}
</div>
</li>
<li
class=
"price-num"
>
<span
class=
"price sale-price"
>
¥
{{
salesPrice
}}
</span>
...
...
apps/shopping/views/partial/cart/stepper.hbs
View file @
3b9a19b
<div
class=
"stepper"
data-product
Id=
{{
productId
}}
>
<div
class=
"stepper"
data-product
Type=
{{
goods_type
}}
>
<div
class=
"minus action"
>
<span
class=
"iconfont"
>

</span>
</div>
...
...
public/js/shopping/cart.page.js
View file @
3b9a19b
...
...
@@ -14,17 +14,49 @@ $(function() {
Cart
.
toggleCheck
.
call
(
Cart
,
this
);
}).
delegate
(
'.remove-item'
,
'click'
,
function
()
{
// 删除商品
Cart
.
removePro
(
$
(
this
).
parents
(
'ul'
).
children
().
first
().
attr
(
'data-product_info'
));
// 重构
Cart
.
removePro
([
$
.
parseJSON
(
$
(
this
).
parents
(
'ul'
).
children
().
first
().
attr
(
'data-product_info'
))]);
}).
delegate
(
'#remove_selected'
,
'click'
,
function
(
e
)
{
// 删除多个商品
// 重构
// 选择的商品
var
selectedProducts
=
[],
product
;
e
.
preventDefault
();
$
(
'#cart_content'
).
find
(
'li.chk'
).
each
(
function
()
{
product
=
$
(
this
);
if
(
product
.
find
(
'label.chk-group'
).
length
)
{
selectedProducts
.
push
(
$
.
parseJSON
(
product
.
attr
(
'data-product_info'
)));
}
});
Cart
.
removePro
(
selectedProducts
);
}).
delegate
(
'.send-to-favorite'
,
'click'
,
function
()
{
// 移入收藏夹
Cart
.
sendToFavorite
(
$
(
this
).
attr
(
'data-productId'
));
// 重构
Cart
.
sendToFavorite
([
$
.
parseJSON
(
$
(
this
).
parents
(
'ul'
).
children
().
first
().
attr
(
'data-product_info'
))]);
}).
delegate
(
'#send_favorite'
,
'click'
,
function
(
e
)
{
// 将多个商品移入收藏夹
// 重构
// 选择的商品
var
selectedProducts
=
[],
product
;
e
.
preventDefault
();
$
(
'#cart_content'
).
find
(
'li.chk'
).
each
(
function
()
{
product
=
$
(
this
);
if
(
product
.
find
(
'label.chk-group'
).
length
)
{
selectedProducts
.
push
(
$
.
parseJSON
(
product
.
attr
(
'data-product_info'
)));
}
});
Cart
.
sendToFavorite
(
selectedProducts
);
}).
delegate
(
'.editable'
,
'click'
,
function
()
{
// 编辑商品颜色和属性
Cart
.
editColorOrSize
(
$
(
this
).
attr
(
'data-productId'
));
}).
delegate
(
'#checkout_btn'
,
'click'
,
function
(
e
)
{
e
.
preventDefault
();
if
(
!
$
(
this
).
hasClass
(
'disable'
))
{
window
.
location
.
href
=
"/shopping/order"
;
if
(
!
$
(
this
).
hasClass
(
'disable'
))
{
window
.
location
.
href
=
'/shopping/order'
;
}
});
...
...
@@ -54,7 +86,7 @@ $(function() {
// TODO=>
// $('#add_to_cart1').on('click', function() {
// Cart.addToCart({
// productSku: '
870896
',
// productSku: '
1413600
',
// buyNumber: 1
// });
// });
...
...
public/js/shopping/cart/cart.js
View file @
3b9a19b
...
...
@@ -11,7 +11,6 @@ var _confirm = Dialog.Confirm;
var
_alert
=
Dialog
.
Alert
;
var
Util
=
require
(
'./util'
);
var
hbs
=
require
(
'yoho-handlebars'
);
var
common
=
require
(
'../../common'
);
var
Stepper
=
require
(
'./stepper'
);
var
Cart
=
{
...
...
@@ -23,22 +22,16 @@ var Cart = {
* @params { Function } callback 购买结果回调
*/
addToCart
:
function
(
params
,
callback
)
{
// TODO
// common.setCookie('uid', '20000058');
Util
.
ajax
({
url
:
'/shopping/cart/add'
,
type
:
'POST'
,
data
:
params
,
success
:
function
(
res
)
{
if
(
res
.
code
===
200
)
{
common
.
setCookie
(
'_SPK'
,
res
.
data
.
shopping_key
);
if
(
callback
)
{
return
callback
(
res
);
}
}
},
fail
:
function
()
{
// TODO
}
});
},
...
...
@@ -206,38 +199,39 @@ var Cart = {
dialog
.
close
();
Util
.
ajax
({
url
:
'/shopping/cart/product/remove'
,
data
:
{
skuList
:
JSON
.
stringify
(
[
$
.
parseJSON
(
products
)]
)},
data
:
{
skuList
:
JSON
.
stringify
(
products
)},
type
:
'DELETE'
,
success
:
function
(
res
)
{
if
(
res
.
code
===
200
)
{
Cart
.
refreshCart
(
res
);
}
else
{
_alert
(
res
.
message
);
}
},
fail
:
function
()
{
// TODO
Cart
.
refreshCart
(
res
);
}
});
}
}).
show
();
},
// 移入收藏夹
sendToFavorite
:
function
(
productId
)
{
var
dialog
=
new
_confirm
({
content
:
'确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示'
,
/*
* 删除商品
* @function [removePro]
* @params { Array } products 商品列表
*/
sendToFavorite
:
function
(
products
)
{
var
msg
=
'确定要将该商品从购物车中移入收藏吗?<br/>移入收藏后该商品将不在购物车中显示'
;
var
dialog
;
if
(
products
.
length
>
1
)
{
msg
=
'确定要将已选中的商品从购物车中移入收藏吗?<br/>移入收藏后已选中的商品将不在购物车中显示'
;
}
dialog
=
new
_confirm
({
content
:
msg
,
cb
:
function
()
{
dialog
.
close
();
Util
.
ajax
({
url
:
'/shopping/cart/product/
'
+
productId
+
'/
send_to_favorite'
,
url
:
'/shopping/cart/product/send_to_favorite'
,
type
:
'POST'
,
data
:
{
skuList
:
JSON
.
stringify
(
products
)},
success
:
function
(
res
)
{
if
(
res
.
code
===
'0'
)
{
dialog
.
close
();
}
},
fail
:
function
()
{
// TODO
Cart
.
refreshCart
(
res
);
}
});
}
...
...
public/js/shopping/cart/stepper.js
View file @
3b9a19b
...
...
@@ -6,24 +6,28 @@
*/
var
Util
=
require
(
'./util'
);
var
$
=
require
(
'yoho-jquery'
);
var
Stepper
=
{
// 减少商品数量
decrease
:
function
(
productId
,
currNum
,
callback
)
{
decrease
:
function
(
goodType
,
sku
,
currNum
)
{
if
(
parseInt
(
currNum
,
10
)
<=
1
)
{
return
callback
(
1
);
//
return callback(1);
}
else
{
Util
.
ajax
({
url
:
'/shopping/cart/product/
'
+
productId
+
'/
change_num'
,
url
:
'/shopping/cart/product/change_num'
,
type
:
'POST'
,
data
:
{
changeType
:
'DECREASE'
,
changeTo
:
parseInt
(
currNum
,
10
)
-
1
sku
:
sku
,
goodType
:
goodType
// changeTo: parseInt(currNum, 10) - 1
},
success
:
function
(
res
)
{
if
(
res
.
code
===
'0'
)
{
return
callback
(
res
.
num
,
res
.
changed
);
}
Util
.
refreshCart
(
res
,
function
()
{
Stepper
.
init
();
});
}
});
}
...
...
@@ -31,21 +35,26 @@ var Stepper = {
},
// 增加商品数量
increase
:
function
(
productId
,
currNum
,
callback
)
{
increase
:
function
(
goodType
,
sku
)
{
Util
.
ajax
({
url
:
'/shopping/cart/product/
'
+
productId
+
'/
change_num'
,
url
:
'/shopping/cart/product/change_num'
,
type
:
'POST'
,
data
:
{
changeType
:
'INCREASE'
,
changeTo
:
parseInt
(
currNum
,
10
)
+
1
sku
:
sku
,
goodType
:
goodType
// changeTo: parseInt(currNum, 10) + 1
},
success
:
function
(
res
)
{
if
(
res
.
code
===
'0'
)
{
return
callback
(
res
.
num
,
res
.
changed
);
}
else
{
return
callback
(
res
.
num
,
res
.
changed
,
res
.
code
===
'1000'
);
}
// if (res.code === '0') {
// return callback(res.num, res.changed);
// } else {
// return callback(res.num, res.changed, res.code === '1000');
// }
Util
.
refreshCart
(
res
,
function
()
{
Stepper
.
init
();
});
}
});
},
...
...
@@ -53,7 +62,8 @@ var Stepper = {
init
:
function
()
{
var
_this
=
this
,
$target
,
productId
;
sku
,
goodType
;
var
steppers
=
$
(
'.stepper'
),
$input
,
...
...
@@ -77,8 +87,9 @@ var Stepper = {
plus
=
$input
.
parent
().
next
();
if
(
!
$target
.
hasClass
(
'disable'
))
{
productId
=
$target
.
parent
().
attr
(
'data-productId'
);
_this
.
decrease
(
productId
,
currNum
,
function
(
num
,
changed
)
{
sku
=
$
.
parseJSON
(
$target
.
parents
(
'ul'
).
children
().
first
().
attr
(
'data-product_info'
)).
product_sku
;
goodType
=
$target
.
parent
().
attr
(
'data-producttype'
);
_this
.
decrease
(
goodType
,
sku
,
currNum
,
function
(
num
,
changed
)
{
if
(
num
===
1
)
{
$input
.
val
(
1
);
$target
.
addClass
(
'disable'
);
...
...
@@ -103,8 +114,9 @@ var Stepper = {
minus
=
$input
.
parent
().
prev
();
if
(
!
$target
.
hasClass
(
'disable'
))
{
productId
=
$target
.
parent
().
attr
(
'data-productId'
);
_this
.
increase
(
productId
,
currNum
,
function
(
num
,
changed
,
overflow
)
{
sku
=
$
.
parseJSON
(
$target
.
parents
(
'ul'
).
children
().
first
().
attr
(
'data-product_info'
)).
product_sku
;
goodType
=
$target
.
parent
().
attr
(
'data-producttype'
);
_this
.
increase
(
goodType
,
sku
,
currNum
,
function
(
num
,
changed
,
overflow
)
{
if
(
overflow
)
{
$target
.
addClass
(
'disable'
);
}
...
...
public/js/shopping/cart/util.js
View file @
3b9a19b
...
...
@@ -6,6 +6,7 @@
*/
var
dialog
=
require
(
'../../plugins/dialog'
);
var
_alert
=
dialog
.
Alert
;
var
hbs
=
require
(
'yoho-handlebars'
);
var
Util
=
{
ajax
:
function
(
options
)
{
...
...
@@ -15,8 +16,10 @@ var Util = {
data
:
options
.
data
||
{},
dataType
:
'json'
}).
done
(
function
(
res
)
{
if
(
options
.
success
)
{
if
(
options
.
success
&&
res
.
code
===
200
)
{
options
.
success
(
res
);
}
else
{
new
_alert
(
res
.
message
).
show
();
}
}).
fail
(
function
()
{
if
(
options
.
fail
)
{
...
...
@@ -25,6 +28,45 @@ var Util = {
new
_alert
(
'网络异常,稍后请重试'
).
show
();
}
});
},
/*
* 根据服务端JSON,刷新购物车信息
* @function [refreshCart]
*/
refreshCart
:
function
(
data
,
callback
)
{
var
template
;
hbs
.
registerHelper
(
'multiple'
,
function
(
num1
,
num2
)
{
num1
=
typeof
num1
===
'number'
?
num1
:
parseFloat
(
num1
,
10
);
num2
=
typeof
num2
===
'number'
?
num2
:
parseFloat
(
num2
,
10
);
if
(
num1
&&
num2
)
{
return
num1
*
num2
;
}
else
{
console
.
error
(
'multiplication needs two number parameters'
);
}
});
hbs
.
registerHelper
(
'isEqual'
,
function
(
v1
,
v2
,
options
)
{
if
(
v1
===
v2
)
{
return
options
.
fn
(
this
);
}
return
options
.
inverse
(
this
);
});
hbs
.
registerHelper
(
'image'
,
function
(
url
,
width
,
height
,
mode
)
{
mode
=
parseInt
(
mode
,
10
)
?
mode
:
2
;
url
=
url
||
''
;
return
url
.
replace
(
/{width}/g
,
width
).
replace
(
/{height}/g
,
height
).
replace
(
/{mode}/g
,
mode
);
});
template
=
hbs
.
compile
(
$
(
'#cart-content-tpl'
).
html
());
$
(
'#cart_content'
).
html
(
template
(
data
));
if
(
callback
)
{
return
callback
();
}
}
};
...
...
public/scss/shopping/_cart-products.css
View file @
3b9a19b
...
...
@@ -73,6 +73,11 @@ $hoverColor: #379ed6;
width
:
234px
;
word-wrap
:
break-word
;
margin-bottom
:
13px
;
display
:
-webkit-box
;
-webkit-box-orient
:
vertical
;
-webkit-line-clamp
:
2
;
line-height
:
1.3em
;
overflow
:
hidden
;
}
.size
{
...
...
@@ -137,17 +142,22 @@ $hoverColor: #379ed6;
width
:
168px
;
position
:
relative
;
.iconfont
{
display
:
none
;
}
&
:hover
{
cursor
:
pointer
;
border
:
1px
dashed
#3a9ed6
;
}
.iconfont
{
position
:
absolute
;
right
:
5px
;
top
:
3px
;
font-size
:
16px
;
font-weight
:
normal
!important
;
.iconfont
{
position
:
absolute
;
right
:
5px
;
top
:
3px
;
font-size
:
16px
;
font-weight
:
normal
!important
;
display
:
inline-block
!important
;
}
}
.sizes-list
{
width
:
195px
;
...
...
public/scss/shopping/_statement.css
View file @
3b9a19b
...
...
@@ -60,11 +60,11 @@
.checkout-total
{
position
:
relative
;
display
:
inline-block
;
float
:
right
;
font-size
:
14px
;
color
:
#1b1b1b
;
font-weight
:
bold
;
width
:
35
8
px
;
width
:
35
0
px
;
div
{
display
:
inline-block
;
...
...
@@ -90,7 +90,7 @@
.checkout
{
margin-top
:
40px
;
float
:
right
;
margin-right
:
200
px
;
margin-right
:
192
px
;
.btn
{
padding
:
14px
59px
;
...
...
Please
register
or
login
to post a comment