invoice_user.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. FlatList,
  7. TextInput,
  8. TouchableOpacity,
  9. DeviceEventEmitter,
  10. ScrollView,
  11. SafeAreaView,
  12. StyleSheet,
  13. Dimensions,
  14. PixelRatio,
  15. } from 'react-native';
  16. import {List, SwipeAction, WhiteSpace, Radio} from '@ant-design/react-native';
  17. import DragSortableView from 'react-native-drag-sort/DragSortableView';
  18. import {ShowToast} from '../../components/rootToast/root_toast';
  19. import public_css from '../../source/css/public_css';
  20. const {width} = Dimensions.get('window');
  21. const parentWidth = width;
  22. const childrenWidth = width;
  23. const childrenHeight = 48;
  24. const RadioItem = Radio.RadioItem;
  25. export default class invoice_user extends Component {
  26. constructor(props) {
  27. super(props);
  28. this.state = {
  29. type: this.props.route.params.type,
  30. user: [],
  31. userName: '',
  32. };
  33. }
  34. render() {
  35. return (
  36. <View
  37. style={{
  38. flex: 1,
  39. backgroundColor: '#ffffff',
  40. display: 'flex',
  41. }}>
  42. <View style={{alignItems: 'center'}}>
  43. <View style={[public_css.view, public_css.lineTopBottom]}>
  44. <Text style={public_css.text}>人员添加:</Text>
  45. <TextInput
  46. style={public_css.textInputStyle}
  47. placeholder="请输入需要添加的人员姓名"
  48. clearButtonMode="while-editing"
  49. secureTextEntry={false}
  50. onChangeText={value => {
  51. this.setState({
  52. userName: value,
  53. });
  54. }}
  55. value={this.state.userName}
  56. />
  57. <View>
  58. <TouchableOpacity
  59. onPress={() => {
  60. this.addUser();
  61. }}>
  62. <Image
  63. source={require('../../source/img/productImg/addIcon.png')}
  64. style={{height: 16, width: 16}}
  65. />
  66. </TouchableOpacity>
  67. </View>
  68. </View>
  69. </View>
  70. <View style={{alignItems: 'center', margin: 5}}>
  71. <Text>人员姓名</Text>
  72. </View>
  73. <View style={{flex: 1}}>
  74. <FlatList
  75. data={this.state.user}
  76. renderItem={item => this.renderItem(item)}
  77. />
  78. </View>
  79. <View style={public_css.bottomStaus}>
  80. <TouchableOpacity
  81. style={[public_css.statusBtn, public_css.statusLBtn]}
  82. onPress={() => {
  83. this.setState({
  84. user: '',
  85. userName: '',
  86. });
  87. }}>
  88. <Image
  89. source={require('../../source/img/productImg/clear.png')}
  90. style={{width: 32, height: 32}}
  91. />
  92. <Text>全部清除</Text>
  93. </TouchableOpacity>
  94. <TouchableOpacity
  95. style={[public_css.statusBtn, public_css.statusRBtn]}
  96. onPress={() => this.submitData()}>
  97. <Image
  98. source={require('../../source/img/productImg/confirm.png')}
  99. style={{width: 32, height: 32}}
  100. />
  101. <Text style={{color: '#fff'}}>确定</Text>
  102. </TouchableOpacity>
  103. </View>
  104. </View>
  105. );
  106. }
  107. //显示页面加载
  108. componentDidMount(): void {
  109. if (this.props.route.params.type == 1) {
  110. let payees = this.props.route.params.data.state.payees;
  111. if (payees != null || payees != '') {
  112. if (payees.length > 0) {
  113. let list = payees.split(',');
  114. let userList = list.map((_, i) => ({
  115. key: i,
  116. name: list[i],
  117. }));
  118. this.setState({
  119. user: this.state.user.concat(userList),
  120. userName: '',
  121. });
  122. }
  123. }
  124. }
  125. if (this.props.route.params.type == 2) {
  126. let reviewers = this.props.route.params.data.state.reviewers;
  127. if (reviewers != null) {
  128. if (reviewers.length > 0) {
  129. let list = reviewers.split(',');
  130. let userList = list.map((_, i) => ({
  131. key: i,
  132. name: list[i],
  133. }));
  134. this.setState({
  135. user: this.state.user.concat(userList),
  136. userName: '',
  137. });
  138. }
  139. }
  140. }
  141. }
  142. //关闭页面加载
  143. componentWillUnmount(): void {
  144. this.timer && clearTimeout(this.timer);
  145. }
  146. //显示侧滑按钮
  147. right = data => [
  148. {
  149. text: '删除',
  150. onPress: () => {
  151. this.deleteData(data);
  152. },
  153. style: {backgroundColor: 'red', color: 'white'},
  154. },
  155. ];
  156. //删除用户信息
  157. deleteData = data => {
  158. let listData = this.state.user;
  159. const prevIndex = listData.findIndex(item => item.key === data.key);
  160. listData.splice(prevIndex, 1);
  161. let userList = listData.map((_, i) => ({
  162. key: i,
  163. name: listData[i].name,
  164. }));
  165. this.setState({
  166. user: userList,
  167. });
  168. };
  169. //添加人员信息
  170. addUser = () => {
  171. if (this.state.userName.length > 0) {
  172. let user = {
  173. key: this.state.user.length,
  174. name: this.state.userName,
  175. };
  176. this.setState({
  177. user: this.state.user.concat(user),
  178. userName: '',
  179. });
  180. } else {
  181. ShowToast('请输入人员姓名!');
  182. return;
  183. }
  184. };
  185. //提交用户信息
  186. submitData = (data) => {
  187. if (this.state.type == 1) {
  188. this.props.route.params.data.setPayees(data.name);
  189. }
  190. if (this.state.type == 2) {
  191. this.props.route.params.data.setReviewers(data.name);
  192. }
  193. this.props.navigation.goBack();
  194. };
  195. //加载items
  196. renderItem = data => (
  197. <SwipeAction
  198. autoClose
  199. style={{backgroundColor: 'transparent'}}
  200. right={this.right(data)}>
  201. <List.Item onPress={() => this.submitData(data.item)}>
  202. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  203. <Text>{data.item.name} </Text>
  204. </View>
  205. </List.Item>
  206. </SwipeAction>
  207. );
  208. }
  209. const styles = StyleSheet.create({
  210. container: {
  211. flex: 1,
  212. backgroundColor: '#f0f0f0',
  213. },
  214. item: {
  215. width: childrenWidth,
  216. height: childrenHeight,
  217. flexDirection: 'row',
  218. justifyContent: 'center',
  219. alignItems: 'center',
  220. backgroundColor: '#ffffff',
  221. borderBottomWidth: 3 / PixelRatio.get(),
  222. borderColor: 'rgb(208,208,208)',
  223. },
  224. item_children: {
  225. width: childrenWidth,
  226. height: childrenHeight - 4,
  227. backgroundColor: '#ffffff',
  228. flexDirection: 'row',
  229. alignItems: 'center',
  230. },
  231. item_icon: {
  232. width: childrenHeight * 0.6,
  233. height: childrenHeight * 0.6,
  234. marginLeft: 15,
  235. resizeMode: 'contain',
  236. },
  237. item_text: {
  238. marginRight: 15,
  239. color: '#2ecc71',
  240. },
  241. });