enterprise_user.js 7.9 KB

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