Authored by chenl

增加了赞的点击事件。review by 于良。

... ... @@ -36,6 +36,7 @@ import {
import {
setBrandId,
setUdid,
} from './reducers/detail/detailActions';
function getInitialState() {
... ... @@ -101,7 +102,9 @@ export default function native(platform) {
);
} else {
let brandId=this.props.id;
let udid=this.props.udid;
store.dispatch(setBrandId(brandId));
store.dispatch(setUdid(udid));
return (
<Provider store={store}>
<DetailContainer />
... ...
... ... @@ -32,8 +32,10 @@ export default class BrandArticleCell extends Component {
}
//内容
_renderTimeAndVisit(time, visit, likeNum, isliked){
//时间和访问次数以及是否喜欢
_renderTimeAndVisit(time, visit, likeNum, id, isliked){
let likeicon = isliked ? require("../../images/like_on.png") : require("../../images/like_off.png");
return (
<View style={styles.timebar}>
... ... @@ -41,7 +43,15 @@ export default class BrandArticleCell extends Component {
<Text style={styles.time} numberOfLines={1}>{visit}&nbsp;&nbsp;&nbsp;&nbsp;</Text>
<Text style={styles.time} numberOfLines={1}>{likeNum}</Text>
<TouchableOpacity
activeOpacity={1}
onPress={()=>{
this.props.onPressArticleLike && this.props.onPressArticleLike(id, !isliked)
}}>
<Image style={styles.likeicon} source={likeicon} />
<Text style={styles.time} numberOfLines={1}>{likeNum}</Text>
</TouchableOpacity>
</View>
... ... @@ -52,11 +62,16 @@ export default class BrandArticleCell extends Component {
render() {
let {rowData} = this.props;
//url跳转地址
let url = rowData.get('url');
//id
let id = rowData.get('id');
//标题
let title = rowData.get('title');
//图片
let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', 290).replace('{height}', 386);
//imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), 290, 386, 2);
//let brandIconUrl = SlicedImage.getSlicedUrl(data.get('brand_img', ''), 150, 80, 2);
//介绍
let intro = rowData.get('intro');
//发布时间
... ... @@ -70,10 +85,6 @@ export default class BrandArticleCell extends Component {
//喜欢人数
let likeCount = like.get("count");
//console.log("chenlin444", JSON.stringify(rowData));
//console.log("chenlin444", "isLiked" + isLiked + "----likeCount" + likeCount);
return (
<View style={styles.cellContainer}>
... ... @@ -81,7 +92,7 @@ export default class BrandArticleCell extends Component {
style={[styles.touchableContainer]}
activeOpacity={1}
onPress={()=>{
this.props.onPressTopic && this.props.onPressTopic()
this.props.onPressArticle && this.props.onPressArticle(url)
}}>
<Image style={styles.image} source={{uri:imgUrl}} />
... ... @@ -92,7 +103,7 @@ export default class BrandArticleCell extends Component {
<Text style={styles.content} numberOfLines={4}>{intro}</Text>
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, isLiked)}
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, isLiked)}
</View>
... ... @@ -141,7 +152,11 @@ let styles = StyleSheet.create({
paddingBottom:5,
},
time:{
fontSize: 9,
fontSize: 15,
color: '#b0b0b0',
},
likeicon:{
width: 20,
height:20,
},
});
... ...
... ... @@ -47,7 +47,8 @@ export default class BrandArticleList extends Component {
key={'row' + rowID}
rowID={rowID}
rowData={rowData}
// onPressProduct={this.props.onPressProduct}
onPressArticle={this.props.onPressArticle}
onPressArticleLike={this.props.onPressArticleLike}
/>
);
... ... @@ -71,6 +72,8 @@ export default class BrandArticleList extends Component {
renderRow={this._renderRow}
enableEmptySections = {true}
renderSeparator={this._renderSeparator}
onPressArticle={this.props.onPressArticle}
onPressArticleLike={this.props.onPressArticleLike}
//renderHeader={this._renderHeader}
/>
... ...
... ... @@ -7,6 +7,7 @@ export default keyMirror({
SET_SEGMENT: null,
SET_GENDER: null,
SET_BRAND_ID:null,
SET_UDID:null,
PLUSTAR_LIST_REQUEST: null,
PLUSTAR_LIST_SUCCESS: null,
... ... @@ -44,4 +45,8 @@ export default keyMirror({
CANCEL_FAVORITE_REQUEST: null,
CANCEL_FAVORITE_SUCCESS: null,
CANCEL_FAVORITE_FAILURE: null,
PRAISE_ARTICLE_REQUEST: null,
PRAISE_ARTICLE_SUCCESS: null,
PRAISE_ARTICLE_FAILURE: null,
});
... ...
... ... @@ -49,6 +49,8 @@ class DetailContainer extends Component {
}
constructor(props) {
super(props);
this._onPressArticle = this._onPressArticle.bind(this);
this._onPressArticleLike = this._onPressArticleLike.bind(this);
}
componentDidMount() {
... ... @@ -58,6 +60,17 @@ class DetailContainer extends Component {
this.props.actions.articleByBrand();
}
_onPressArticle(url) {
console.log("chenlin", "_onPressArticle:URL:" + url);
}
_onPressArticleLike(id, isLiked) {
console.log("chenlin", "_onPressArticleLike:id" + id + ",isLiked:" + isLiked);
let opt = isLiked ? "ok" : "cancel";
this.props.actions.praiseArticle(id,opt);
}
render() {
let {detail} = this.props;
//console.log("chenlin", JSON.stringify(detail));
... ... @@ -66,9 +79,12 @@ class DetailContainer extends Component {
<BrandIntro
brandIntro={detail.get('brandInfo')}
/>
<BrandArticleList
articleList={detail.get('articleList')} />
articleList={detail.get('articleList')}
onPressArticle={this._onPressArticle}
onPressArticleLike={this._onPressArticleLike} />
</View>
);
}
... ...
... ... @@ -13,6 +13,7 @@ const {
SET_BRAND_ID,
SET_GENDER,
SET_UDID,
BRADN_FAV_REQUEST,
BRADN_FAV_SUCCESS,
... ... @@ -35,6 +36,10 @@ const {
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
PRAISE_ARTICLE_REQUEST,
PRAISE_ARTICLE_SUCCESS,
PRAISE_ARTICLE_FAILURE,
} = require('../../constants/actionTypes').default;
export function jumpWithUrl(url) {
... ... @@ -125,6 +130,13 @@ export function setGender(gender) {
};
}
export function setUdid(udid){
return {
type: SET_UDID,
payload:udid
};
}
export function uidBrandFavRequest(){
return {
type: BRADN_FAV_REQUEST,
... ... @@ -358,3 +370,47 @@ export function cancelFavorite() {
});
};
}
export function praiseArticleRequest(){
return {
type: PRAISE_ARTICLE_REQUEST,
};
}
export function praiseArticleSuccess(json){
return {
type: PRAISE_ARTICLE_SUCCESS,
payload:json
};
}
export function praiseArticleFailure(error){
return {
type: PRAISE_ARTICLE_FAILURE,
payload:error
};
}
export function praiseArticle(articleId, opt) {
return (dispatch, getState) => {
let {app, detail} = getState();
let {udid} = detail;
console.log("chenlin", "getState:" + JSON.stringify(getState()));
let articleRequest = (articleId, udid, opt) => {
dispatch(praiseArticleRequest());
return new DetailService(app.servicehost).praiseArticle(articleId, udid, opt)
.then(json=>{
dispatch(praiseArticleSuccess(json));
})
.catch(error=>{
dispatch(praiseArticleFailure(error));
});
}
articleRequest(articleId, udid, opt);
};
}
... ...
... ... @@ -10,6 +10,7 @@ let InitialState = Record({
error: null,
})),
brandId:'',
udid:'',
gender:'',
productList: List(),
articleList: List(),
... ...
... ... @@ -11,6 +11,7 @@ const {
JUMP_WITH_URL,
SET_BRAND_ID,
SET_GENDER,
SET_UDID,
BRADN_FAV_REQUEST,
BRADN_FAV_SUCCESS,
... ... @@ -31,6 +32,11 @@ const {
CANCEL_FAVORITE_REQUEST,
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
PRAISE_ARTICLE_REQUEST,
PRAISE_ARTICLE_SUCCESS,
PRAISE_ARTICLE_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -53,12 +59,21 @@ export default function plustarReducer(state=initialState, action) {
case SET_BRAND_ID:{
return state.set('brandId', action.payload);
}
case SET_UDID:{
return state.set('udid', action.payload);
}
case NEW_ARRIVE_SUCCESS:{
return state.set('productList', Immutable.fromJS(action.payload));
}
case ARTICLE_BY_BRAND_SUCCESS:{
return state.set('articleList', Immutable.fromJS(action.payload));
}
case PRAISE_ARTICLE_SUCCESS:{
console.log("chenlin", "PRAISE_ARTICLE_SUCCESS:" + JSON.stringify(action.payload));
}
case PRAISE_ARTICLE_FAILURE:{
console.log("chenlin", "PRAISE_ARTICLE_FAILURE:" + JSON.stringify(action.payload));
}
}
return state;
... ...
... ... @@ -66,15 +66,20 @@ export default class DetailService {
});
}
async getArticleByBrand(brandId,uid) {
async getArticleByBrand(brandId,uid,udid) {
return await this.api.get({
url: '/guang/service/v1/article/getArticleByBrand',
body: {
brand_id: brandId,
uid: uid,
udid: udid,
// client_type: clientType,
// limit: 3,
// private_key: privateKeyList[clientType],
}
})
.then((json) => {
return json;
})
.catch((error) => {
... ... @@ -116,5 +121,24 @@ export default class DetailService {
throw(error);
});
}
//点赞,opt:ok表示点赞,cancel表示取消点赞
async praiseArticle(id, udid, opt='ok') {
return await this.api.post({
url: '/guang/opt/praiseArticle',
body: {
id: id,
udid: udid,
opt: opt
}
})
.then((json) => {
console.log("chenlin", "点赞返回数据:" + JSON.stringify(json));
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...