import React, {Component} from 'react'; import { View, Text, TextInput, TouchableOpacity, ScrollView, SafeAreaView, } from 'react-native'; import {List, Picker, WingBlank, WhiteSpace} from '@ant-design/react-native'; 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 {RequestNetwork} from '../../../data/encryption'; import {RetrieveData} from '../../../data/storage'; import {CheckEmail, CheckPhoneNumber} from '../../../source/inspect/inspect'; import {ToastShow} from '../../../components/toast/toast'; export default class customer_add_or_edit extends Component { constructor(props) { super(props); this.state = { customerName: '', entTaxId: '', email: '', customerMobile: '', address: '', contactPhone: '', bank: '', bankAccount: '', remark: '', mobile: '', spinner: false, companyTypes: [ { label: '个人', value: '1', }, { label: '企业', value: '2', }, ], companyType: '1', isEdit: false, customerId: '', }; } render() { return ( 基础信息 this.companyTypeChange(value)}> * 客户抬头类型: *客户姓名: { this.setState({ customerName: text, }); }} /> {this.state.companyType === '1' ? ( 客户企业税号: { this.setState({ entTaxId: text, }); }} /> ) : ( * 客户企业税号: { this.setState({ entTaxId: text, }); }} /> )} 地址: { this.setState({ address: text, }); }} multiline={true} numberOfLines={2} textAlignVertical={'top'} /> 联系电话: { this.setState({ contactPhone: text, }); }} /> 开户行: { this.setState({ bank: text, }); }} /> 银行账号: { this.setState({ bankAccount: text, }); }} multiline={true} numberOfLines={2} textAlignVertical={'top'} /> 备注: { this.setState({ remark: text, }); }} /> 填写联系方式,向您同步电子发票信息 * 客户手机号: { this.setState({ customerMobile: text, }); }} /> * 邮箱: { this.setState({ email: text, }); }} /> {this.state.isEdit === true ? ( this.deleteCustomer()}> 删除 this.submitData()}> 保存 ) : ( this.submitData()}> 新增 )} ); } //加载页面时显示数据 componentDidMount(): void { let customerId = this.props.route.params.companyId; if (customerId) { this.setState({ isEdit: true, customerId: customerId, }); this.getCompanyData(); } } //提交数据 submitData = async () => { let name = this.state.customerName; if (!name) { ToastShow(1, '客户姓名不可以为空!'); return; } if (this.state.companyType === '2') { let entId = this.state.entTaxId; if (!entId) { ToastShow(1, '客户企业税号不可以为空!'); return; } } let phone = this.state.customerMobile; if (!phone) { ToastShow(1, '客户手机号不可以为空!'); return; } let email = this.state.email; if (!email) { ToastShow(1, '客户邮箱不可以为空!'); return; } let {status, msg} = CheckPhoneNumber(`${this.state.customerMobile}`); if (status) { let {status, msg} = CheckEmail(`${this.state.email}`); if (status) { this.setLoadingStatus(true); const token = await RetrieveData('token'); const account = await RetrieveData('account'); const company = JSON.parse(await RetrieveData('company')); if (token && account) { const url = '/sys/customer/save'; let response = await RequestNetwork( url, token, { customerId: this.state.customerId, customerName: this.state.customerName, customerType: this.state.companyType, customerEntTaxId: this.state.entTaxId, email: this.state.email, customerMobile: this.state.customerMobile, address: this.state.address, contactPhone: this.state.contactPhone, bankName: this.state.bank, bankAccountNumber: this.state.bankAccount, remark: this.state.remark, entTaxId: company.entTaxId, mobile: account, reqChannel: 3, }, false, 1, ); if (response) { console.log(response); if (response.code === 0) { this.setLoadingStatus(false); ToastShow(1, '保存成功!'); this.props.route.params.refresh(); this.props.navigation.goBack(); } else { this.setLoadingStatus(false); ToastShow(1, response.msg); } } } } else { ToastShow(1, msg); } } else { ToastShow(1, msg); } }; //设置loading层是否显示 setLoadingStatus(isLoading) { this.setState({ spinner: isLoading, }); } // 企业类型选择 companyTypeChange = (value) => { let companyType = ''; if (value.length > 0) { companyType = value[0]; } this.setState({ companyType: companyType, }); }; //加载数据 getCompanyData = async () => { const token = await RetrieveData('token'); if (token) { const url = '/sys/customer/findById'; let res = await RequestNetwork( url, token, { customerId: this.state.customerId, }, false, 2, ); if (res) { if (res.code === 0) { this.setState({ customerName: res.data.customerName, entTaxId: res.data.customerEntTaxId, email: res.data.email, address: res.data.address, contactPhone: res.data.contactPhone, customerMobile: res.data.customerMobile, bank: res.data.bankName, bankAccount: res.data.bankAccountNumber, remark: res.data.remark, companyType: res.data.customerType.toString(), }); } } } }; //删除客户数据 deleteCustomer = async () => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); const company = JSON.parse(await RetrieveData('company')); if (account && token) { const url = '/sys/customer/delete'; let res = await RequestNetwork( url, token, { mobile: account, reqChannel: 3, delList: [ { customerId: this.state.customerId, entTaxId: company.entTaxId, }, ], }, false, 1, ); if (res) { if (res.code === 0) { ToastShow(1, '删除成功!'); this.props.route.params.refresh(); this.props.navigation.goBack(); } else { ToastShow(1, '删除失败!'); } } else { ToastShow(1, '删除失败!'); } } }; }