PhoneEditView.js 3.53 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TextInput,
} from 'react-native';
const defaultHeight = (70);
const titleViewHeight = (24);
const VPading = (6);

export default class PhoneEditView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            inputValue: ''
        };
        this.attrData = this.props.attrData;
        this.extendData = (this.attrData.data && this.attrData.data.length > 0)?JSON.parse(this.attrData.data):{};
        this.onChangeText = this.props.onChangeText;
        this.inputType = this.props.inputType || 'numeric';
    }

    componentWillMount() {
        if (this.attrData.value && this.attrData.value.length > 0) {
            this.setState({
                inputValue: this.attrData.value
            })
        }
    }

    render() {
        // 名称    // type固定:PHONE   // 是否必须
        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        // data type: 校验类型 固定:ALL=手机和固话|MOBILE=手机|PHONE=固话
        let {placeholder} = this.extendData;
        let tabType = this.extendData.type;

        return (
            <View style={{width: '100%', backgroundColor: 'white', height: defaultHeight, paddingVertical: VPading, paddingLeft: 10, paddingRight: 15,
            }}>
                <View style={{height:titleViewHeight, flexDirection: 'row', justifyContent:'flex-start',alignItems:'center', backgroundColor: '#fff'}}>
                    {isRequired&&<Text style={{ color: "#FF3030" }}>* </Text>}
                    {!isRequired&&<Text style={{ color: "#fff" }}>* </Text>}
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{name || ""}</Text>
                </View>
                <View style={{flexDirection: 'row', width: '100%', justifyContent: 'center', marginLeft: 10}}>
                    {tabType !== 'ALL' &&
                        <View style={{flexDirection: 'row'}}>
                            <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{tabType === 'MOBILE'?'+86  >  ':'固话'}</Text>
                            <View style={{width: 1, height: 24, backgroundColor: '#f3f4f5', marginHorizontal: 5}}/>
                        </View>
                    }
                    <TextInput
                        style={{
                            fontSize: 14,
                            color: 'black',
                            width: '100%',
                            backgroundColor: '#fff',
                            textAlign: 'left',
                            height: 30,
                            marginTop:4,
                            marginBottom:4,
                            padding:0
                        }}
                        maxLength={11}
                        keyboardType={this.inputType}
                        value={this.state.inputValue}
                        onChangeText={text => {
                            const newText = text.replace(/[^\d]+/, '');
                            this.setState({inputValue: newText})
                            if (this.onChangeText) {
                                this.onChangeText(newText)
                            }
                            this.attrData.value = newText;
                        }}
                        placeholderTextColor={'#999'}
                        placeholder={placeholder||'请输入'}
                        underlineColorAndroid="transparent"
                    />
                </View>
            </View>
        );
    }
}