CalculatorView.js 3.06 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TextInput,
    Image,
} from 'react-native';
import {convertCurrency} from "../utils/utils";

const defaultHeight = (62);
const titleViewHeight = (24);
const HPading = (16);
const VPading = (6);

export default class CalculatorView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            result: '',
        };
        this.attrData = this.props.attrData;
        this.onChangeText = this.props.onChangeText;
        this.inputType = this.props.inputType || 'default';// 输入类型

        this.extendData = JSON.parse(this.attrData.data);
        this.expression = this.extendData.expression;
    }

    calculateValue(count, type) {
        if (count === null || count.length === 0) {
            this.setState({
                result: ""
            })
        } else {
            let _result = Number(count) * 2;
            this.setState({
                result: _result+""
            })
        }
    }

    render() {
        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        let {placeholder, showChinese} = this.extendData;

        let calcHeight = defaultHeight;
        if(showChinese){
            calcHeight += 40
        }

        return(
            <View style={{width: '100%', backgroundColor: 'white', paddingTop: VPading,paddingHorizontal: HPading, height:calcHeight}}>
                <View style={{flexDirection: 'row',height:titleViewHeight,justifyContent:'flex-start',alignItems:'center'}}>
                    {isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
                    {!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', marginBottom: 5}}>{name||""}</Text>
                </View>
                <TextInput
                    style={{fontSize: 14, color: 'black', width: "100%", backgroundColor: 'white', textAlign: 'left', paddingVertical: 5, paddingHorizontal: 0}}
                    multiline={false}
                    editable={false}
                    keyboardType={this.inputType}
                    onChangeText={text => {
                        if (this.onChangeText) {
                            this.onChangeText(text)
                        }
                    }}
                    value={this.state.result}
                    placeholderTextColor={'#999'}
                    placeholder={placeholder||'自动计算数值'}
                    underlineColorAndroid="transparent"
                />
                {showChinese && <View style={{height:40,paddingBottom:VPading,flexDirection: 'row',alignItems:'center',backgroundColor:'#fff',marginHorizontal:HPading}}>
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>大写</Text>
                    <Text style={{fontSize: 14, color: 'rgba(0, 0, 0, 1)',marginLeft:4,marginRight:4}}>{!!this.state.result?convertCurrency(this.state.result):''}</Text>
                </View>
                }
            </View>
        )
    }
}