OutOfStock.js 4.62 KB
'use strict';

import React, {Component} from 'react';
import LoadMoreIndicator from '../indicator/LoadMoreIndicator';
import LoadingIndicator from '../indicator/LoadingIndicator';
import moment from 'moment';

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

export default class OutOfStock extends Component {

    constructor(props) {
        super (props);
        this._onChangeText = this._onChangeText.bind(this);
    }

    _onChangeText(text){
        let {resource} = this.props;
        let data = resource?resource.toJS():null;
        let id = data?data.id:0;
        let lackNum = data.lackNum?data.lackNum:0;//缺货数
        let shipmentsNums = data.shipmentsNums?data.shipmentsNums:0;//发货数量
        let buyingNums = data.buyingNums?data.buyingNums:0;//外采数量 销售数
        let lastNum = buyingNums - lackNum - shipmentsNums;//实际应发数
        let num = text;

        if ((num | 0) === num || num > lastNum) {
            num = -1;
        }
        this.props.setLackNum && this.props.setLackNum(num);
        this.props.setInitialRes && this.props.setInitialRes(data);
    }

	render() {
        let {resource,outOfStock} = this.props;
        let num = outOfStock?outOfStock.lackNum:0;
        let textInputColor = num >= 0 ? 'transparent' : 'red';

        let data = resource?resource.toJS():null;
        let sku = data.productSku?data.productSku:0;//sku
        let factoryGoodsName = data.factoryGoodsName?data.factoryGoodsName:0;//厂家颜色
        let sizeName = data.sizeName?data.sizeName:0;//尺码名
        let skuFactoryCode = data.skuFactoryCode?data.skuFactoryCode:0;//商品条码
        let lackNum = data.lackNum?data.lackNum:0;//缺货数

        let shipmentsNums = data.shipmentsNums?data.shipmentsNums:0;//发货数量
        let inStoreNum = data.inStoreNum?data.inStoreNum:0;//入库数量 收货数量
        let buyingNums = data.buyingNums?data.buyingNums:0;//外采数量 销售数

        let lastNum = buyingNums - lackNum - shipmentsNums;//实际应发数

		return (
            <View style={styles.container}>
				<View style={styles.cell}>
					<Text style={styles.cellText1} numberOfLines={1}>SKU:{sku}</Text>
					<Text style={styles.cellText2} numberOfLines={1}>商品条码:{skuFactoryCode}  {factoryGoodsName}/{sizeName}</Text>
					<Text style={styles.cellText3} numberOfLines={1}>当前需发数:{lastNum}</Text>
				</View>
				<View style={styles.textInputCell}>
                    <Text style={styles.cellText} numberOfLines={1}>缺货:</Text>
                    <TextInput style={{
                        width: width - 80,
                        height: 40,
                        backgroundColor: textInputColor,
                        fontSize:15,
                        marginLeft: 10,
                        borderWidth: 1,
                        borderColor: '#CCC',
                        borderRadius: 4,
                        marginTop: 5,
                    }}
                        ref = 'textInput'
    					placeholder={'单行输入'}
                        keyboardType={'numeric'}
    					onChangeText={this._onChangeText}
    				/>
                </View>
				<Text style={styles.tip} numberOfLines={1}>*提货报缺后不可修改,平台将对顾客订单商品进行退单处理</Text>
            </View>
		);
	}
}

let {width, height} = Dimensions.get('window');
const styles = StyleSheet.create({
    container: {
        flex: 1,
		backgroundColor: 'white',
    },
	cell: {
        width: width,
        height: 40,
        backgroundColor: 'white',
        flexDirection: 'row',
        alignItems: 'center',
    },
	cellText1: {
        fontSize:12,
        marginLeft: 10,
        width:  Math.ceil((width-20)/3)-30,
    	textAlign: 'left',
        color: 'black',
    },
    cellText2: {
        fontSize:12,
        width: Math.ceil((width-20)/3)+60,
    	textAlign: 'center',
        color: 'black',
    },
    cellText3: {
        fontSize:12,
        width: Math.ceil((width-20)/3)-30,
    	textAlign: 'right',
        color: 'black',
    },
	textInputCell: {
        width: width,
        height: 50,
        flexDirection: 'row',
        alignItems: 'center',
		marginLeft: 20,
    },
    inputText:{
        width: width - 80,
        height: 40,
        backgroundColor:'transparent',
        fontSize:15,
        marginLeft: 10,
        borderWidth: 1,
        borderColor: '#CCC',
        borderRadius: 4,
        marginTop: 5,
    },
	tip: {
		marginTop: 20,
		marginLeft: 20,
		fontSize:12,
        width: width-20,
    	textAlign: 'left',
        color: 'red',
	}
});