MineContainer.js 13.6 KB
'use strict'

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

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as mineActions from '../reducers/mine/mineActions';
import MineList from '../components/mine/MineList';
const actions = [
    mineActions,
];
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 MineContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressItem = this._onPressItem.bind(this);
        this._onPressProductListProduct = this._onPressProductListProduct.bind(this);
        this._onMineCenterRefresh = this._onMineCenterRefresh.bind(this);
        this._onLongPressProduct = this._onLongPressProduct.bind(this);
        this._onPressFindSimilar = this._onPressFindSimilar.bind(this);

        this.subscription1 = NativeAppEventEmitter.addListener(
            'UserDidLoginEvent',
            (reminder) => {
                this.props.actions.loginInSuccess(reminder.uid);
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription2 = NativeAppEventEmitter.addListener(
            'UserDidLogoutEvent',
            (reminder) => {
                this.props.actions.loginOutSuccess();
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription3 = NativeAppEventEmitter.addListener(
            'ChannelDidChangeEvent',
            (reminder) => {
                this.props.actions.getProductListForMineCenter();
            }
        );

        this.subscription4 = NativeAppEventEmitter.addListener(
            'MineCenterResumeEvent',
            (reminder) => {
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription5 = NativeAppEventEmitter.addListener(
            'UserDidRegisterEvent',
            (reminder) => {
                this.props.actions.onMineCenterRefresh();
            }
        );
    }

    componentDidMount() {
        this.props.actions.getProductListForMineCenter();
        this.props.actions.onMineCenterRefresh();
        this.props.actions.getMineAllIcon();
        this.props.actions.setShowSimilarGuider(true);
    }

    componentWillUnmount() {
        this.subscription1 && this.subscription1.remove();
        this.subscription2 && this.subscription2.remove();
        this.subscription3 && this.subscription3.remove();
        this.subscription4 && this.subscription4.remove();
        this.subscription5 && this.subscription5.remove();
    }

    _onPressItem(viewId, data) {
        let url = "";
        let params = {};
        switch (viewId) {
            case 'mineSetting':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.setting","params":{}}`;
                break;
            case 'mineMessageHome':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.messagehome","params":{}}`;
                params = {
                    ENTER_SRC:1,
                };
                NativeModules.YH_CommonHelper.logEvent('YB_MY_MESS', params);
                break;
            case 'mineInfo':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineinfo","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_PERSONAL_INFO_C', params);
                break;
            case 'mineVip':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.vipInfo","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_VIP_C', params);
                break;
            case 'mineStudentHome':
                //学生认证
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.studenthome","params":{}}`;
                params = {
                    SRC_ID: 2,
                }
                NativeModules.YH_CommonHelper.logEvent('YB_MY_STU_IDENTIFY', params);
                break;
            case 'mineLogin':
                //登陆,直接return了,不需要再去调用跳转规则
                ReactNative.NativeModules.YH_CommonHelper.login();
                return;
            case 'mineFavProduct':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_FAVPRD', {});
                break;
            case 'mineFavBrand':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{"favType":"1"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_FAVBRND', {});
                break;
            case 'mineBrowseHis':
                //浏览记录
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.browserhistory","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_BROWSE', {});
                break;
            case 'mineCertification':
                //设置安全性
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.associatephone","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_GO_BIND_C', {});
                break;
            case 'mineAnnounce':
                //通知
                url = data;
                if (!url) {
                    return;
                }
                params = {
                    POS_ID: 1,
                }
                NativeModules.YH_CommonHelper.logEvent('YB_MY_NOTICE_C', params);
                break;
            case 'mineOrder':
                //我的订单
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"0"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_ORD', {});
                break;
            case 'dfkOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"1"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTPAY', {});
                break;
            case 'dfhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"2"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTOUT', {});
                break;
            case 'dshOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"3"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTREV', {});
                break;
            case 'dsdOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.showgoods","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTAPP', {});
                break;
            case 'thhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.orderService","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_RETURN', {});
                break;
            case 'mineCoupon':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.coupon","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_COUP', {});
                break;
            case 'mineYohoCoin':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.yohocoin","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_YOHO', {});
                break;
            case 'mineLimitCode':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minerestrictioncode","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_RESTRICTION_CODE_C', {});
                break;
            case 'mineInstallment':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.myInstalment","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_INST', {});
                break;
            case 'mineRedPackage':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineredenvelop","params":{}}`;
                break;
            case 'mineGuang':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineguang","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_STROLL', {});
                break;
            case 'mineShareOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minesharelist","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_SHOW', {});
                break;
            case 'mineMemberInfo':
                if (!data) {
                    return;
                }
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.memberbill","params":{"mine_memberbill_title":"${data.title}","mine_memberbill_url":"${data.url}"}}`;
                NativeModules.YH_MineHelper.setMemberBillNew(false);
                this.props.actions.getMemberBillTaskRedDotSuccess(false);
                break;
            case 'mineActivity':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineactivity","params":{"act_name":"${data.get('act_name')}","act_id":"${data.get('act_id')}","url":"${data.get('url')}","link":"${data.get('url')}"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_INV', {});
                NativeModules.YH_MineHelper.setMineActivityClicked(data.get('act_id'));
                break;
            case 'mineFeedback':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.sfhome","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_FEEDBACK_C', {});
                break;
            case 'mineGlobalOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalorderlist","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_GLOBAL', {});
            default:
                break;
        }
        // 去设置界面不需要判断登陆
        if (viewId === 'mineSetting') {
            ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        }
        else {
            ReactNative.NativeModules.YH_CommonHelper.uid()
                .then(data => {
                    ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
                })
                .catch(error => {
                    ReactNative.NativeModules.YH_CommonHelper.login()
                        .then(uid => {
                            ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
                        })
                        .catch(error => {

                        });
                });
        }
    }

    _onPressProductListProduct(product, rowId = 0) {
        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);
    }

    _onLongPressProduct(rowID) {
        if (rowID) {
            this.props.actions.setSimilarIndex(rowID);
        }
    }

    _onPressFindSimilar(product) {
        if (!product) {
            return;
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpFindSimilar(product.toJS());
        ReactNative.NativeModules.YH_CommonHelper.setSimilarGuiderVisible(false);
        this.props.actions.setSimilarIndex(-1);
        this.props.actions.setShowSimilarGuider(false, false);
    }

    _onMineCenterRefresh() {
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.onMineCenterRefresh();
        });
    }

    render() {
        let {
            isFetching,
            isNeedShowXsrz,
            isLogin,
            open,
            profile,
            mineInfoNum,
            redPackageNum,
            activityListInfo,
            memberBill,
            showRedPacket,
            certificationInfo,
            announcement,
            globalOrderData,
            iconAll,
            instalmentStatus,
            showSimilarGuider,
        } = this.props.mine;
        return (
            <MineList
                isFetching={isFetching}
                isNeedShowXsrz={isNeedShowXsrz}
                isLogin={isLogin}
                productListForMineCenter={open.productListForMineCenter}
                mineCenterInfo={open.mineCenterInfo}
                profile={profile}
                mineInfoNum={mineInfoNum}
                redPackageNum={redPackageNum}
                activityListInfo={activityListInfo}
                memberBill={memberBill}
                showRedPacket={showRedPacket}
                certificationInfo={certificationInfo}
                announcement={announcement}
                globalOrderData={globalOrderData}
                iconAll={iconAll}
                instalmentStatus={instalmentStatus}

                onPressItem={this._onPressItem}
                onPressProductListProduct={this._onPressProductListProduct}
                onMineCenterRefresh={this._onMineCenterRefresh}
                onLongPressProduct={this._onLongPressProduct}
                onPressFindSimilar={this._onPressFindSimilar}
                showSimilarGuider={showSimilarGuider}
            />
        );
    }
}
let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

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