import React, {Component} from 'react'; import { View, Image, Text, FlatList, TextInput, TouchableOpacity, ScrollView, SafeAreaView, StyleSheet, } from 'react-native'; import { List, SwipeAction, WhiteSpace, WingBlank } from "@ant-design/react-native"; import public_css from '../../../source/css/public_css'; import {ToastShow} from '../../../components/toast/toast'; export default class enterprise_tax_rate extends Component { constructor(props) { super(props); this.state = { taxRates: [], taxRate: '', }; } render() { return ( { this.addRate(); }} style={{ height: 40, backgroundColor: '#ffffff', justifyContent: 'center', alignItems: 'center', flexDirection: 'row', elevation: 10, shadowColor: 'black', shadowOffset: {width: 0, height: 0}, shadowOpacity: 1, shadowRadius: 10, }}> 添加开票员 {this.state.taxRates.map((item) => { return ( {item.isEdit === false ? ( {item.name}{' '} ) : ( { this.setState({ taxRate: value, }); }} value={this.state.taxRate} /> { this.rateConfirm(item); }}> )} ); })} this.submitRate()}> 保存 ); } //显示页面加载 async componentDidMount(): void { let taxRates = this.props.route.params.data; if (taxRates != null || taxRates !== '') { if (taxRates.length > 0) { let list = taxRates.split(','); let userList = list.map((_, i) => ({ key: i, name: list[i], isEdit: false, })); this.setState({ taxRates: this.state.taxRates.concat(userList), taxRate: '', }); } } } //显示侧滑按钮 right = (data) => [ { text: '删除', onPress: () => { this.deleteData(data); }, style: {backgroundColor: 'red', color: 'white'}, }, ]; //删除税率信息 deleteData = (data) => { let listData = this.state.taxRates; const prevIndex = listData.findIndex((item) => item.key === data.key); listData.splice(prevIndex, 1); let userList = listData.map((_, i) => ({ key: i, name: listData[i].name, isEdit: false, })); this.setState({ taxRates: userList, }); }; // 添加税率信息 addRate = () => { let isEdit = false; this.state.taxRates.map((item) => { isEdit = item.isEdit; }); if (isEdit) { ToastShow(1, '存在编辑中的数据,请编辑完成后再添加税率信息!'); } else { let user = { key: this.state.taxRates.length, name: '', isEdit: true, }; this.setState({ taxRates: this.state.taxRates.concat(user), }); } }; // 税率信息确认 rateConfirm = async (data) => { let isRepeat = false; if (this.state.taxRate === '') { ToastShow(1, '请输入税率信息!'); return; } this.state.taxRates.map((item) => { if (item.name === this.state.taxRate) { isRepeat = true; } }); if (isRepeat) { ToastShow(1, '税率信息已存在,请重新输入!'); return; } data.name = this.state.taxRate; data.isEdit = false; this.setState({ taxRates: this.state.taxRates, taxRate: '', }); }; //提交税率信息 submitRate = async () => { let taxRate = ''; let status = 0; if (this.state.taxRates.length > 0) { this.state.taxRates.map((item) => { if (item.isEdit) { status = 1; } else { taxRate += item.name + ','; } }); taxRate = taxRate.substring(0, taxRate.length - 1); } if (status === 1) { ToastShow(1, '存在编辑中的数据,请编辑完成后再点击保存!'); } else { this.props.route.params.getUserTaxRate(taxRate); this.props.navigation.goBack(); } }; } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f0f0f0', }, item_text: { marginRight: 15, color: '#2ecc71', }, });