MineContainer.js 9.79 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.subscription1 = NativeAppEventEmitter.addListener(
            'UserDidLoginEvent',
            (reminder) => {
                this.props.actions.getMineUserInfo();
                this.props.actions.getMineUserInfoNum();
                this.props.actions.getMineUnreadMsg();
                this.props.actions.getMineFavProNum();
                this.props.actions.getMineRedPackageNum();
                this.props.actions.getMineInstalemtInfo();
                this.props.actions.getMineActivity();
                this.props.actions.getMemberBillTask();
                this.props.actions.getEnvelopesItem();
                this.props.actions.getCertificationData();
                this.props.actions.getAnnouncement();
                this.props.actions.getGlobalOrderState();
            }
        );

        this.subscription2 = NativeAppEventEmitter.addListener(
            'UserDidLogoutEvent',
            (reminder) => {
                this.props.actions.getMineUserInfo();
                this.props.actions.getMineUserInfoNum();
                this.props.actions.getMineUnreadMsg();
                this.props.actions.getMineFavProNum();
                this.props.actions.getMineRedPackageNum();
                this.props.actions.getMineInstalemtInfo();
                this.props.actions.getMineActivity();
                this.props.actions.getMemberBillTask();
                this.props.actions.getEnvelopesItem();
                this.props.actions.getCertificationData();
                this.props.actions.getAnnouncement();
                this.props.actions.getGlobalOrderState();
            }
        );

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



    componentDidMount() {
        this.props.actions.productListForInstallment();
        this.props.actions.getMineUserInfo();
        this.props.actions.getMineUserInfoNum();
        this.props.actions.getMineUnreadMsg();
        this.props.actions.getMineFavProNum();
        this.props.actions.getMineRedPackageNum();
        this.props.actions.getMineInstalemtInfo();
        this.props.actions.getMineActivity();
        this.props.actions.getMemberBillTask();
        this.props.actions.getEnvelopesItem();
        this.props.actions.getCertificationData();
        this.props.actions.getAnnouncement();
        this.props.actions.getGlobalOrderState();
    }

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

    _onPressItem(viewId, data) {
        let url = "";
        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":{}}`;
                break;
            case 'mineInfo':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineinfo","params":{}}`;
                break;
            case 'mineCertification':
                //学生认证
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.studenthome","params":{}}`;
                break;
            case 'mineLogin':
                ReactNative.NativeModules.YH_CommonHelper.login();
                //登陆
                break;
            case 'mineFavProduct':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{}}`;
                break;
            case 'mineFavBrand':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{"favType":"1"}}`;
                break;
            case 'mineBrowseHis':
                //浏览记录
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.browserhistory","params":{}}`;
                break;
            case 'mineSetPhone':
                //设置安全性
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.associatephone","params":{}}`;
                break;
            case 'mineAnnounce':
                //通知
                url = data;
                break;
            case 'mineOrder':
                //我的订单
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"0"}}`;
                break;
            case 'dfkOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"0"}}`;
                break;
            case 'dfhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"1"}}`;
                break;
            case 'dshOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"2"}}`;
                break;
            case 'dsdOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.showgoods","params":{}}`;
                break;
            case 'thhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.orderService","params":{}}`;
                break;
            case 'mineCoupon':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.coupon","params":{}}`;
                break;
            case 'mineYohoCoin':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.yohocoin","params":{}}`;
                break;
            case 'mineLimitCode':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minerestrictioncode","params":{}}`;
                break;
            case 'mineInstallment':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.myInstalment","params":{}}`;
                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":{}}`;
                break;
            case 'mineShareOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.shareorder","params":{}}`;
                break;
            case 'mineMemberInfo':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.memberbill","params":{}}`;
                break;
            case 'mineActivity':
                url = data;
                break;
            case 'mineFeedback':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.sfhome","params":{}}`;
                break;
            case 'mineGlobalOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalorderlist","params":{}}`;
            default:
                break;
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

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

    render() {
        let {
            isFetching,
            isLogin,
            open,
            profile,
            mineInfoNum,
            redPackageNum,
            activityListInfo,
            memberBill,
            showRedPacket,
            certificationInfo,
            announcement,
            globalOrderData,
        } = this.props.mine;
        console.log("open");
        console.log(activityListInfo);
        return (
            <MineList
                isFetching={isFetching}
                isLogin={isLogin}
                productListForInstallment={open.productListForInstallment}
                installmentInfo={open.installmentInfo}
                profile={profile}
                mineInfoNum={mineInfoNum}
                redPackageNum={redPackageNum}
                activityListInfo={activityListInfo}
                memberBill={memberBill}
                showRedPacket={showRedPacket}
                certificationInfo={certificationInfo}
                announcement={announcement}
                globalOrderData={globalOrderData}

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

});

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