select_user.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. TextInput,
  7. TouchableOpacity,
  8. ScrollView,
  9. SafeAreaView,
  10. StyleSheet,
  11. } from 'react-native';
  12. import {
  13. List,
  14. SwipeAction,
  15. WingBlank,
  16. WhiteSpace,
  17. } from '@ant-design/react-native';
  18. import public_css from '../../source/css/public_css';
  19. import {ToastShow} from '../toast/toast';
  20. import {IndividualStorageData, RetrieveData} from '../../data/storage';
  21. import {RequestNetwork} from '../../data/encryption';
  22. export default class select_user extends Component {
  23. constructor(props) {
  24. super(props);
  25. this.state = {
  26. type: this.props.route.params.type,
  27. user: [],
  28. userName: '',
  29. };
  30. }
  31. render() {
  32. return (
  33. <SafeAreaView style={[public_css.body, {backgroundColor: '#FCFCFC'}]}>
  34. <WhiteSpace />
  35. <WingBlank>
  36. <TouchableOpacity
  37. onPress={() => {
  38. this.addUser();
  39. }}
  40. style={{
  41. height: 40,
  42. backgroundColor: '#ffffff',
  43. justifyContent: 'center',
  44. alignItems: 'center',
  45. flexDirection: 'row',
  46. elevation: 10,
  47. shadowColor: 'black',
  48. shadowOffset: {width: 0, height: 0},
  49. shadowOpacity: 1,
  50. shadowRadius: 10,
  51. }}>
  52. <Image
  53. source={require('../../source/img/productImg/addIcon.png')}
  54. style={{height: 16, width: 16}}
  55. />
  56. <Text style={{marginLeft: 5, color: '#2A67FE'}}>添加开票员</Text>
  57. </TouchableOpacity>
  58. </WingBlank>
  59. <WhiteSpace />
  60. <ScrollView>
  61. {this.state.user.map((item) => {
  62. return (
  63. <SwipeAction
  64. autoClose
  65. style={{backgroundColor: 'transparent'}}
  66. right={this.right(item)}>
  67. <List.Item>
  68. {item.isEdit === false ? (
  69. <TouchableOpacity
  70. onPress={() => this.selectUser(item)}
  71. style={{
  72. height: 40,
  73. // flexDirection: 'row',
  74. backgroundColor: '#ffffff',
  75. justifyContent: 'center',
  76. elevation: 10,
  77. shadowColor: 'black',
  78. shadowOffset: {width: 0, height: 0},
  79. shadowOpacity: 1,
  80. shadowRadius: 10,
  81. }}>
  82. <Text
  83. style={{
  84. color: '#333333',
  85. fontSize: 16,
  86. fontWeight: 'bold',
  87. marginLeft: 15,
  88. }}>
  89. {item.name}{' '}
  90. </Text>
  91. </TouchableOpacity>
  92. ) : (
  93. <View
  94. style={{
  95. flexDirection: 'row',
  96. justifyContent: 'center',
  97. alignItems: 'center',
  98. height: 40,
  99. // flexDirection: 'row',
  100. backgroundColor: '#ffffff',
  101. elevation: 10,
  102. shadowColor: 'black',
  103. shadowOffset: {width: 0, height: 0},
  104. shadowOpacity: 1,
  105. shadowRadius: 10,
  106. }}>
  107. <View style={{flex: 1}}>
  108. <TextInput
  109. style={{
  110. marginLeft: 15,
  111. color: '#333333',
  112. fontSize: 16,
  113. fontWeight: 'bold',
  114. }}
  115. onChangeText={(value) => {
  116. this.setState({
  117. userName: value,
  118. });
  119. }}
  120. value={this.state.userName}
  121. />
  122. </View>
  123. <View>
  124. <TouchableOpacity
  125. style={{
  126. height: 40,
  127. width: 60,
  128. alignItems: 'center',
  129. justifyContent: 'center',
  130. }}
  131. onPress={() => {
  132. this.userConfirm(item);
  133. }}>
  134. <Image
  135. source={require('../../source/img/select.png')}
  136. style={{height: 16, width: 16}}
  137. />
  138. </TouchableOpacity>
  139. </View>
  140. </View>
  141. )}
  142. </List.Item>
  143. </SwipeAction>
  144. );
  145. })}
  146. </ScrollView>
  147. </SafeAreaView>
  148. );
  149. }
  150. //显示页面加载
  151. async componentDidMount(): void {
  152. let company = JSON.parse(await RetrieveData('company'));
  153. let users = '';
  154. if (this.state.type === 1) {
  155. users = company.payees;
  156. }
  157. if (this.state.type === 2) {
  158. users = company.reviewers;
  159. }
  160. if (this.state.type === 3) {
  161. users = company.drawers;
  162. }
  163. if (users != null || users !== '') {
  164. if (users.length > 0) {
  165. let list = users.split(',');
  166. let userList = list.map((_, i) => ({
  167. key: i,
  168. name: list[i],
  169. isEdit: false,
  170. }));
  171. this.setState({
  172. user: this.state.user.concat(userList),
  173. userName: '',
  174. });
  175. }
  176. }
  177. }
  178. //显示侧滑按钮
  179. right = (data) => [
  180. {
  181. text: '删除',
  182. onPress: () => {
  183. this.deleteData(data);
  184. },
  185. style: {backgroundColor: 'red', color: 'white'},
  186. },
  187. ];
  188. //删除用户信息
  189. deleteData = async (data) => {
  190. let listData = this.state.user;
  191. const prevIndex = listData.findIndex((item) => item.key === data.key);
  192. listData.splice(prevIndex, 1);
  193. let userList = listData.map((_, i) => ({
  194. key: i,
  195. name: listData[i].name,
  196. isEdit: false,
  197. }));
  198. this.setState({
  199. user: userList,
  200. });
  201. let user = '';
  202. if (this.state.user.length > 0) {
  203. this.state.user.map((item) => {
  204. user += item.name + ',';
  205. });
  206. user = user.substring(0, user.length - 1);
  207. }
  208. await this.updateCompany(user);
  209. };
  210. // 添加人员信息
  211. addUser = () => {
  212. let isEdit = false;
  213. this.state.user.map((item) => {
  214. isEdit = item.isEdit;
  215. });
  216. if (isEdit) {
  217. ToastShow(1, '存在编辑中的数据,请编辑完成后再添加人员信息!');
  218. } else {
  219. let user = {
  220. key: this.state.user.length,
  221. name: '',
  222. isEdit: true,
  223. };
  224. this.setState({
  225. user: this.state.user.concat(user),
  226. });
  227. }
  228. };
  229. // 人员信息确认
  230. userConfirm = async (data) => {
  231. let isRepeat = false;
  232. if (this.state.userName === '') {
  233. ToastShow(1, '请输入人员姓名!');
  234. return;
  235. }
  236. this.state.user.map((item) => {
  237. if (item.name === this.state.userName) {
  238. isRepeat = true;
  239. }
  240. });
  241. if (isRepeat) {
  242. ToastShow(1, '人员姓名已存在,请重新输入!');
  243. return;
  244. }
  245. data.name = this.state.userName;
  246. data.isEdit = false;
  247. this.setState({
  248. user: this.state.user,
  249. userName: '',
  250. });
  251. let user = '';
  252. let status = 0;
  253. if (this.state.user.length > 0) {
  254. this.state.user.map((item) => {
  255. if (item.isEdit) {
  256. status = 1;
  257. } else {
  258. user += item.name + ',';
  259. }
  260. });
  261. user = user.substring(0, user.length - 1);
  262. }
  263. if (status === 1) {
  264. ToastShow(1, '存在编辑中的数据,请编辑完成后再选择人员信息!');
  265. } else {
  266. await this.updateCompany(user);
  267. }
  268. };
  269. //提交用户信息
  270. selectUser = async (data) => {
  271. let status = 0;
  272. if (this.state.user.length > 0) {
  273. this.state.user.map((item) => {
  274. if (item.isEdit) {
  275. status = 1;
  276. }
  277. });
  278. }
  279. if (status === 1) {
  280. ToastShow(1, '存在编辑中的数据,请编辑完成后再选择人员信息!');
  281. } else {
  282. this.props.route.params.getUserInfo(this.state.type, data.name);
  283. this.props.navigation.goBack();
  284. }
  285. };
  286. // 更新企业收款人、开票人、审核人
  287. updateCompany = async (user) => {
  288. let company = JSON.parse(await RetrieveData('company'));
  289. const account = await RetrieveData('account');
  290. let type = this.state.type;
  291. let jason = {};
  292. if (type === 1) {
  293. jason = {
  294. entTaxId: company.entTaxId,
  295. entName: company.entName,
  296. entType: company.entType,
  297. payees: user,
  298. reqChannel: 3,
  299. mobile: account,
  300. };
  301. }
  302. if (type === 2) {
  303. jason = {
  304. entTaxId: company.entTaxId,
  305. entName: company.entName,
  306. entType: company.entType,
  307. reviewers: user,
  308. reqChannel: 3,
  309. mobile: account,
  310. };
  311. }
  312. if (type === 3) {
  313. jason = {
  314. entTaxId: company.entTaxId,
  315. entName: company.entName,
  316. entType: company.entType,
  317. drawers: user,
  318. reqChannel: 3,
  319. mobile: account,
  320. };
  321. }
  322. let token = await RetrieveData('token');
  323. if (token) {
  324. const url = '/sys/entInfo/updateBriefInfo';
  325. let response = await RequestNetwork(url, token, jason, false, 1);
  326. if (response) {
  327. if (response.code === 0) {
  328. if (type === 1) {
  329. company.payees = user;
  330. }
  331. if (type === 2) {
  332. company.reviewers = user;
  333. }
  334. if (type === 3) {
  335. company.drawers = user;
  336. }
  337. await IndividualStorageData('company', JSON.stringify(company));
  338. }
  339. }
  340. }
  341. };
  342. }
  343. const styles = StyleSheet.create({
  344. container: {
  345. flex: 1,
  346. backgroundColor: '#f0f0f0',
  347. },
  348. item_text: {
  349. marginRight: 15,
  350. color: '#2ecc71',
  351. },
  352. });