DetailContainer.js 8.17 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);

    }

    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();
    }

    componentWillUnmount() {

    }

    _onSubmitForComment(content,replyTo){
        this.props.actions.addCommentsForArtivle(content,replyTo);
    }

    _onPressConcerns(isFav){
        if (isFav == 'N') {
            this.props.actions.addFavorite();
        }else {
            this.props.actions.cancelFavorite();
        }
    }

    _addPraiseForArtivle(isPraise){
        if (isPraise == 'N') {
            this.props.actions.praiseForArtivle();
        }else {
            this.props.actions.cancelPraiseForArtivle();
        }
    }

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

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

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

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

    _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) {
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

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

    _onPressTag(url) {
        let taggedUrl = urlAddParamOfType(url, '12')
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(taggedUrl);
    }
    _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);
        if (!productSkn) {
            return;
        }

        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_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) {
        if (!product_skn) {
            return;
        }

        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_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) {
        let param = {
            pruduct_skn: product_skn,
            fromPage: 'YH_GuangDetailViewController',
            pos_id: pos_id,
        }
        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}
                />
            </View>
        );
    }
}

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

});

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