StockStats.js 3.13 KB
'use strict';

import React, {Component} from 'react';
import PlainTextSection from './PlainTextSection';
import Placeholder from './Placeholder';

import {
    StyleSheet,
    View,
    Text,
    ListView,
    Image,
    Dimensions,
    TouchableHighlight,
} from 'react-native';

export default class StockStats extends Component {

    constructor(props) {
        super (props);

        this.ds = new ListView.DataSource({
            rowHasChanged: (r1, r2) => r1 !== r2,
        });

        this._renderRow = this._renderRow.bind(this);
    }

	_renderRow(rowData, sectionID, rowID) {
        return (
            <TouchableHighlight underlayColor={'white'} onPress={() => {}}>
                <View style={styles.row}>
                    <Image source={{uri: rowData.thumb}} style={styles.thumb}/>
                    <View style={styles.detail}>
                        <Text style={styles.brand}>{rowData.brand}</Text>
                        <Text style={styles.product}>{rowData.product}</Text>
                        <Text style={styles.brand}>{'厂家编号:' + rowData.vendor + '  sku:' + rowData.sku}</Text>
                        <Text style={styles.product}>{'进货价:' + rowData.importPrice + '  库存:' + rowData.stockNum}</Text>
                    </View>
                </View>
            </TouchableHighlight>
        );
	}

	render() {
		return (
            <View style={styles.container}>
                <View style={styles.dateContainer}>
                    <Image source={require('../images/date.png')}/>
                    <Text style={styles.date}>{this.props.section1}</Text>
                </View>
                <Placeholder />
                <PlainTextSection content={this.props.section2} />
                <Placeholder />
                <ListView
                    dataSource={this.ds.cloneWithRows(this.props.section3)}
                    renderRow={this._renderRow}
                    renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator}/>}
                    onEndReachedThreshold={-10}
                    onEndReached={this.props.requestData}
                    enableEmptySections={true} />
            </View>
		);
	}

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    dateContainer: {
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        height: 45,
        backgroundColor: 'white',
    },
    date: {
        fontSize: 14,
        color: '#444444',
        textAlign: 'center',
        marginLeft: 10,
    },
    separator: {
        height: 1,

    },
    row: {
        flexDirection: 'row',
        paddingLeft: 10,
        paddingRight: 10,
        paddingTop: 10,
        paddingBottom: 10,
        backgroundColor: 'white',
        alignItems: 'center',
    },
    detail: {
        flexDirection: 'column',
        justifyContent: 'center',
        flex: 1,
        paddingLeft: 10,

    },
    thumb: {
        width: 60,
        height: 80,
    },
    brand: {
        color: '#B0B0B0',
        fontSize: 12,
    },
    product: {
        color: '#444444',
        fontSize: 12,
    },
});