DeliverGoodsContainer.js 2.79 KB

'use strict';

import React, { Component } from 'react';
import Immutable, {List, Record} from 'immutable';
import DeliverGoods from '../components/DeliverGoods/DeliverGoods'

import ReactNative,{
    StyleSheet,
    View,
    Text,
    ListView,
    Dimensions,
    Platform,
    NativeAppEventEmitter,
    NativeModules,
} from 'react-native';

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {Map} from 'immutable';

import * as deliverGoodsActions from '../reducers/deliverGoods/deliverGoodsActions';

const actions = [
    deliverGoodsActions,
];


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 DeliverGoodsContainer extends Component {

	constructor(props) {
		super(props);
        this._setExpressNum = this._setExpressNum.bind(this);
        this._setExpressValue = this._setExpressValue.bind(this);
        this._startScanQRCode = this._startScanQRCode.bind(this);

        this.subscription = NativeAppEventEmitter.addListener(
            'scanQRComplete',
            (param) => {
                this.props.actions.setExpressNum(param.QRCode);
            }
        );
	}

    componentWillUnmount() {
        this.subscription && this.subscription.remove();
    }

	componentDidMount() {
        this.props.actions.getExpressList();
        this.props.actions.queryBySupplierId();
	}

    _setExpressNum(text){
        this.props.actions.setExpressNum(text);
    }

    _setExpressValue(value,initialRes){
        this.props.actions.setExpressValue(value,initialRes);
    }

    _startScanQRCode(){
        NativeModules.QRNativeConfig.startScanQRCode();
    }

	render() {
        let {deliverGoods,initialRes,expressNum,expressValue} = this.props;

		return (
			<View style={styles.container}>
                <DeliverGoods
                    initialRes={initialRes}
                    resource={deliverGoods}
                    expressNum={expressNum}
                    expressValue={expressValue}
                    setExpressNum={this._setExpressNum}
                    setExpressValue={this._setExpressValue}
                    startScanQRCode={this._startScanQRCode}/>
			</View>
		);
	}
}

let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;

let styles = StyleSheet.create({
    container: {
        top: navbarHeight,
        height: height - navbarHeight,
        paddingBottom: (Platform.OS === 'android') ? 24 : 0,
    },

});

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