DetailContainer.js 10.8 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    NativeModules,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as detailActions from '../reducers/detail/detailActions';

import Detail from '../components/detail/Detail';
import {urlAddParamOfType} from '../../common/utils/urlHandler';

const actions = [
    detailActions,
];

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {

    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    };
}

class DetailContainer extends Component {
    constructor(props) {
        super(props);

        this._onPressFilter = this._onPressFilter.bind(this);
        this._onPressAuthor = this._onPressAuthor.bind(this);
        this._onPressMoreLink = this._onPressMoreLink.bind(this);
        this._onPressProduct = this._onPressProduct.bind(this);
        this._onPressWeixin = this._onPressWeixin.bind(this);
        this._onPressGoodY = this._onPressGoodY.bind(this);
        this._onPressLink = this._onPressLink.bind(this);
        this._onPressTag = this._onPressTag.bind(this);
        this._onPressBrand = this._onPressBrand.bind(this);
        this._onPressArticle = this._onPressArticle.bind(this);
        this._onPressShopCar = this._onPressShopCar.bind(this);
        this._onPressTagProduct = this._onPressTagProduct.bind(this);
        this._onPressConcerns = this._onPressConcerns.bind(this);
        this._onSubmitForComment = this._onSubmitForComment.bind(this);
        this._addPraiseForArtivle = this._addPraiseForArtivle.bind(this);
        this._addPraiseForComments = this._addPraiseForComments.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
    }

    componentDidMount() {
        this.props.actions.getArticle();
        this.props.actions.getArticleContent();
        this.props.actions.getBrand();
        this.props.actions.getWeixinPublic();
        this.props.actions.getWeChatAtten();
        this.props.actions.getCommentsList();
        this.props.actions.getPraiseForArtivle();

        NativeModules.YH_CommonHelper.logEvent('YB_STROLL_CONT', {});
    }

    componentWillUnmount() {

    }

    _onSubmitForComment(content,replyTo){
        this.props.actions.addCommentsForArtivle(content,replyTo);
        if (replyTo) {
            let articleId = this.props.detail.get('articleId');
            let params = {
                ID:  articleId,
                COMMENT_UID: replyTo,
            };
            NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_REPLY_C', params);
        } else {
            let articleId = this.props.detail.get('articleId');
            let params = {
                ID:  articleId,
            };
            NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_COMMENT_C', params);
        }
    }

    _onPressConcerns(isFav){
        if (isFav == 'Y') {
            this.props.actions.addFavorite();

            let articleId = this.props.detail.get('articleId');
            let params = {
                ID:  articleId,
            };
            NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_FAV_ART_C', params);
        }else {
            this.props.actions.cancelFavorite();
        }
    }

    _onEndReached() {
        this.props.actions.getCommentsList();
    }

    _addPraiseForArtivle(isPraise){
        if (isPraise == 'Y') {
            this.props.actions.praiseForArtivle();

            let articleId = this.props.detail.get('articleId');
            let params = {
                ID:  articleId,
            };
            NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_ART_LIKE_C', params);
        }else {
            this.props.actions.cancelPraiseForArtivle();
        }
    }

    _addPraiseForComments(comment_id,praise, uid){
        this.props.actions.setPraiseForComments(comment_id,praise);
        this.props.actions.addPraiseForComments(comment_id,praise);

        if (praise == 'Y') {
            let articleId = this.props.detail.get('articleId');
            let params = {
                ID:  articleId,
                COMMENT_UID: uid,
            };
            NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_USER_LIKE_C', params);
        }
    }

    _onPressFilter(value) {
        this.props.actions.setGoodsGroupFilter(value);
    }

    _onPressGoodY(y) {
        this.props.actions.setGoodsGroupY(y);
    }

    _onPressAuthor(url, author_id, id) {
        let authorUrl = urlAddParamOfType(url, '11')
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(authorUrl);

        let params = {
            ID: id + '' ,
            UID: author_id,
        };
        NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_HEAD_C', params);
    }

    _onPressBrand(url,rowID,id) {
        let {detail} = this.props;
        let {articleId} = detail;

        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        try {
            let params = {
                TOURL: url,
                NAV_NUM: parseInt(rowID) + 1 + '',
                CONTENT_ID: articleId,
                BRAND_ID: id,
            };
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_STROLL_CONT_BRND', params);
        } catch (e) {
            console.log(e);
        }
    }

    _onPressArticle(url, id) {
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);

        let articleId = this.props.detail.get('articleId');
        let params = {
            ID:  articleId,
            R_ART_ID: id + '',
        };
        NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_R_ART_C', params);
    }

    _onPressLink(url) {
        ReactNative.NativeModules.YH_CommonHelper.goLinkUrl(url);
    }

    _onPressTag(value) {

        let url = value.url;
        let taggedUrl = urlAddParamOfType(url, '12')
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(taggedUrl);

        let articleId = this.props.detail.get('articleId');
        let params = {
            ID:  articleId,
            LABEL_NAME: value.name,
        };
        NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_LABEL_C', params);
    }
    _onPressMoreLink(url) {
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    _onPressWeixin(data) {
        ReactNative.NativeModules.YH_CommonHelper.copyWechatIdToClipboard(data);

        try {
            let params = {
                IS_FROM: 2,
            };
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_COPY_WECHAT_PN_C', params);
        } catch (e) {
            console.log(e);
        }

    }

    _onPressProduct(product,rowID,pos_id) {

        let {detail} = this.props;
        let {articleId} = detail;

        let productSkn = product && product.get('product_skn', 0);
        let is_global = product && product.get('is_global', 'N');

        if (!productSkn) {
            return;
        }

        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`;

        if (is_global == 'Y') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalpurchase","params":{"skn":"${productSkn}"}}`;
        }

        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);

        try {
            let params = {
                TOURL: '',
                PRD_SKN: productSkn,
                CONTENT_ID: articleId,
                NAV_NUM:parseInt(rowID) + 1 + '',
                POS_ID:pos_id,
            };
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_STROLL_CONT_REC_PRD', params);
        } catch (e) {
            console.log(e);
        }
    }

    _onPressTagProduct(product_skn,rowID,pos_id,is_global) {
        if (!product_skn) {
            return;
        }
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${product_skn}"}}`;

        if (is_global == 'Y') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalpurchase","params":{"skn":"${product_skn}"}}`;
        }

        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);

        try {
            let {detail} = this.props;
            let {articleId} = detail;
            let params = {
                TOURL: '',
                PRD_SKN: product_skn,
                CONTENT_ID: articleId,
                NAV_NUM:parseInt(rowID) + 1 + '',
                POS_ID:pos_id,
            };
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_STROLL_CONT_REC_PRD', params);
        } catch (e) {
            console.log(e);
        }
    }

    _onPressShopCar(product_skn,prd_id,pos_id,isGlobal) {
        let param = {
            pruduct_skn: product_skn,
            fromPage: 'YH_GuangDetailViewController',
            pos_id: pos_id,
            isGlobal: isGlobal,
        }
        ReactNative.NativeModules.YH_CommonHelper.showChooseInfoView(param)

        try {
            let params = {
                PRD_ID: prd_id,
                PRD_SKN: product_skn,
                POS_ID:pos_id,
            };
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_GDS_DT_ADD_CART_C', params);
        } catch (e) {
            console.log(e);
        }
    }

    render() {
        let {detail} = this.props;

        return (
            <View style={styles.container}>
                <Detail
                    resource={detail}
                    onPressFilter= {this._onPressFilter}
                    onPressAuthor={this._onPressAuthor}
                    onPressMoreLink={this._onPressMoreLink}
                    onPressProduct={this._onPressProduct}
                    onPressWeixin={this._onPressWeixin}
                    onPressGoodY={this._onPressGoodY}
                    onPressLink={this._onPressLink}
                    onPressTag={this._onPressTag}
                    onPressBrand={this._onPressBrand}
                    onPressArticle={this._onPressArticle}
                    onPressShopCar={this._onPressShopCar}
                    onPressTagProduct={this._onPressTagProduct}
                    onPressConcerns={this._onPressConcerns}
                    onSubmitForComment={this._onSubmitForComment}
                    addPraiseForArtivle={this._addPraiseForArtivle}
                    addPraiseForComments={this._addPraiseForComments}
                    onEndReached={this._onEndReached}

                />
            </View>
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

export default connect(mapStateToProps, mapDispatchToProps)(DetailContainer);