import React, {Component} from 'react'; import { View, Image, TouchableHighlight, Text, StyleSheet, TextInput, TouchableOpacity, Dimensions, ScrollView, KeyboardAvoidingView, DeviceEventEmitter, } from 'react-native'; import login_css from '../login/login_css'; import public_css from '../../source/css/public_css'; import loading_css from '../../source/css/loading_css'; import Spinner from 'react-native-loading-spinner-overlay'; import {GetDataPost} from '../../data/encryption'; import {ShowToast} from '../../components/rootToast/root_toast'; import {RetrieveData, StorageData} from '../../data/storage'; import {CheckEmail, CheckPhoneNumber} from '../../source/inspect/inspect'; export default class customer_edit extends Component { constructor(props) { super(props); this.props.navigation.dangerouslyGetParent().setOptions({ tabBarVisible: false, }); this.companyId = this.props.route.params.companyId; this.state = { customer_name: '', customer_code: '', parent_code: '', ent_tax_id: '', short_code: '', email: '', customer_mobile: '', address: '', contact_phone: '', bank_account: '', remark: '', mobile: '', req_channel: '', ip: '', spinner: false, }; } render() { return ( *客户姓名: { this.setState({ customer_name: text, }); }} /> *客户企业税号: { this.setState({ ent_tax_id: text, }); }} /> 联系电话: { this.setState({ contact_phone: text, }); }} /> 地址: { this.setState({ address: text, }); }} multiline={true} numberOfLines={2} textAlignVertical={'top'} /> 银行账号: { this.setState({ bank_account: text, }); }} multiline={true} numberOfLines={2} textAlignVertical={'top'} /> 备注: { this.setState({ remark: text, }); }} /> 填写联系方式,向你同步电子发票信息 *客户手机号: { this.setState({ customer_mobile: text, }); }} /> *邮箱: { this.setState({ email: text, }); }} /> { this.setState({ customer_name: '', customer_code: '', parent_code: '', ent_tax_id: '', short_code: '', email: '', customer_mobile: '', address: '', contact_phone: '', bank_account: '', remark: '', mobile: '', req_channel: '', ip: '', }); }}> 全部清除 this.submitData()}> 确定添加 ); } //提交数据 submitData = async () => { let name = this.state.customer_name; if (!name) { ShowToast('客户姓名不可以为空!'); return; } let entId = this.state.ent_tax_id; if (!entId) { ShowToast('客户企业税号不可以为空!'); return; } let phone = this.state.customer_mobile; if (!phone) { ShowToast('客户手机号不可以为空!'); return; } let email = this.state.email; if (!email) { ShowToast('客户邮箱不可以为空!'); return; } let {status, msg} = CheckPhoneNumber(`${this.state.customer_mobile}`); if (status) { let {status, msg} = CheckEmail(`${this.state.email}`); if (status) { this.setLoadingStatus(true); const res = await RetrieveData('token'); const account = await RetrieveData('account'); if (res && account) { let token = res.substring(1, res.length - 1); let mobile = account.substring(1, account.length - 1); const url = 'https://app.taxbk.cn:9443/sys/customer/saveOrUpdate'; let response = await GetDataPost( url, token, { customerId: this.companyId, customerName: this.state.customer_name, customerCode: this.state.customer_code, parentCode: this.state.parent_code, entTaxId: this.state.ent_tax_id, shortCode: this.state.short_code, email: this.state.email, customerMobile: this.state.customer_mobile, address: this.state.address, contactPhone: this.state.contact_phone, bankAccount: this.state.bank_account, remark: this.state.remark, mobile: mobile, reqChannel: 3, ip: this.state.ip, }, false, 1, ); if (response.code != 0) { ShowToast(response.msg); this.setLoadingStatus(false); } else { ShowToast('编辑成功!'); this.setLoadingStatus(false); this.props.navigation.goBack(); DeviceEventEmitter.emit('刷新列表', ''); } } } else { ShowToast(msg); } } else { ShowToast(msg); } }; //设置loading层是否显示 setLoadingStatus(isLoading) { this.setState({ spinner: isLoading, }); } //加载页面时显示数据 componentDidMount(): void { this.getCompanyData(); } //加载数据 getCompanyData = async () => { const res = await RetrieveData('token'); if (res) { let token = res.substring(1, res.length - 1); const url = 'https://app.taxbk.cn:9443/sys/customer/findById'; GetDataPost( url, token, { customerId: this.companyId, }, false, 2, ).then(res => { console.log(res); this.setState({ customer_name: res.data.customerName, customer_code: res.data.customerCode, parent_code: res.data.parentCode, ent_tax_id: res.data.entTaxId, short_code: res.data.shortCode, email: res.data.email, address: res.data.address, contact_phone: res.data.contactPhone, bank_account: res.data.bankAccount, remark: res.data.remark, }); }); } }; }