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
Email Patches
Plain Diff
Browse Files
Authored by
姜枫
9 years ago
Commit
d9791b733a86b6eb9bae0fb0d6fb06b4be3e9e76
1 parent
7a7c6161
add shop&brand collect
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
149 additions
and
16 deletions
apps/product/controllers/favorite.js
apps/product/controllers/shop.js
apps/product/models/brand-service.js
apps/product/models/favorite-api.js
apps/product/models/favorite.js
apps/product/models/shop-service.js
apps/product/router.js
apps/product/views/partial/brand-banner-list.hbs
config/common.js
public/js/product/list.page.js
public/js/product/list/favorite.js
public/js/product/shop-list.page.js
public/js/product/shop.page.js
public/scss/product/_brand-banner.css
public/scss/product/_shop.css
apps/product/controllers/favorite.js
View file @
d9791b7
...
...
@@ -37,6 +37,66 @@ const product = (req, res, next) => {
res
.
json
(
resData
);
};
const
brand
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
pid
=
req
.
body
.
brandId
;
let
type
=
(
req
.
body
.
type
===
'add'
);
let
resData
=
{
code
:
400
,
message
:
'操作失败'
};
if
(
uid
)
{
if
(
pid
)
{
fav
.
toggleFavBrand
(
pid
,
uid
,
type
).
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
return
;
}
}
else
{
Object
.
assign
(
resData
,
{
code
:
403
,
message
:
'请登录后执行该操作'
,
data
:
{
refer
:
helpers
.
urlFormat
(
'/signin'
)
}
});
}
res
.
json
(
resData
);
};
const
shop
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
pid
=
req
.
body
.
shopId
;
let
type
=
(
req
.
body
.
type
===
'add'
);
let
resData
=
{
code
:
400
,
message
:
'操作失败'
};
if
(
uid
)
{
if
(
pid
)
{
fav
.
toggleFavShop
(
pid
,
uid
,
type
).
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
return
;
}
}
else
{
Object
.
assign
(
resData
,
{
code
:
403
,
message
:
'请登录后执行该操作'
,
data
:
{
refer
:
helpers
.
urlFormat
(
'/signin'
)
}
});
}
res
.
json
(
resData
);
};
module
.
exports
=
{
product
// 组件demo页
product
,
brand
,
shop
};
...
...
apps/product/controllers/shop.js
View file @
d9791b7
...
...
@@ -60,7 +60,6 @@ const shop = {
q
.
page
=
parseInt
(
q
.
page
||
1
,
10
);
ShopData
.
getShopHeadData
(
domain
,
uid
).
then
(
result
=>
{
data
.
banner
=
result
;
if
(
data
.
banner
.
banner
)
{
...
...
apps/product/models/brand-service.js
View file @
d9791b7
...
...
@@ -19,9 +19,9 @@ const getDomainInfo = domain => {
})();
};
const
getBrandInfo
=
bid
=>
{
const
getBrandInfo
=
(
bid
,
uid
)
=>
{
return
co
(
function
*
()
{
let
brandInfo
=
yield
api
.
getBrandInfo
(
bid
);
let
brandInfo
=
yield
api
.
getBrandInfo
(
bid
,
uid
);
if
(
!
brandInfo
.
data
||
brandInfo
.
code
!==
200
)
{
return
{};
...
...
apps/product/models/favorite-api.js
View file @
d9791b7
...
...
@@ -8,21 +8,21 @@
const
api
=
global
.
yoho
.
API
;
const
addFavAsync
=
(
uid
,
pid
)
=>
{
const
addFavAsync
=
(
uid
,
id
,
type
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.favorite.add'
,
id
:
p
id
,
id
:
id
,
uid
:
uid
,
type
:
'product'
type
:
type
});
};
const
cancelFavAsync
=
(
uid
,
pid
)
=>
{
const
cancelFavAsync
=
(
uid
,
id
,
type
)
=>
{
return
api
.
get
(
''
,
{
method
:
'app.favorite.cancel'
,
fav_id
:
p
id
,
fav_id
:
id
,
uid
:
uid
,
type
:
'product'
type
:
type
});
};
...
...
apps/product/models/favorite.js
View file @
d9791b7
...
...
@@ -10,13 +10,31 @@ const FavAPI = require('./favorite-api');
const
toggleFavProduct
=
(
productId
,
uid
,
isadd
)
=>
{
if
(
isadd
)
{
return
FavAPI
.
addFavAsync
(
uid
,
productId
);
return
FavAPI
.
addFavAsync
(
uid
,
productId
,
'product'
);
}
else
{
return
FavAPI
.
cancelFavAsync
(
uid
,
productId
);
return
FavAPI
.
cancelFavAsync
(
uid
,
productId
,
'product'
);
}
};
const
toggleFavBrand
=
(
brandId
,
uid
,
isadd
)
=>
{
if
(
isadd
)
{
return
FavAPI
.
addFavAsync
(
uid
,
brandId
,
'brand'
);
}
else
{
return
FavAPI
.
cancelFavAsync
(
uid
,
brandId
,
'brand'
);
}
};
const
toggleFavShop
=
(
shopId
,
uid
,
isadd
)
=>
{
if
(
isadd
)
{
return
FavAPI
.
addFavAsync
(
uid
,
shopId
,
'shop'
);
}
else
{
return
FavAPI
.
cancelFavAsync
(
uid
,
shopId
,
'shop'
);
}
};
module
.
exports
=
{
toggleFavProduct
toggleFavProduct
,
toggleFavBrand
,
toggleFavShop
};
...
...
apps/product/models/shop-service.js
View file @
d9791b7
...
...
@@ -122,6 +122,8 @@ const ShopService = {
let
brandId
=
domainInfo
.
id
;
let
brandInfo
=
yield
BrandService
.
getBrandInfo
(
brandId
,
uid
);
console
.
log
(
brandInfo
);
info
.
name
=
brandInfo
.
brandName
;
info
.
info
=
brandInfo
.
brandIntro
;
info
.
btnName
=
'品牌介绍'
;
...
...
apps/product/router.js
View file @
d9791b7
...
...
@@ -23,6 +23,8 @@ router.post('/item/togglecollect', fav.product); // 商品详情页
router
.
get
(
'/shop/:domain/list'
,
shop
.
list
);
router
.
get
(
'/shop/:domain'
,
shop
.
index
);
router
.
post
(
'/shop/togglecollect'
,
fav
.
shop
);
router
.
post
(
'/brand/togglecollect'
,
fav
.
brand
);
router
.
get
(
'/query'
,
query
.
index
);
...
...
apps/product/views/partial/brand-banner-list.hbs
View file @
d9791b7
{{#
banner
}}
<div
class=
"brand-banner"
>
<div
class=
"brand-banner"
data-brand=
"
{{
brandId
}}
"
data-shop=
"
{{
shopId
}}
"
>
<div
class=
"brand-img"
style=
"height:150px; background: url('
{{
image
banner
1150
150
}}
')"
></div>
<p
class=
"opts"
>
<a
id=
"brand-info"
>
...
...
config/common.js
View file @
d9791b7
...
...
@@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain
:
'yohoblk.com'
,
domains
:
{
api
:
'http://
testapi.yoho.cn:28078
/'
,
// devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api
:
'http://
api.yoho.cn
/'
,
// devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service
:
'http://testservice.yoho.cn:28077/'
,
// testservice.yoho.cn:28077 devservice.yoho.cn:58077
search
:
'http://192.168.102.216:8080/yohosearch/'
},
...
...
public/js/product/list.page.js
View file @
d9791b7
require
(
'./list/list-search'
);
require
(
'./list/favorite'
);
...
...
public/js/product/list/favorite.js
0 → 100644
View file @
d9791b7
/**
* 品牌或店铺收藏
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/19
*/
function
_favBack
(
data
)
{
if
(
data
&&
data
.
code
===
200
)
{
$
(
'#brand-fav'
).
toggleClass
(
'coled'
);
}
}
function
_favShop
(
shopId
,
isAdd
)
{
$
.
post
(
'/product/shop/togglecollect'
,
{
shopId
:
shopId
,
type
:
isAdd
?
''
:
'add'
},
function
(
data
)
{
_favBack
(
data
);
});
}
function
_favBrand
(
brandId
,
isAdd
)
{
$
.
post
(
'/product/brand/togglecollect'
,
{
brandId
:
brandId
,
type
:
isAdd
?
''
:
'add'
},
function
(
data
)
{
_favBack
(
data
);
});
}
$
(
'#brand-fav'
).
click
(
function
()
{
var
shopId
=
$
(
this
).
parents
(
'.brand-banner'
).
data
(
'shop'
);
var
brandId
=
$
(
this
).
parents
(
'.brand-banner'
).
data
(
'brand'
);
var
isAdd
=
$
(
this
).
hasClass
(
'coled'
);
if
(
shopId
)
{
_favShop
(
shopId
,
isAdd
);
}
else
if
(
brandId
)
{
_favBrand
(
brandId
,
isAdd
);
}
});
...
...
public/js/product/shop-list.page.js
View file @
d9791b7
...
...
@@ -8,7 +8,7 @@ var Dialog = require('../plugins/dialog').Dialog;
var
Shop
=
{
init
:
function
()
{
require
(
'./list/list-search'
);
require
(
'./list/favorite'
);
$
(
'#brand-info'
).
click
(
function
()
{
Shop
.
brandInfoDialog
().
show
();
...
...
public/js/product/shop.page.js
View file @
d9791b7
var
lazyload
=
require
(
'yoho-jquery-lazyload'
);
lazyload
();
require
(
'./list/favorite'
);
...
...
public/scss/product/_brand-banner.css
View file @
d9791b7
...
...
@@ -28,6 +28,14 @@
display
:
inline-block
;
}
.brand-info
{
cursor
:
pointer
;
}
.brand-fav
{
cursor
:
pointer
;
}
.iconfont
{
font-size
:
12px
;
}
...
...
public/scss/product/_shop.css
View file @
d9791b7
...
...
@@ -20,11 +20,17 @@
border
:
1px
solid
#fff
;
padding
:
10px
;
margin-left
:
10px
;
cursor
:
pointer
;
.iconfont
{
font-size
:
14px
;
}
}
.brand-fav.coled
.iconfont
{
color
:
#000
;
}
}
}
...
...
Please
register
or
login
to post a comment