DataContainer.js 5.54 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._onHiddenTipMessage = this._onHiddenTipMessage.bind(this);

    }

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

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

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

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

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

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

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

    render() {
        let {
            showTipsAlert,
            showHelpDialog,
            showSureDialog,
            showWithdrawalDialog,
            settlementInfo,
            addSettlement,
            statisticsInfo,
            shareTotalInfo,
            tipMessage,
        } = 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}
                    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}
                />
                <LoadingIndicator isVisible={isFetching}/>
            </View>

        );
    }
}

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

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