enterprise_tax_rate.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. FlatList,
  7. TextInput,
  8. TouchableOpacity,
  9. ScrollView,
  10. SafeAreaView,
  11. StyleSheet,
  12. } from 'react-native';
  13. import { List, SwipeAction, WhiteSpace, WingBlank } from "@ant-design/react-native";
  14. import public_css from '../../../source/css/public_css';
  15. import {ToastShow} from '../../../components/toast/toast';
  16. export default class enterprise_tax_rate extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. taxRates: [],
  21. taxRate: '',
  22. };
  23. }
  24. render() {
  25. return (
  26. <SafeAreaView style={public_css.body}>
  27. <WhiteSpace />
  28. <WingBlank>
  29. <TouchableOpacity
  30. onPress={() => {
  31. this.addRate();
  32. }}
  33. style={{
  34. height: 40,
  35. backgroundColor: '#ffffff',
  36. justifyContent: 'center',
  37. alignItems: 'center',
  38. flexDirection: 'row',
  39. elevation: 10,
  40. shadowColor: 'black',
  41. shadowOffset: {width: 0, height: 0},
  42. shadowOpacity: 1,
  43. shadowRadius: 10,
  44. }}>
  45. <Image
  46. source={require('../../../source/img/productImg/addIcon.png')}
  47. style={{height: 16, width: 16}}
  48. />
  49. <Text style={{marginLeft: 5, color: '#2A67FE'}}>添加开票员</Text>
  50. </TouchableOpacity>
  51. </WingBlank>
  52. <WhiteSpace />
  53. <ScrollView>
  54. {this.state.taxRates.map((item) => {
  55. return (
  56. <SwipeAction
  57. autoClose
  58. style={{backgroundColor: 'transparent'}}
  59. right={this.right(item)}>
  60. <List.Item>
  61. {item.isEdit === false ? (
  62. <View
  63. style={{
  64. height: 40,
  65. // flexDirection: 'row',
  66. backgroundColor: '#ffffff',
  67. justifyContent: 'center',
  68. elevation: 10,
  69. shadowColor: 'black',
  70. shadowOffset: {width: 0, height: 0},
  71. shadowOpacity: 1,
  72. shadowRadius: 10,
  73. }}>
  74. <Text
  75. style={{
  76. color: '#333333',
  77. fontSize: 16,
  78. fontWeight: 'bold',
  79. marginLeft: 15,
  80. }}>
  81. {item.name}{' '}
  82. </Text>
  83. </View>
  84. ) : (
  85. <View
  86. style={{
  87. flexDirection: 'row',
  88. justifyContent: 'center',
  89. alignItems: 'center',
  90. height: 40,
  91. // flexDirection: 'row',
  92. backgroundColor: '#ffffff',
  93. elevation: 10,
  94. shadowColor: 'black',
  95. shadowOffset: {width: 0, height: 0},
  96. shadowOpacity: 1,
  97. shadowRadius: 10,
  98. }}>
  99. <View style={{flex: 1}}>
  100. <TextInput
  101. style={{
  102. marginLeft: 15,
  103. color: '#333333',
  104. fontSize: 16,
  105. fontWeight: 'bold',
  106. }}
  107. onChangeText={(value) => {
  108. this.setState({
  109. taxRate: value,
  110. });
  111. }}
  112. value={this.state.taxRate}
  113. />
  114. </View>
  115. <View>
  116. <TouchableOpacity
  117. style={{
  118. height: 40,
  119. width: 60,
  120. alignItems: 'center',
  121. justifyContent: 'center',
  122. }}
  123. onPress={() => {
  124. this.rateConfirm(item);
  125. }}>
  126. <Image
  127. source={require('../../../source/img/select.png')}
  128. style={{height: 16, width: 16}}
  129. />
  130. </TouchableOpacity>
  131. </View>
  132. </View>
  133. )}
  134. </List.Item>
  135. </SwipeAction>
  136. );
  137. })}
  138. </ScrollView>
  139. <WingBlank>
  140. <View style={public_css.bottomStatus}>
  141. <TouchableOpacity
  142. style={[public_css.statusBtn, public_css.statusRBtn]}
  143. onPress={() => this.submitRate()}>
  144. <Text style={{color: '#fff'}}>保存</Text>
  145. </TouchableOpacity>
  146. </View>
  147. </WingBlank>
  148. <WhiteSpace />
  149. </SafeAreaView>
  150. );
  151. }
  152. //显示页面加载
  153. async componentDidMount(): void {
  154. let taxRates = this.props.route.params.data;
  155. if (taxRates != null || taxRates !== '') {
  156. if (taxRates.length > 0) {
  157. let list = taxRates.split(',');
  158. let userList = list.map((_, i) => ({
  159. key: i,
  160. name: list[i],
  161. isEdit: false,
  162. }));
  163. this.setState({
  164. taxRates: this.state.taxRates.concat(userList),
  165. taxRate: '',
  166. });
  167. }
  168. }
  169. }
  170. //显示侧滑按钮
  171. right = (data) => [
  172. {
  173. text: '删除',
  174. onPress: () => {
  175. this.deleteData(data);
  176. },
  177. style: {backgroundColor: 'red', color: 'white'},
  178. },
  179. ];
  180. //删除税率信息
  181. deleteData = (data) => {
  182. let listData = this.state.taxRates;
  183. const prevIndex = listData.findIndex((item) => item.key === data.key);
  184. listData.splice(prevIndex, 1);
  185. let userList = listData.map((_, i) => ({
  186. key: i,
  187. name: listData[i].name,
  188. isEdit: false,
  189. }));
  190. this.setState({
  191. taxRates: userList,
  192. });
  193. };
  194. // 添加税率信息
  195. addRate = () => {
  196. let isEdit = false;
  197. this.state.taxRates.map((item) => {
  198. isEdit = item.isEdit;
  199. });
  200. if (isEdit) {
  201. ToastShow(1, '存在编辑中的数据,请编辑完成后再添加税率信息!');
  202. } else {
  203. let user = {
  204. key: this.state.taxRates.length,
  205. name: '',
  206. isEdit: true,
  207. };
  208. this.setState({
  209. taxRates: this.state.taxRates.concat(user),
  210. });
  211. }
  212. };
  213. // 税率信息确认
  214. rateConfirm = async (data) => {
  215. let isRepeat = false;
  216. if (this.state.taxRate === '') {
  217. ToastShow(1, '请输入税率信息!');
  218. return;
  219. }
  220. this.state.taxRates.map((item) => {
  221. if (item.name === this.state.taxRate) {
  222. isRepeat = true;
  223. }
  224. });
  225. if (isRepeat) {
  226. ToastShow(1, '税率信息已存在,请重新输入!');
  227. return;
  228. }
  229. data.name = this.state.taxRate;
  230. data.isEdit = false;
  231. this.setState({
  232. taxRates: this.state.taxRates,
  233. taxRate: '',
  234. });
  235. };
  236. //提交税率信息
  237. submitRate = async () => {
  238. let taxRate = '';
  239. let status = 0;
  240. if (this.state.taxRates.length > 0) {
  241. this.state.taxRates.map((item) => {
  242. if (item.isEdit) {
  243. status = 1;
  244. } else {
  245. taxRate += item.name + ',';
  246. }
  247. });
  248. taxRate = taxRate.substring(0, taxRate.length - 1);
  249. }
  250. if (status === 1) {
  251. ToastShow(1, '存在编辑中的数据,请编辑完成后再点击保存!');
  252. } else {
  253. this.props.route.params.getUserTaxRate(taxRate);
  254. this.props.navigation.goBack();
  255. }
  256. };
  257. }
  258. const styles = StyleSheet.create({
  259. container: {
  260. flex: 1,
  261. backgroundColor: '#f0f0f0',
  262. },
  263. item_text: {
  264. marginRight: 15,
  265. color: '#2ecc71',
  266. },
  267. });