123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- 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 (
- <SafeAreaView style={public_css.body}>
- <WhiteSpace />
- <WingBlank>
- <TouchableOpacity
- onPress={() => {
- 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,
- }}>
- <Image
- source={require('../../../source/img/productImg/addIcon.png')}
- style={{height: 16, width: 16}}
- />
- <Text style={{marginLeft: 5, color: '#2A67FE'}}>添加开票员</Text>
- </TouchableOpacity>
- </WingBlank>
- <WhiteSpace />
- <ScrollView>
- {this.state.taxRates.map((item) => {
- return (
- <SwipeAction
- autoClose
- style={{backgroundColor: 'transparent'}}
- right={this.right(item)}>
- <List.Item>
- {item.isEdit === false ? (
- <View
- style={{
- height: 40,
- // flexDirection: 'row',
- backgroundColor: '#ffffff',
- justifyContent: 'center',
- elevation: 10,
- shadowColor: 'black',
- shadowOffset: {width: 0, height: 0},
- shadowOpacity: 1,
- shadowRadius: 10,
- }}>
- <Text
- style={{
- color: '#333333',
- fontSize: 16,
- fontWeight: 'bold',
- marginLeft: 15,
- }}>
- {item.name}{' '}
- </Text>
- </View>
- ) : (
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'center',
- alignItems: 'center',
- height: 40,
- // flexDirection: 'row',
- backgroundColor: '#ffffff',
- elevation: 10,
- shadowColor: 'black',
- shadowOffset: {width: 0, height: 0},
- shadowOpacity: 1,
- shadowRadius: 10,
- }}>
- <View style={{flex: 1}}>
- <TextInput
- style={{
- marginLeft: 15,
- color: '#333333',
- fontSize: 16,
- fontWeight: 'bold',
- }}
- onChangeText={(value) => {
- this.setState({
- taxRate: value,
- });
- }}
- value={this.state.taxRate}
- />
- </View>
- <View>
- <TouchableOpacity
- style={{
- height: 40,
- width: 60,
- alignItems: 'center',
- justifyContent: 'center',
- }}
- onPress={() => {
- this.rateConfirm(item);
- }}>
- <Image
- source={require('../../../source/img/select.png')}
- style={{height: 16, width: 16}}
- />
- </TouchableOpacity>
- </View>
- </View>
- )}
- </List.Item>
- </SwipeAction>
- );
- })}
- </ScrollView>
- <WingBlank>
- <View style={public_css.bottomStatus}>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusRBtn]}
- onPress={() => this.submitRate()}>
- <Text style={{color: '#fff'}}>保存</Text>
- </TouchableOpacity>
- </View>
- </WingBlank>
- <WhiteSpace />
- </SafeAreaView>
- );
- }
- //显示页面加载
- 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',
- },
- });
|