Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
htoooth
9 years ago
Commit
1c11711a70ce549ddd1dede289d91d8f6261082a
1 parent
19d36c93
add controller brand
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
46 deletions
apps/product/controllers/favorite-brand.js → apps/product/controllers/favorite.js
apps/product/router.js
public/js/product/detail.page.js
apps/product/controllers/favorite
-brand
.js → apps/product/controllers/favorite.js
View file @
1c11711
...
...
@@ -5,8 +5,8 @@
const
helpers
=
require
(
`
$
{
library
}
/helpers`
)
;
const
mRoot
=
'../models'
;
const
service
=
require
(
`
$
{
mRoot
}
/favorite-service`
)
;
const
brandService
=
require
(
'../models/favorite-brand-service'
);
const
productService
=
require
(
'../models/favorite-product-service'
);
/**
* 收藏品牌ajax请求
...
...
@@ -14,10 +14,11 @@ const service = require(`${mRoot}/favorite-service`);
module
.
exports
.
changeFavoriteBrand
=
(
req
,
res
,
next
)
=>
{
// TODO: uid get
let
uid
=
''
;
let
brandId
=
req
.
body
.
brandId
;
if
(
uid
&&
brandId
)
{
s
ervice
.
changeAsync
(
uid
,
brandId
).
then
(
result
=>
{
brandS
ervice
.
changeAsync
(
uid
,
brandId
).
then
(
result
=>
{
res
.
json
(
result
)
}).
catch
(
next
);
}
else
if
(
!
uid
)
{
...
...
@@ -35,3 +36,55 @@ module.exports.changeFavoriteBrand = (req, res, next) => {
});
}
};
module
.
exports
.
collectProduct
=
(
req
,
res
,
next
)
=>
{
// TODO: uid get
let
uid
=
''
;
let
pid
=
req
.
body
.
productId
;
let
type
=
req
.
body
.
type
||
'add'
;
if
(
uid
&&
pid
)
{
switch
(
type
)
{
case
'add'
:
{
productService
.
createAsync
(
uid
,
pid
).
then
(
result
=>
{
if
(
result
.
code
===
413
)
{
result
.
message
=
'该商品已经收藏'
;
}
res
.
json
(
result
);
}).
catch
(
next
);
break
;
}
case
'cancel'
:
{
productService
.
deleteAsync
(
uid
,
pid
)
.
then
(
result
=>
res
.
json
(
result
))
.
catch
(
next
);
break
;
}
default
:
{
res
.
json
({
code
:
400
,
message
:
'错误类型'
});
}
}
}
else
if
(
!
uid
)
{
res
.
json
({
code
:
403
,
message
:
'用户没有登录'
,
data
:
{
url
:
helpers
.
urlFormat
(
'/signin.html'
)
}
})
}
else
{
res
.
json
({
code
:
400
,
message
:
'收藏失败'
})
}
};
...
...
apps/product/router.js
View file @
1c11711
...
...
@@ -12,8 +12,8 @@ const cRoot = './controllers';
// 商品详情controller
const
detail
=
require
(
`
$
{
cRoot
}
/detail`
)
;
// 收藏品牌
const
favorite
=
require
(
`
$
{
cRoot
}
/favorite-brand`
)
;
// 收藏品牌,商品,店铺
const
favorite
=
require
(
`
$
{
cRoot
}
/favorite`
)
;
// 商品促销controller
const
sale
=
require
(
`
$
{
cRoot
}
/sale`
)
;
...
...
@@ -50,5 +50,6 @@ router.get('/detail/hotarea', detail.indexHotArea);
// 收藏品牌
router
.
post
(
'/index/favoriteBrand'
,
favorite
.
changeFavoriteBrand
);
router
.
post
(
'/item/togglecollect'
,
favorite
.
collectProduct
);
module
.
exports
=
router
;
...
...
public/js/product/detail.page.js
View file @
1c11711
...
...
@@ -103,7 +103,7 @@ function showSizeWarn() {
}
// size title
(
function
()
{
(
function
()
{
var
$sizeTitleJson
=
$
(
'#size-title-json'
),
jsonHtml
=
$sizeTitleJson
.
html
(),
sizeTitle
;
...
...
@@ -117,7 +117,7 @@ function showSizeWarn() {
// 数据获取后删除
$sizeTitleJson
.
remove
();
$sizes
.
children
(
'li'
).
each
(
function
()
{
$sizes
.
children
(
'li'
).
each
(
function
()
{
var
$this
=
$
(
this
),
key
=
$this
.
data
(
'name'
);
...
...
@@ -129,7 +129,7 @@ function showSizeWarn() {
thumbsLoaded
[
$
(
'.colors .focus'
).
index
()]
=
true
;
// 品牌收藏
$
(
'#brand-favour'
).
click
(
function
()
{
$
(
'#brand-favour'
).
click
(
function
()
{
var
$this
=
$
(
this
);
$
.
ajax
({
...
...
@@ -138,7 +138,7 @@ $('#brand-favour').click(function() {
data
:
{
brandId
:
$this
.
data
(
'id'
)
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
if
(
data
.
code
===
200
)
{
$this
.
toggleClass
(
'coled'
);
}
else
if
(
data
.
code
===
403
)
{
...
...
@@ -148,7 +148,7 @@ $('#brand-favour').click(function() {
});
// 颜色
$
(
'.colors'
).
on
(
'click'
,
'li'
,
function
()
{
$
(
'.colors'
).
on
(
'click'
,
'li'
,
function
()
{
var
$this
=
$
(
this
),
index
=
$this
.
index
();
...
...
@@ -203,12 +203,12 @@ $('.colors').on('click', 'li', function() {
});
// 缩略图鼠标移入显示
$
(
'#thumbs'
).
on
(
'mouseenter'
,
'.thumb'
,
function
()
{
$
(
'#thumbs'
).
on
(
'mouseenter'
,
'.thumb'
,
function
()
{
imgShow
(
$
(
this
).
data
(
'shower'
));
});
// 尺码
$size
.
on
(
'click'
,
'li'
,
function
()
{
$size
.
on
(
'click'
,
'li'
,
function
()
{
var
$this
=
$
(
this
);
if
(
$this
.
hasClass
(
'focus'
))
{
...
...
@@ -227,7 +227,7 @@ $size.on('click', 'li', function() {
switchBtnStatus
();
resetNum
();
}).
on
(
'click'
,
'.size-ruler'
,
function
()
{
}).
on
(
'click'
,
'.size-ruler'
,
function
()
{
// 尺码帮助
...
...
@@ -237,7 +237,7 @@ $size.on('click', 'li', function() {
});
// 数量
$plusNum
.
click
(
function
()
{
$plusNum
.
click
(
function
()
{
var
num
=
getNum
();
if
(
$
(
this
).
hasClass
(
'dis'
))
{
...
...
@@ -266,11 +266,11 @@ $plusNum.click(function() {
}
$num
.
text
(
num
+
1
>
maxStock
?
maxStock
:
num
+
1
);
}).
on
(
'selectstart'
,
function
()
{
}).
on
(
'selectstart'
,
function
()
{
return
false
;
});
$minusNum
.
click
(
function
()
{
$minusNum
.
click
(
function
()
{
var
num
=
getNum
();
if
(
$
(
this
).
hasClass
(
'dis'
))
{
...
...
@@ -288,19 +288,19 @@ $minusNum.click(function() {
}
$num
.
text
(
num
-
1
<
0
?
0
:
num
-
1
);
}).
on
(
'selectstart'
,
function
()
{
}).
on
(
'selectstart'
,
function
()
{
return
false
;
});
// 限购码
$
(
'.get-lc:not(.dis)'
).
hover
(
function
()
{
$
(
'.get-lc:not(.dis)'
).
hover
(
function
()
{
$lcContainer
.
removeClass
(
'hide'
);
},
function
()
{
},
function
()
{
$lcContainer
.
addClass
(
'hide'
);
});
// 加入购物车
$addToCart
.
click
(
function
()
{
$addToCart
.
click
(
function
()
{
if
(
maxStock
===
-
1
)
{
showSizeWarn
();
return
;
...
...
@@ -313,7 +313,7 @@ $addToCart.click(function() {
productSku
:
$
(
'.size:not(.hide) li.focus'
).
data
(
'sku'
),
buyNumber
:
getNum
()
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
var
code
=
data
.
code
;
if
(
code
===
200
)
{
...
...
@@ -326,7 +326,7 @@ $addToCart.click(function() {
});
// 收藏
$
(
'#collect-product'
).
click
(
function
()
{
$
(
'#collect-product'
).
click
(
function
()
{
var
$this
=
$
(
this
),
cancel
;
...
...
@@ -341,7 +341,7 @@ $('#collect-product').click(function() {
productId
:
id
,
type
:
cancel
?
'cancel'
:
'add'
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
var
code
=
data
.
code
;
if
(
code
===
200
)
{
...
...
@@ -357,13 +357,13 @@ $('#collect-product').click(function() {
location
.
href
=
data
.
data
.
url
;
}
});
}).
hover
(
function
()
{
}).
hover
(
function
()
{
var
$this
=
$
(
this
);
if
(
$this
.
hasClass
(
'coled'
))
{
$this
.
find
(
'em'
).
text
(
colTxt
.
hover
);
}
},
function
()
{
},
function
()
{
var
$this
=
$
(
this
);
if
(
$this
.
hasClass
(
'coled'
))
{
...
...
@@ -372,13 +372,13 @@ $('#collect-product').click(function() {
});
// 继续购物
$
(
'#keep-shopping'
).
click
(
function
()
{
$
(
'#keep-shopping'
).
click
(
function
()
{
$
(
'#type-chose'
).
slideDown
(
SLIDETIME
);
$
(
'#balance'
).
slideUp
(
SLIDETIME
);
});
// 立即购买
$
(
'#buy-now'
).
click
(
function
()
{
$
(
'#buy-now'
).
click
(
function
()
{
var
sku
,
base
,
myAlert
;
...
...
@@ -409,18 +409,18 @@ $('#buy-now').click(function() {
});
// 按钮鼠标移入效果【dis状态的按钮状态不变】
$
(
'.buy-btn'
).
mouseover
(
function
()
{
$
(
'.buy-btn'
).
mouseover
(
function
()
{
if
(
$
(
this
).
hasClass
(
'dis'
))
{
return
;
}
$
(
this
).
addClass
(
'hover'
);
}).
mouseleave
(
function
()
{
}).
mouseleave
(
function
()
{
$
(
this
).
removeClass
(
'hover'
);
});
// 商品详情/材质洗涤切换
$
(
'.description-material'
).
on
(
'click'
,
'.title'
,
function
()
{
$
(
'.description-material'
).
on
(
'click'
,
'.title'
,
function
()
{
var
$this
=
$
(
this
),
index
=
$this
.
index
();
...
...
@@ -446,7 +446,7 @@ $('.description-material').on('click', '.title', function() {
});
// 售后服务
$
(
'.after-service-switch'
).
click
(
function
()
{
$
(
'.after-service-switch'
).
click
(
function
()
{
var
$this
=
$
(
this
),
$content
=
$this
.
next
(
'.after-service-content'
);
...
...
@@ -474,18 +474,18 @@ $.ajax({
data
:
{
productId
:
id
}
}).
then
(
function
(
html
)
{
}).
then
(
function
(
html
)
{
$
(
'#details-html'
).
prepend
(
html
);
// 修正热区尺寸使居中
$
(
'.hot-point-wrap > img'
).
load
(
function
()
{
$
(
'.hot-point-wrap > img'
).
load
(
function
()
{
$
(
this
).
parent
(
'.hot-point-wrap'
).
width
(
$
(
this
).
width
());
});
// Bind Hover event
$
(
'.hot-point'
).
hover
(
function
()
{
$
(
'.hot-point'
).
hover
(
function
()
{
$
(
this
).
addClass
(
'hover'
);
},
function
()
{
},
function
()
{
$
(
this
).
removeClass
(
'hover'
);
});
});
...
...
@@ -494,7 +494,7 @@ $.ajax({
lazyLoad
(
$
(
'#details-html img'
));
// 只有一个尺码(多个或一个颜色)时默认选中第一个未售罄的颜色的第一个尺码
(
function
()
{
(
function
()
{
var
hasOnlyOneSize
=
true
,
i
;
...
...
@@ -511,7 +511,7 @@ lazyLoad($('#details-html img'));
}());
// 咨询和评价
(
function
()
{
(
function
()
{
var
commentPage
=
1
,
consultPage
=
1
;
...
...
@@ -541,7 +541,7 @@ lazyLoad($('#details-html img'));
productId
:
id
,
page
:
commentPage
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
var
res
;
if
(
data
.
code
===
200
)
{
...
...
@@ -560,7 +560,7 @@ lazyLoad($('#details-html img'));
}));
commentPage
++
;
}
}).
always
(
function
()
{
}).
always
(
function
()
{
loadingComments
=
false
;
});
}
...
...
@@ -580,7 +580,7 @@ lazyLoad($('#details-html img'));
productId
:
id
,
page
:
consultPage
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
var
res
;
if
(
data
.
code
===
200
)
{
...
...
@@ -599,13 +599,13 @@ lazyLoad($('#details-html img'));
}));
consultPage
++
;
}
}).
always
(
function
()
{
}).
always
(
function
()
{
loadingConsults
=
false
;
});
}
// 评价和咨询切换
$
(
'.consult-comment'
).
on
(
'click'
,
'.title'
,
function
()
{
$
(
'.consult-comment'
).
on
(
'click'
,
'.title'
,
function
()
{
var
$this
=
$
(
this
),
index
=
$this
.
index
();
...
...
@@ -628,7 +628,7 @@ lazyLoad($('#details-html img'));
$consults
.
slideUp
(
SLIDETIME
);
$comments
.
slideDown
(
SLIDETIME
);
}
}).
on
(
'click'
,
'.load-more'
,
function
()
{
}).
on
(
'click'
,
'.load-more'
,
function
()
{
var
$this
=
$
(
this
);
if
(
$this
.
hasClass
(
'load-more-comments'
))
{
...
...
@@ -639,7 +639,7 @@ lazyLoad($('#details-html img'));
});
// 我要咨询
$
(
'#consults-btn'
).
click
(
function
()
{
$
(
'#consults-btn'
).
click
(
function
()
{
// TODO:点击我要资讯的时候更新验证码显示
$
(
'.new-consult'
).
removeClass
(
'hide'
);
...
...
@@ -647,7 +647,7 @@ lazyLoad($('#details-html img'));
});
// 提交咨询
$
(
'#submit-consult'
).
click
(
function
()
{
$
(
'#submit-consult'
).
click
(
function
()
{
var
$this
=
$
(
this
),
$parent
=
$this
.
closest
(
'.new-consult'
),
$textarea
=
$parent
.
find
(
'.my-consult'
),
...
...
@@ -678,7 +678,7 @@ lazyLoad($('#details-html img'));
productId
:
id
,
content
:
content
}
}).
then
(
function
(
data
)
{
}).
then
(
function
(
data
)
{
var
code
=
data
.
code
;
if
(
code
===
200
)
{
...
...
Please
register
or
login
to post a comment