personnel_list.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. Dimensions,
  6. FlatList,
  7. RefreshControl,
  8. ActivityIndicator,
  9. DeviceEventEmitter,
  10. } from 'react-native';
  11. import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
  12. import {RetrieveData} from '../../data/storage';
  13. import {GetDataPost} from '../../data/encryption';
  14. import personnel_css from './personnel_css';
  15. import {ShowToast} from '../../components/rootToast/root_toast';
  16. let pageNo = 1; //当前第几页
  17. let totalPage = 5; //总的页数
  18. export default class personnel_list extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.props.navigation.dangerouslyGetParent().setOptions({
  22. tabBarVisible: false,
  23. });
  24. this.state = {
  25. listData: [],
  26. search_data: '',
  27. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  28. user_type: 1,
  29. isLoading: false,
  30. };
  31. }
  32. render() {
  33. return (
  34. <View style={{flex: 1, backgroundColor: '#ffffff'}}>
  35. <View
  36. style={{
  37. width: Dimensions.get('window').width,
  38. alignItems: 'center',
  39. justifyContent: 'center',
  40. backgroundColor: '#ffffff',
  41. height: 50,
  42. }}>
  43. <SearchBar
  44. placeholder="搜索"
  45. value={this.state.search_data}
  46. // onSubmit={value => Alert.alert(value)}
  47. onCancel={() => this.searchClear()}
  48. onChange={(value) => this.searchData(value)}
  49. showCancelButton={false}
  50. style={{borderRadius: 15}}
  51. />
  52. </View>
  53. <View style={personnel_css.container}>
  54. <FlatList
  55. data={this.state.listData}
  56. renderItem={(item) => this.renderItem(item)}
  57. refreshControl={
  58. <RefreshControl
  59. title={'加载中...'}
  60. colors={['#B7B7B7']} //此颜色无效
  61. tintColor={'#B7B7B7'}
  62. titleColor={'#B7B7B7'} //只有ios有效
  63. refreshing={this.state.isLoading}
  64. onRefresh={() => {
  65. this.initData();
  66. }}
  67. />
  68. }
  69. ListFooterComponent={this._renderFooter.bind(this)}
  70. onEndReached={this._onEndReached.bind(this)}
  71. onEndReachedThreshold={0.1}
  72. />
  73. </View>
  74. </View>
  75. );
  76. }
  77. //搜索数据
  78. searchData = (value) => {
  79. this.setState({
  80. search_data: value,
  81. });
  82. this.timer = setTimeout(() => {
  83. this.initData();
  84. }, 1000);
  85. };
  86. //清空搜索
  87. searchClear = () => {
  88. this.setState({
  89. search_data: '',
  90. });
  91. this.initData();
  92. };
  93. //数据初始化
  94. initData = () => {
  95. this.setState({
  96. listData: [],
  97. isLoading: false,
  98. showFoot: 0,
  99. });
  100. pageNo = 1;
  101. this.getPersonnelData();
  102. };
  103. //上拉加载
  104. _onEndReached() {
  105. if (this.state.showFoot === 0) {
  106. if (pageNo >= totalPage) {
  107. this.setState({showFoot: 1});
  108. return;
  109. } else {
  110. pageNo++;
  111. this.setState({showFoot: 2});
  112. //获取数据
  113. this.getPersonnelData();
  114. }
  115. }
  116. }
  117. //显示list尾部
  118. _renderFooter() {
  119. if (this.state.showFoot === 1) {
  120. return (
  121. <View
  122. style={{
  123. height: 30,
  124. alignItems: 'center',
  125. justifyContent: 'flex-start',
  126. }}>
  127. <Text
  128. style={{
  129. color: '#999999',
  130. fontSize: 14,
  131. marginTop: 5,
  132. marginBottom: 5,
  133. }}>
  134. 没有更多数据了
  135. </Text>
  136. </View>
  137. );
  138. } else if (this.state.showFoot === 2) {
  139. return (
  140. <View style={personnel_css.footer}>
  141. <ActivityIndicator />
  142. <Text>正在加载更多数据...</Text>
  143. </View>
  144. );
  145. } else if (this.state.showFoot === 0) {
  146. return (
  147. <View style={personnel_css.footer}>
  148. <Text />
  149. </View>
  150. );
  151. }
  152. }
  153. //显示页面加载
  154. componentDidMount(): void {
  155. this.getPersonnelData();
  156. this.getUserType();
  157. //收到监听
  158. this.listener = DeviceEventEmitter.addListener('刷新用户列表', (data) => {
  159. //收到监听后想做的事情
  160. this.initData();
  161. });
  162. }
  163. //获取用户类型
  164. getUserType = async () => {
  165. let userType = await RetrieveData('usertype');
  166. userType = userType.substring(1, userType.length - 1);
  167. this.setState({
  168. user_type: userType,
  169. });
  170. };
  171. //关闭页面加载
  172. componentWillUnmount(): void {
  173. pageNo = 1;
  174. this.timer && clearTimeout(this.timer);
  175. //移除监听
  176. if (this.listener) {
  177. this.listener.remove();
  178. }
  179. }
  180. //获取用户数据
  181. getPersonnelData = async () => {
  182. let account = await RetrieveData('account');
  183. let token = await RetrieveData('token');
  184. if (token && account) {
  185. account = account.substring(1, account.length - 1);
  186. token = token.substring(1, token.length - 1);
  187. const url = 'https://app.taxbk.cn:9443/auth/comm/user/findChildUsers';
  188. let response = await GetDataPost(
  189. url,
  190. token,
  191. {
  192. currentUserMobile: account,
  193. reqChannel: 3,
  194. pageNum: pageNo,
  195. pageSize: 10,
  196. name: this.state.search_data,
  197. },
  198. false,
  199. 2,
  200. );
  201. if (response) {
  202. if (response.code == 0) {
  203. totalPage = response.data.pages;
  204. this.setList(response.data.records);
  205. }
  206. }
  207. }
  208. };
  209. //设置客户数据列表
  210. setList = (data) => {
  211. let listDatas = data.map((_, i) => ({
  212. key: data[i].id,
  213. name: data[i].name,
  214. mobile: data[i].mobile,
  215. status: data[i].status,
  216. deptId: data[i].deptId,
  217. userType: data[i].userType,
  218. manageUserId: data[i].manageUserId,
  219. deptName: data[i].deptName,
  220. }));
  221. let list = this.state.listData.concat(listDatas);
  222. this.setState({
  223. listData: list,
  224. showFoot: 0,
  225. });
  226. };
  227. //加载客户列表数据
  228. renderItem = (data) => (
  229. <SwipeAction
  230. autoClose
  231. style={{backgroundColor: 'transparent'}}
  232. right={this.right(data)}>
  233. <List.Item
  234. onPress={() => {
  235. // this.props.navigation.navigate('enterprise_see', {
  236. // enterprise: data.item,
  237. // });
  238. }}>
  239. <View style={{flex: 1}}>
  240. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  241. <View style={{flex: 1, alignItems: 'center'}}>
  242. <Text
  243. style={{
  244. fontSize: 18,
  245. fontFamily: 'PingFang-SC-Regular',
  246. color: '#333333',
  247. }}>
  248. {data.item.name}
  249. </Text>
  250. </View>
  251. <View style={{flex: 1, alignItems: 'center'}}>
  252. <Text
  253. style={{
  254. fontSize: 18,
  255. fontFamily: 'PingFang-SC-Regular',
  256. color: '#333333',
  257. }}>
  258. {data.item.mobile}
  259. </Text>
  260. </View>
  261. </View>
  262. </View>
  263. </List.Item>
  264. </SwipeAction>
  265. );
  266. //显示侧滑按钮
  267. right = (data) => [
  268. {
  269. text: '编辑',
  270. onPress: () =>
  271. this.props.navigation.navigate('personnel_edit', {
  272. personnel: data.item,
  273. }),
  274. style: {backgroundColor: 'orange', color: 'white'},
  275. },
  276. {
  277. text: '删除',
  278. onPress: () => {
  279. this.deleteData(data.item);
  280. },
  281. style: {backgroundColor: 'red', color: 'white'},
  282. },
  283. ];
  284. //提交数据
  285. submitData = () => {
  286. //服务商
  287. if (this.state.user_type == 2) {
  288. this.deletedIspUser();
  289. }
  290. //运营商
  291. if (this.state.user_type == 3) {
  292. this.deletedAuthUser();
  293. }
  294. };
  295. //删除服务商用户
  296. deletedIspUser = async () => {
  297. let account = await RetrieveData('account');
  298. let token = await RetrieveData('token');
  299. if (token && account) {
  300. account = account.substring(1, account.length - 1);
  301. token = token.substring(1, token.length - 1);
  302. const url = 'https://app.taxbk.cn:9443/auth/isp/user/delete';
  303. let response = await GetDataPost(
  304. url,
  305. token,
  306. {
  307. mobile: '',
  308. currentUserMobile: account,
  309. reqChannel: 3,
  310. },
  311. false,
  312. 1,
  313. );
  314. if (response) {
  315. if (response.code == 0) {
  316. ShowToast('删除成功!');
  317. } else {
  318. ShowToast('删除失败!');
  319. }
  320. }
  321. }
  322. };
  323. //删除运营商用户
  324. deletedAuthUser = async () => {
  325. let account = await RetrieveData('account');
  326. let token = await RetrieveData('token');
  327. if (token && account) {
  328. account = account.substring(1, account.length - 1);
  329. token = token.substring(1, token.length - 1);
  330. const url = 'https://app.taxbk.cn:9443/auth/oper/user/delete';
  331. let response = await GetDataPost(
  332. url,
  333. token,
  334. {
  335. mobile: '',
  336. currentUserMobile: account,
  337. reqChannel: 3,
  338. },
  339. false,
  340. 1,
  341. );
  342. if (response) {
  343. if (response.code == 0) {
  344. ShowToast('删除成功!');
  345. } else {
  346. ShowToast('删除失败!');
  347. }
  348. }
  349. }
  350. };
  351. }