MineContainer.js 11.9 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.subscription1 = NativeAppEventEmitter.addListener(
            'UserDidLoginEvent',
            (reminder) => {
                this.props.actions.onMineCenterRefresh();
            }
        );

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

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

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

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

    componentWillUnmount() {
        this.subscription1 && this.subscription1.remove();
        this.subscription2 && this.subscription2.remove();
        this.subscription3 && this.subscription3.remove();
        this.subscription4 && this.subscription4.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":{}}`;
                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.shareOrder","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')}"}}`;
                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);
    }

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

    render() {
        let {
            isFetching,
            isLogin,
            open,
            profile,
            mineInfoNum,
            redPackageNum,
            activityListInfo,
            memberBill,
            showRedPacket,
            certificationInfo,
            announcement,
            globalOrderData,
            iconAll,
        } = this.props.mine;
        return (
            <MineList
                isFetching={isFetching}
                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}

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

});

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