BillingAdd.js 7.55 KB
/**
 * Created by DEV005 on 2017/11/13.
 */

/**
 * Created by tdzl2003 on 12/18/16.
 */
import React, {Component} from "react";
import {
    Image,
    ListView,
    NativeModules,
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View,
    Platform,
    RefreshControl,
    ActivityIndicator,
    ScrollView,
    Dimensions,
    Modal
} from "react-native";

import { observable, useStrict, action } from 'mobx';
import { observer } from 'mobx-react';
import {xnToast,getHeaderHeight,getHeaderPadding,getFooterBottom,xnBorderWidth} from "../utils/utils";
import AppService from "../service/AppService";



export default class BillingAdd extends Component {

    static navigationOptions = ({ navigation, screenProps })=>({
        title: '我的开票公司',
        headerLeft:(<View style={{flexDirection: 'row',flex:1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._goBack:null}>
                <Image style={{  width:16,height:16}}  source={require('../img/backB.png')}  resizeMode="contain"/>
            </TouchableOpacity>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:15}} onPress={navigation.state.params?navigation.state.params._close:null}>
                <Image style={{  width:16,height:16}}  source={require('../img/closeB.png')}  resizeMode="contain"/>
            </TouchableOpacity>
        </View>),
        headerRight:(<View style={{flexDirection: 'row',flex:1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._save:null}>
                <Text style={{fontSize:16,color:"#000"}} >保存</Text>
            </TouchableOpacity>
        </View>)
    });

    constructor(props) {
        super(props);
        this.state = {
            legalentityName:"",
            creditCode:"",
            bankAccountName:"",
            bankAccountNumber:"",
            legalentityAddress:"",
            phoneNumber:"",

        };
    }
    componentDidMount(){
        let  _this=this;
        //设置头部
        this.props.navigation.setParams({
            _goBack:()=>{
                this.props.navigation.goBack();
            },
            _close:()=>{
                NativeModules.system.navTo("BACK")
            },
            _save:()=>{
                _this._save();

            }
        });

    };


    render() {
        return (
            <View style={styles.body}>
                <ScrollView  style={styles.list}>
                    <View style={styles.item} >
                        <TextInput  style={styles.input}  autoFocus={true}
                                    placeholder="输入开票公司名称"  placeholderTextColor="#dddddd"
                                    value={this.state.legalentityName}
                                    onChangeText={v => {this.setState({legalentityName: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>
                    <View style={styles.item} >
                        <TextInput  style={styles.input}
                                    placeholder="输入统一社会信用代码"  placeholderTextColor="#dddddd"
                                    value={this.state.creditCode}
                                    onChangeText={v => {this.setState({creditCode: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>

                    <View style={styles.item} >
                        <TextInput  style={styles.input}
                                    placeholder="输入开户银行账号名称"  placeholderTextColor="#dddddd"
                                    value={this.state.bankAccountName}
                                    onChangeText={v => {this.setState({bankAccountName: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>
                    <View style={styles.item} >
                        <TextInput  style={styles.input}
                                    placeholder="输入开户银行账号"  placeholderTextColor="#dddddd"
                                    value={this.state.bankAccountNumber}
                                    onChangeText={v => {this.setState({bankAccountNumber: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>
                    <View style={styles.item} >
                        <TextInput  style={styles.input}
                                    placeholder="输入单位地址"  placeholderTextColor="#dddddd"
                                    value={this.state.legalentityAddress}
                                    onChangeText={v => {this.setState({legalentityAddress: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>
                    <View style={styles.item} >
                        <TextInput  style={styles.input} keyboardType="phone-pad"
                                    placeholder="输入电话号码"  placeholderTextColor="#dddddd"
                                    value={this.state.phoneNumber}
                                    onChangeText={v => {this.setState({phoneNumber: v});}}
                                    underlineColorAndroid={'transparent'}
                        />
                    </View>
                </ScrollView>
            </View>
        );
    }
    
    _save=()=>{
        let _this=this;
        if(!_this.state.legalentityName){
            xnToast("输入开票公司名称!");
            return
        }
        if(!_this.state.creditCode){
            xnToast("输入统一社会信用代码!");
            return
        }
        if(!_this.state.bankAccountName){
            xnToast("输入开户银行账号名称!");
            return
        }
        if(!_this.state.bankAccountNumber){
            xnToast("输入开户银行账号!");
            return
        }
        if(!_this.state.legalentityAddress){
            xnToast("输入单位地址!");
            return
        }
        if(!_this.state.phoneNumber){
            xnToast("输入电话号码!");
            return
        }
        var item={
            unionId:global.unionId,
            legalentityName:_this.state.legalentityName,
            creditCode:_this.state.creditCode,
            bankAccountName:_this.state.bankAccountName,
            bankAccountNumber:_this.state.bankAccountNumber,
            legalentityAddress:_this.state.legalentityAddress,
            phoneNumber:_this.state.phoneNumber,
        };

        AppService.createLegalentity(item).then(data=>{
            if (data.errors == null || data.errors.length > 0) {
                xnToast(data.errors[0].message);
                return
            }
            _this.props.navigation.navigate("Billing");
        })

    }

}

const styles = StyleSheet.create({

    body:{
        flex:1,
        flexDirection:"column",  
        backgroundColor:"#f0eff5",      
    },
    list:{
        flex:1
    },
    item:{
        flexDirection:"row",
        alignItems:"center",
        backgroundColor:"#fff",
        marginTop:10,
        height:45,
    },
    input:{
        flex:1,
        paddingLeft:8,
        paddingRight:8,
    }
});