DataContainer.js 7.39 KB
'use strict';

import React, {Component} from 'react';
import ReactNative, {AsyncStorage, Platform, StyleSheet, View} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as allianceActions from '../reducers/alliance/allianceActions';
import LoadingIndicator from '../../common/components/LoadingIndicator';
import Data from "../components/Data";

const actions = [
    allianceActions,
];


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 DataContainer extends Component {
    constructor(props) {
        super(props);

        this.state = {
            tips: '',
        };

        this._showTipsAlertDialog = this._showTipsAlertDialog.bind(this);
        this._hiddenTipsAlertDialog = this._hiddenTipsAlertDialog.bind(this);
        this._showHelpDialog = this._showHelpDialog.bind(this);
        this._hiddenHelpDialog = this._hiddenHelpDialog.bind(this);
        this._showSureDialog = this._showSureDialog.bind(this);
        this._hiddenSureDialog = this._hiddenSureDialog.bind(this);
        this._showWithDrawDialog = this._showWithDrawDialog.bind(this);
        this._hiddenWithDrawDialog = this._hiddenWithDrawDialog.bind(this);
        this._changeTab = this._changeTab.bind(this);
        this._jumpWithUrl = this._jumpWithUrl.bind(this);
        this._resourceJumpWithUrl = this._resourceJumpWithUrl.bind(this);
        this._refreshSettlementInfo = this._refreshSettlementInfo.bind(this);
        this._refreshIdentityCardInfo = this._refreshIdentityCardInfo.bind(this);
        this._onHiddenTipMessage = this._onHiddenTipMessage.bind(this);
        this._onShowTipMessage = this._onShowTipMessage.bind(this);

        this._showBindAlertDialog = this._showBindAlertDialog.bind(this);
        this._hiddenBindAlertDialog = this._hiddenBindAlertDialog.bind(this);

        this._showCheckSettleDialog = this._showCheckSettleDialog.bind(this);
        this._hiddenCheckSettleDialog = this._hiddenCheckSettleDialog.bind(this);
    }

    componentDidMount() {
        this.props.actions.getSettlementInfo();
        this.props.actions.getStatisticsInfo(1);
        this.props.actions.getIdentityCardInfo();
    }

    componentWillUnmount() {

    }

    _showTipsAlertDialog(tips) {
        this.setState({
            tips,
        });
        this.props.actions.showTipsAlertDialog();
    }

    _hiddenTipsAlertDialog() {
        this.props.actions.hiddenTipsAlertDialog();
    }

    _showHelpDialog(tips) {
        this.setState({
            tips,
        });
        this.props.actions.showHelpDialog();
    }

    _hiddenHelpDialog() {
        this.props.actions.hiddenHelpDialog();
    }

    _showSureDialog() {
        this.props.actions.showSureDialog();
    }

    _hiddenSureDialog() {
        this.props.actions.hiddenSureDialog();
    }

    _showCheckSettleDialog() {
       this.props.actions.checkSettlementInfo();
    }

    _hiddenCheckSettleDialog() {
      this.props.actions.hiddenCheckSettleDialog();
    }

    _showWithDrawDialog() {
        this.props.actions.getAddSettlement();
    }

    _hiddenWithDrawDialog() {
        this.props.actions.hiddenWithDrawDialog();
        //重新刷新页面
        this.props.actions.getSettlementInfo();
    }

    _onShowTipMessage(message) {
        this.props.actions.showTipMessage(message);
    }

    _onHiddenTipMessage() {
        this.props.actions.hiddenTipMessage();
    }

    _showBindAlertDialog() {
        this.props.actions.showBindAlertDialog();
    }

    _hiddenBindAlertDialog() {
        this.props.actions.hiddenBindAlertDialog();
    }

    _changeTab(type){
        this.props.actions.getStatisticsInfo(type);
    }

    _jumpWithUrl(title = '', type = '') {
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minealliance","params":{"title":"${title}","type":"${type}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    //重新请求信息,更新银行卡绑定状态
    _refreshSettlementInfo() {
        this.props.actions.getSettlementInfo();
    }

    //重新请求信息,更新身份证绑定状态
    _refreshIdentityCardInfo() {
        this.props.actions.getIdentityCardInfo();
    }

    _resourceJumpWithUrl(url) {
        if (!url) {
            return
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    render() {
        let {
            showTipsAlert,
            showBindAlert,
            showHelpDialog,
            showSureDialog,
            showWithdrawalDialog,
            settlementInfo,
            addSettlement,
            statisticsInfo,
            shareTotalInfo,
            identityCardInfo,
            tipMessage,
            checkSettlementInfo,
            showCheckSettleDialog,
        } = this.props.alliance;
        let tip = this.state.tips;
        let isFetching = settlementInfo.isFetching;
        return (
            <View style={styles.container}>
                <Data
                    isShowTipsAlert={showTipsAlert}
                    isShowHelp={showHelpDialog}
                    isShowSure={showSureDialog}
                    isShowWithdrawal={showWithdrawalDialog}
                    settlementInfo={settlementInfo}
                    addSettlement={addSettlement}
                    statisticsInfo={statisticsInfo}
                    shareTotalInfo={shareTotalInfo}
                    identityCardInfo={identityCardInfo}
                    tips={tip}
                    showTipsAlertDialog={this._showTipsAlertDialog}
                    hiddenTipsAlertDialog={this._hiddenTipsAlertDialog}
                    showHelpDialog={this._showHelpDialog}
                    hiddenHelpDialog={this._hiddenHelpDialog}
                    showSureDialog={this._showSureDialog}
                    hiddenSureDialog={this._hiddenSureDialog}
                    showWithdrawalDialog={this._showWithDrawDialog}
                    hiddenWithDrawDialog={this._hiddenWithDrawDialog}
                    changeTab={this._changeTab}
                    jumpWithUrl={this._jumpWithUrl}
                    refreshSettlementInfo={this._refreshSettlementInfo}
                    resourceJumpWithUrl={this._resourceJumpWithUrl}
                    tipMessage={tipMessage}
                    onHiddenTipMessage={this._onHiddenTipMessage}
                    onShowTipMessage={this._onShowTipMessage}

                    showCheckSettleDialog={this._showCheckSettleDialog}
                    hiddenCheckSettleDialog={this._hiddenCheckSettleDialog}

                    checkSettlementInfo={checkSettlementInfo}
                    isShowCheckSettleDialog={showCheckSettleDialog}

                    isShowBindAlert={showBindAlert}
                    showBindAlertDialog={this._showBindAlertDialog}
                    hiddenBindAlertDialog={this._hiddenBindAlertDialog}
                    refreshIdentityCardInfo={this._refreshIdentityCardInfo}
                />
                <LoadingIndicator isVisible={isFetching}/>
            </View>

        );
    }
}

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

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