StudentContainer.js 5.21 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 studentActions from '../reducers/student/studentActions';
import Register from '../components/student/Register';

const actions = [
    studentActions,
];

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 StudentContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressRegisterInfoCell = this._onPressRegisterInfoCell.bind(this);

        this._fetchStudentProducts = this._fetchStudentProducts.bind(this);
        this._onPressProduct = this._onPressProduct.bind(this);

        this._updateRegisterCellsInfo = this._updateRegisterCellsInfo.bind(this);
        this._showProvinceSelectView = this._showProvinceSelectView.bind(this);
        this._showSchoolSelectView = this._showSchoolSelectView.bind(this);

        this._hideProvinceSelectView = this._hideProvinceSelectView.bind(this);
        this._hideSchoolSelectView = this._hideSchoolSelectView.bind(this);
        this._registerNow = this._registerNow.bind(this);
        this._updateSearchResultPageInfo = this._updateSearchResultPageInfo.bind(this);
        this._gotoProtocol = this._gotoProtocol.bind(this);
        this._showTipMesage = this._showTipMesage.bind(this);
        this._checkYohoProtocol = this._checkYohoProtocol.bind(this);
    }

    componentDidMount() {
        this.props.actions.getRegisterPageInfo();
        this.props.actions.getProvince();
        this.props.actions.getSchool();
    }

    _onPressRegisterInfoCell(registerCellInfo) {
        this.props.actions.clickRegisterInfoCell(registerCellInfo);
    }

    _fetchStudentProducts(){
        this.props.actions.fetchStudentProducts();
    }

    _onPressProduct(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);
    }
    _updateRegisterCellsInfo(registerCellInfo) {
        this.props.actions.updateRegisterCellsInfo(registerCellInfo);
    }


    _showProvinceSelectView() {
        this.props.actions.showProvinceSelectView();
    }

    _showSchoolSelectView() {
        this.props.actions.showSchoolSelectView();
    }

    _hideProvinceSelectView(provinceItemInfo) {
        this.props.actions.hideProvinceSelectView(provinceItemInfo);
    }

    _hideSchoolSelectView(schoolItemInfo) {
        this.props.actions.hideSchoolSelectView(schoolItemInfo);
    }
    _updateSearchResultPageInfo(searchResultPageInfo){
        this.props.actions.updateSearchResultPageInfo(searchResultPageInfo);
    }

    _registerNow() {
        this.props.actions.registerNow();
    }

    _gotoProtocol() {
        this.props.actions.gotoProtocol();
    }

    _showTipMesage(message) {
        this.props.actions.showTipMesage(message);
    }

    _checkYohoProtocol() {
        this.props.actions.checkYohoProtocol();
    }

    render() {
        let {student} = this.props;
        let {registerPageInfo,productPageInfo,tipMessage} = student;
        return (
            <View style={styles.container}>
                <Register
                    registerPageInfo={registerPageInfo}
                    fetchStudentProducts={this._fetchStudentProducts}
                    resource={productPageInfo}
                    onPressProduct={this._onPressProduct}
                    tipMessage={tipMessage}
                    onPressRegisterInfoCell={this._onPressRegisterInfoCell}
                    updateRegisterCellsInfo={this._updateRegisterCellsInfo}
                    showProvinceSelectView={this._showProvinceSelectView}
                    showSchoolSelectView={this._showSchoolSelectView}
                    hideProvinceSelectView={this._hideProvinceSelectView}
                    hideSchoolSelectView={this._hideSchoolSelectView}
                    registerNow={this._registerNow}
                    updateSearchResultPageInfo={this._updateSearchResultPageInfo}
                    gotoProtocol={this._gotoProtocol}
                    showTipMesage={this._showTipMesage}
                    checkYohoProtocol={this._checkYohoProtocol}
                />
            </View>

            // <View style={styles.container}>
            //     <Register
            //     registerPageInfo={registerPageInfo}
            //     onPressRegisterInfoCell={this._onPressRegisterInfoCell}
            //     />
            // </View>
        );
    }
}

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

});

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