enterprise_user.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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} 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. export default class enterprise_user extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. type: this.props.route.params.type,
  29. user: [],
  30. userName: '',
  31. };
  32. }
  33. render() {
  34. return (
  35. <View
  36. style={{
  37. flex: 1,
  38. backgroundColor: '#ffffff',
  39. display: 'flex',
  40. }}>
  41. <View style={{alignItems: 'center'}}>
  42. <View style={[public_css.view, public_css.lineTopBottom]}>
  43. <Text style={public_css.text}>人员添加:</Text>
  44. <TextInput
  45. style={public_css.textInputStyle}
  46. placeholder="请输入需要添加的人员姓名"
  47. clearButtonMode="while-editing"
  48. secureTextEntry={false}
  49. onChangeText={value => {
  50. this.setState({
  51. userName: value,
  52. });
  53. }}
  54. value={this.state.userName}
  55. />
  56. <View>
  57. <TouchableOpacity
  58. onPress={() => {
  59. this.addUser();
  60. }}>
  61. <Image
  62. source={require('../../source/img/productImg/addIcon.png')}
  63. style={{height: 16, width: 16}}
  64. />
  65. </TouchableOpacity>
  66. </View>
  67. </View>
  68. </View>
  69. <View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
  70. <View />
  71. <View style={{margin: 5}}>
  72. <Text>人员姓名</Text>
  73. </View>
  74. <View style={{margin: 5}}>
  75. <Text>排序</Text>
  76. </View>
  77. </View>
  78. <View style={{flex: 1}}>
  79. <SafeAreaView style={{backgroundColor: '#fff', flex: 1}}>
  80. <ScrollView
  81. ref={scrollView => (this.scrollView = scrollView)}
  82. scrollEnabled={this.state.scrollEnabled}
  83. style={styles.container}>
  84. <DragSortableView
  85. dataSource={this.state.user}
  86. parentWidth={parentWidth}
  87. childrenWidth={childrenWidth}
  88. childrenHeight={childrenHeight}
  89. scaleStatus={'scaleY'}
  90. onDragStart={(startIndex, endIndex) => {
  91. this.setState({
  92. scrollEnabled: false,
  93. });
  94. }}
  95. onDragEnd={startIndex => {
  96. this.setState({
  97. scrollEnabled: true,
  98. });
  99. }}
  100. onDataChange={data => {
  101. this.setState({
  102. user: data,
  103. });
  104. }}
  105. // keyExtractor={(item, index) => item.key} // FlatList作用一样,优化
  106. onClickItem={(data, item, index) => {}}
  107. renderItem={(item, index) => {
  108. return this.renderItem(item, index);
  109. }}
  110. />
  111. </ScrollView>
  112. </SafeAreaView>
  113. </View>
  114. <View style={public_css.bottomStaus}>
  115. <TouchableOpacity
  116. style={[public_css.statusBtn, public_css.statusLBtn]}
  117. onPress={() => {
  118. this.setState({
  119. user: '',
  120. userName: '',
  121. });
  122. }}>
  123. <Image
  124. source={require('../../source/img/productImg/clear.png')}
  125. style={{width: 32, height: 32}}
  126. />
  127. <Text>全部清除</Text>
  128. </TouchableOpacity>
  129. <TouchableOpacity
  130. style={[public_css.statusBtn, public_css.statusRBtn]}
  131. onPress={() => this.submitData()}>
  132. <Image
  133. source={require('../../source/img/productImg/confirm.png')}
  134. style={{width: 32, height: 32}}
  135. />
  136. <Text style={{color: '#fff'}}>确定</Text>
  137. </TouchableOpacity>
  138. </View>
  139. </View>
  140. );
  141. }
  142. //显示页面加载
  143. componentDidMount(): void {
  144. if (this.props.route.params.type == 1) {
  145. let payees = this.props.route.params.data.state.payees;
  146. if (payees != null) {
  147. if (payees.length > 0) {
  148. let list = payees.split(',');
  149. let userList = list.map((_, i) => ({
  150. key: i,
  151. name: list[i],
  152. }));
  153. this.setState({
  154. user: this.state.user.concat(userList),
  155. userName: '',
  156. });
  157. }
  158. }
  159. }
  160. if (this.props.route.params.type == 2) {
  161. let reviewers = this.props.route.params.data.state.reviewers;
  162. if (reviewers != null) {
  163. if (reviewers.length > 0) {
  164. let list = reviewers.split(',');
  165. let userList = list.map((_, i) => ({
  166. key: i,
  167. name: list[i],
  168. }));
  169. this.setState({
  170. user: this.state.user.concat(userList),
  171. userName: '',
  172. });
  173. }
  174. }
  175. }
  176. }
  177. //关闭页面加载
  178. componentWillUnmount(): void {
  179. this.timer && clearTimeout(this.timer);
  180. }
  181. //加载客户列表数据
  182. renderItem = data => (
  183. <View style={styles.item}>
  184. <SwipeAction
  185. autoClose
  186. style={{backgroundColor: 'transparent', flex: 1}}
  187. right={this.right(data)}>
  188. <View style={styles.item_children}>
  189. <Text
  190. style={{
  191. fontSize: 18,
  192. fontFamily: 'PingFang-SC-Regular',
  193. color: '#333333',
  194. textAlign: 'center',
  195. flex: 1,
  196. }}>
  197. {data.name}
  198. </Text>
  199. </View>
  200. </SwipeAction>
  201. <Image source={require('../../source/img/category.png')} />
  202. </View>
  203. );
  204. //显示侧滑按钮
  205. right = data => [
  206. {
  207. text: '删除',
  208. onPress: () => {
  209. this.deleteData(data);
  210. },
  211. style: {backgroundColor: 'red', color: 'white'},
  212. },
  213. ];
  214. //删除用户信息
  215. deleteData = data => {
  216. let listData = this.state.user;
  217. const prevIndex = listData.findIndex(item => item.key === data.key);
  218. listData.splice(prevIndex, 1);
  219. let userList = listData.map((_, i) => ({
  220. key: i,
  221. name: listData[i].name,
  222. }));
  223. this.setState({
  224. user: userList,
  225. });
  226. };
  227. //添加人员信息
  228. addUser = () => {
  229. if (this.state.userName.length > 0) {
  230. let user = {
  231. key: this.state.user.length,
  232. name: this.state.userName,
  233. };
  234. this.setState({
  235. user: this.state.user.concat(user),
  236. userName: '',
  237. });
  238. } else {
  239. ShowToast('请输入人员姓名!');
  240. return;
  241. }
  242. };
  243. //提交用户信息
  244. submitData = () => {
  245. let user = '';
  246. if (this.state.user.length > 0) {
  247. this.state.user.map((_, i) => {
  248. user = user + this.state.user[i].name + ',';
  249. });
  250. user = user.substring(0, user.length - 1);
  251. }
  252. if (this.state.type == 1) {
  253. this.props.route.params.data.setPayees(user);
  254. }
  255. if (this.state.type == 2) {
  256. this.props.route.params.data.setReviewers(user);
  257. }
  258. this.props.navigation.goBack();
  259. };
  260. }
  261. const styles = StyleSheet.create({
  262. container: {
  263. flex: 1,
  264. backgroundColor: '#f0f0f0',
  265. },
  266. item: {
  267. width: childrenWidth,
  268. height: childrenHeight,
  269. flexDirection: 'row',
  270. justifyContent: 'center',
  271. alignItems: 'center',
  272. backgroundColor: '#ffffff',
  273. borderBottomWidth: 3 / PixelRatio.get(),
  274. borderColor: 'rgb(208,208,208)',
  275. },
  276. item_children: {
  277. width: childrenWidth,
  278. height: childrenHeight - 4,
  279. backgroundColor: '#ffffff',
  280. flexDirection: 'row',
  281. alignItems: 'center',
  282. },
  283. item_icon: {
  284. width: childrenHeight * 0.6,
  285. height: childrenHeight * 0.6,
  286. marginLeft: 15,
  287. resizeMode: 'contain',
  288. },
  289. item_text: {
  290. marginRight: 15,
  291. color: '#2ecc71',
  292. },
  293. });