Toggle navigation
Toggle navigation
This project
Loading...
Sign in
mobile
/
YH_RNComponent
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
yoho-js001
8 years ago
Commit
cbb5a02e0552113401c274f34e4751ec92620219
1 parent
68145fbc
Add or cancel favorite for good goods recommend detai. reviewed by YinCheng.
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
118 additions
and
29 deletions
js/blk/components/brand/BLKBrandCell.js
js/goodGoodsRecommend/components/detail/Detail.js
js/goodGoodsRecommend/components/list/ListCell.js
js/goodGoodsRecommend/constants/actionTypes.js
js/goodGoodsRecommend/containers/DetailContainer.js
js/goodGoodsRecommend/image/love_tab_ic_h@2x.png
js/goodGoodsRecommend/image/love_tab_ic_h@3x.png
js/goodGoodsRecommend/reducers/detail/detailActions.js
js/goodGoodsRecommend/reducers/detail/detailInitialState.js
js/goodGoodsRecommend/reducers/detail/detailReducer.js
js/goodGoodsRecommend/services/DetailService.js
js/blk/components/brand/BLKBrandCell.js
View file @
cbb5a02
...
...
@@ -26,13 +26,7 @@ export default class BLKBrandCell extends React.Component {
});
}
shouldComponentUpdate
(
nextProps
){
if
(
Immutable
.
is
(
nextProps
.
resource
,
this
.
props
.
resource
))
{
return
false
;
}
else
{
return
true
;
}
}
_renderRow
(
rowData
,
sectionID
,
rowID
)
{
let
img
=
rowData
.
get
(
'brand_ico'
);
img
=
img
.
replace
(
'{width}'
,
cellWidth
*
2
).
replace
(
'{height}'
,
(
cellWidth
-
10
)
*
2
).
replace
(
'{mode}'
,
2
);
...
...
js/goodGoodsRecommend/components/detail/Detail.js
View file @
cbb5a02
...
...
@@ -94,7 +94,7 @@ export default class Detail extends Component {
}
render
()
{
let
{
product_skn
,
product
,
similarList
}
=
this
.
props
.
resource
;
let
{
product_skn
,
favorite
,
product
,
similarList
}
=
this
.
props
.
resource
;
let
isFetching
=
product
.
get
(
'isFetching'
)
||
similarList
.
get
(
'isFetching'
);
let
images
=
product
.
getIn
([
'data'
,
'goods_list'
,
0
,
'images_list'
]);
let
similar
=
similarList
&&
similarList
.
get
(
'data'
)
&&
similarList
.
get
(
'data'
).
toArray
().
length
?
similarList
.
get
(
'data'
).
toArray
():[];
...
...
@@ -106,10 +106,11 @@ export default class Detail extends Component {
'similar'
:
similar
,
};
//Test
product_skn
=
'51148345'
;
//
// //Test
// product_skn = '51148345';
// //
let
fav_image
=
favorite
?
require
(
'../../image/love_tab_ic_h.png'
):
require
(
'../../image/love_tab_ic.png'
);
let
fav_title
=
favorite
?
'已收藏'
:
'收藏'
;
return
(
<
View
style
=
{
styles
.
container
}
>
{
!
isFetching
?
...
...
@@ -122,10 +123,10 @@ export default class Detail extends Component {
renderRow
=
{
this
.
renderRow
}
/
>
<
View
style
=
{
styles
.
footer
}
>
<
TouchableOpacity
style
=
{
styles
.
favoriteButton
}
>
<
TouchableOpacity
style
=
{
styles
.
favoriteButton
}
onPress
=
{()
=>
{
this
.
props
.
onPressFavorite
&&
this
.
props
.
onPressFavorite
(
favorite
)}}
>
<
View
style
=
{{
flex
:
1
,
flexDirection
:
'row'
,
alignItems
:
'center'
}}
>
<
Image
style
=
{
styles
.
favIcon
}
source
=
{
require
(
'../../image/love_tab_ic.png'
)}
/
>
<
Text
style
=
{
styles
.
favText
}
>
已收藏
<
/Text
>
<
Image
style
=
{
styles
.
favIcon
}
source
=
{
fav_image
}
/
>
<
Text
style
=
{
styles
.
favText
}
>
{
fav_title
}
<
/Text
>
<
/View
>
<
/TouchableOpacity
>
<
View
style
=
{
styles
.
detailButton
}
>
...
...
js/goodGoodsRecommend/components/list/ListCell.js
0 → 100644
View file @
cbb5a02
js/goodGoodsRecommend/constants/actionTypes.js
View file @
cbb5a02
...
...
@@ -14,4 +14,6 @@ export default keyMirror({
GET_SIMILAR_REQUEST
:
null
,
GET_SIMILAR_SUCCESS
:
null
,
GET_SIMILAR_FAILURE
:
null
,
SET_FAVORITE_STATUS
:
null
,
});
...
...
js/goodGoodsRecommend/containers/DetailContainer.js
View file @
cbb5a02
...
...
@@ -47,6 +47,7 @@ class DetailContainer extends Component {
constructor
(
props
)
{
super
(
props
);
this
.
_onPressProduct
=
this
.
_onPressProduct
.
bind
(
this
);
this
.
_onPressFavorite
=
this
.
_onPressFavorite
.
bind
(
this
);
}
componentDidMount
()
{
...
...
@@ -68,12 +69,17 @@ class DetailContainer extends Component {
ReactNative
.
NativeModules
.
YH_CommonHelper
.
jumpWithUrl
(
url
);
}
_onPressFavorite
(
favorite
)
{
this
.
props
.
actions
.
changeFavoriteStatus
(
favorite
);
}
render
()
{
let
{
detail
}
=
this
.
props
;
return
(
<
Detail
resource
=
{
detail
}
onPressProduct
=
{
this
.
_onPressProduct
}
onPressFavorite
=
{
this
.
_onPressFavorite
}
/
>
);
}
...
...
js/goodGoodsRecommend/image/love_tab_ic_h@2x.png
0 → 100644
View file @
cbb5a02
1.37 KB
js/goodGoodsRecommend/image/love_tab_ic_h@3x.png
0 → 100644
View file @
cbb5a02
1.64 KB
js/goodGoodsRecommend/reducers/detail/detailActions.js
View file @
cbb5a02
...
...
@@ -2,8 +2,7 @@
import
ReactNative
from
'react-native'
;
import
DetailService
from
'../../services/DetailService'
;
import
helper
from
'../../../common/utils/helper'
;
import
Immutable
,
{
Map
}
from
'immutable'
;
const
{
SET_PRODUCT_SKN
,
...
...
@@ -14,6 +13,7 @@ const {
GET_SIMILAR_REQUEST
,
GET_SIMILAR_SUCCESS
,
GET_SIMILAR_FAILURE
,
SET_FAVORITE_STATUS
,
}
=
require
(
'../../constants/actionTypes'
).
default
;
export
function
setProductSKN
(
product_skn
)
{
...
...
@@ -33,9 +33,16 @@ export function getDetail() {
dispatch
(
getDetailRequest
());
return
new
DetailService
(
app
.
host
).
getDetailWithProductSKN
(
product_skn
)
.
then
(
json
=>
{
console
.
log
(
product_skn
);
console
.
log
(
json
);
// console.log(product_skn);
// console.log(json);
dispatch
(
getDetailSuccess
(
json
));
return
new
DetailService
(
'http://single.yoho.cn/favorite'
).
getFavoriteStatusWithProductID
(
json
.
product_id
)
.
then
(
json
=>
{
dispatch
(
setFavoriteStatus
(
json
));
})
.
catch
(
error
=>
{
dispatch
(
setFavoriteStatus
(
false
));
})
})
.
catch
(
error
=>
{
dispatch
(
getDetailFailure
(
error
));
...
...
@@ -43,6 +50,28 @@ export function getDetail() {
};
}
export
function
changeFavoriteStatus
(
favorite
)
{
return
(
dispatch
,
getState
)
=>
{
let
{
app
,
detail
}
=
getState
();
let
product_id
=
detail
.
get
(
'product'
).
get
(
'data'
).
get
(
'product_id'
);
if
(
product_id
&&
favorite
)
{
new
DetailService
(
app
.
host
).
cancelFavorite
(
product_id
);
}
if
(
product_id
&&
!
favorite
)
{
new
DetailService
(
app
.
host
).
addFavorite
(
product_id
);
}
dispatch
(
setFavoriteStatus
(
!
favorite
));
}
}
export
function
setFavoriteStatus
(
favorite
)
{
return
{
type
:
SET_FAVORITE_STATUS
,
payload
:
favorite
};
}
export
function
getDetailRequest
()
{
return
{
type
:
GET_DETAIL_REQUEST
,
...
...
@@ -73,8 +102,8 @@ export function getSimilar() {
dispatch
(
getSimilarRequest
());
return
new
DetailService
(
app
.
host
).
getSimilarListWithSKN
(
product_skn
)
.
then
(
json
=>
{
console
.
log
(
product_skn
);
console
.
log
(
json
);
// console.log(product_skn);
// console.log(json);
dispatch
(
getSimilarSuccess
(
json
.
product_list
));
})
.
catch
(
error
=>
{
...
...
js/goodGoodsRecommend/reducers/detail/detailInitialState.js
View file @
cbb5a02
...
...
@@ -4,6 +4,7 @@ import {Record, List, Map} from 'immutable';
let
InitialState
=
Record
({
product_skn
:
''
,
favorite
:
false
,
product
:
new
(
Record
({
isFetching
:
false
,
error
:
null
,
...
...
js/goodGoodsRecommend/reducers/detail/detailReducer.js
View file @
cbb5a02
...
...
@@ -12,12 +12,16 @@ const {
GET_SIMILAR_REQUEST
,
GET_SIMILAR_SUCCESS
,
GET_SIMILAR_FAILURE
,
SET_FAVORITE_STATUS
,
}
=
require
(
'../../constants/actionTypes'
).
default
;
const
initialState
=
new
InitialState
;
export
default
function
detailReducer
(
state
=
initialState
,
action
)
{
switch
(
action
.
type
)
{
case
SET_FAVORITE_STATUS
:
{
return
state
.
set
(
'favorite'
,
action
.
payload
);
}
case
SET_PRODUCT_SKN
:
{
return
state
.
set
(
'product_skn'
,
action
.
payload
);
}
...
...
js/goodGoodsRecommend/services/DetailService.js
View file @
cbb5a02
...
...
@@ -13,11 +13,11 @@ export default class DetailService {
}
async
getDetailWithProductSKN
(
product_skn
)
{
//test
product_skn
=
'51148345'
;
this
.
api
=
new
Request
(
'http://dev-api.yohops.com:9999'
);
//
// //test
// product_skn = '51148345';
// this.api = new Request('http://dev-api.yohops.com:9999');
// //
return
await
this
.
api
.
get
({
url
:
''
,
body
:
{
...
...
@@ -36,9 +36,9 @@ export default class DetailService {
async
getSimilarListWithSKN
(
product_skn
)
{
//test
product_skn
=
'51148345'
;
//
// //test
// product_skn = '51148345';
// //
return
await
this
.
api
.
get
({
url
:
''
,
...
...
@@ -56,4 +56,56 @@ export default class DetailService {
});
}
async
getFavoriteStatusWithProductID
(
id
)
{
return
await
this
.
api
.
get
({
url
:
''
,
body
:
{
method
:
'app.favorite.isFavoriteNew'
,
id
,
}
})
.
then
((
json
)
=>
{
return
json
;
})
.
catch
((
error
)
=>
{
throw
(
error
);
});
}
async
addFavorite
(
id
)
{
let
type
=
'product'
;
return
await
this
.
api
.
get
({
url
:
''
,
body
:
{
method
:
'app.favorite.add'
,
id
,
type
,
}
})
.
then
((
json
)
=>
{
return
json
;
})
.
catch
((
error
)
=>
{
throw
(
error
);
});
}
async
cancelFavorite
(
id
)
{
let
type
=
'product'
;
return
await
this
.
api
.
get
({
url
:
''
,
body
:
{
method
:
'app.favorite.cancel'
,
id
,
type
,
}
})
.
then
((
json
)
=>
{
return
json
;
})
.
catch
((
error
)
=>
{
throw
(
error
);
});
}
}
...
...
Please
register
or
login
to post a comment