enterprise_information.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. Dimensions,
  7. FlatList,
  8. RefreshControl,
  9. ActivityIndicator,
  10. DeviceEventEmitter,
  11. } from 'react-native';
  12. import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
  13. import {RetrieveData} from '../../data/storage';
  14. import {GetDataPost} from '../../data/encryption';
  15. import {ShowToast} from '../../components/rootToast/root_toast';
  16. import enterprise_css from './enterprise_css';
  17. let pageNo = 1; //当前第几页
  18. let totalPage = 5; //总的页数
  19. export default class enterprise_information extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.props.navigation.dangerouslyGetParent().setOptions({
  23. tabBarVisible: false,
  24. });
  25. this.state = {
  26. listData: [],
  27. search_data: '',
  28. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  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={enterprise_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.getCustomerData();
  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.getCustomerData();
  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={enterprise_css.footer}>
  141. <ActivityIndicator />
  142. <Text>正在加载更多数据...</Text>
  143. </View>
  144. );
  145. } else if (this.state.showFoot === 0) {
  146. return (
  147. <View style={enterprise_css.footer}>
  148. <Text />
  149. </View>
  150. );
  151. }
  152. }
  153. //显示页面加载
  154. componentDidMount(): void {
  155. this.getCustomerData();
  156. //收到监听
  157. this.listener = DeviceEventEmitter.addListener('企业信息刷新', (data) => {
  158. //收到监听后想做的事情
  159. this.initData();
  160. });
  161. }
  162. //关闭页面加载
  163. componentWillUnmount(): void {
  164. pageNo = 1;
  165. this.timer && clearTimeout(this.timer);
  166. //移除监听
  167. if (this.listener) {
  168. this.listener.remove();
  169. }
  170. }
  171. //获取客户数据
  172. getCustomerData = async () => {
  173. let account = await RetrieveData('account');
  174. let token = await RetrieveData('token');
  175. if (token && account) {
  176. account = account.substring(1, account.length - 1);
  177. token = token.substring(1, token.length - 1);
  178. const url = 'https://app.taxbk.cn:9443/sys/entInfo/findPageByMobile';
  179. GetDataPost(
  180. url,
  181. token,
  182. {
  183. userMobile: account,
  184. reqChannel: 3,
  185. pageNum: pageNo,
  186. pageSize: 10,
  187. entName: this.state.search_data,
  188. },
  189. false,
  190. 2,
  191. ).then((res) => {
  192. totalPage = res.data.pages;
  193. this.setList(res.data.records);
  194. });
  195. }
  196. };
  197. //设置客户数据列表
  198. setList = (data) => {
  199. let listDatas = data.map((_, i) => ({
  200. key: data[i].entInfoId,
  201. entTaxId: data[i].entTaxId,
  202. entName: data[i].entName,
  203. entAddress: data[i].entAddress,
  204. entContactPerson: data[i].entContactPerson,
  205. entLegelPerson: data[i].entLegelPerson,
  206. entTaxOfficeCode: data[i].entTaxOfficeCode,
  207. taxDiscId: data[i].taxDiscId,
  208. lastMachineId: data[i].lastMachineId,
  209. serviceStatus: data[i].serviceStatus,
  210. ukeyInitStatus: data[i].ukeyInitStatus,
  211. ukeyInitTime: data[i].ukeyInitTime,
  212. certInitStatus: data[i].certInitStatus,
  213. certInitTime: data[i].certInitTime,
  214. availableTaxes: data[i].availableTaxes,
  215. entPhone: data[i].entPhone,
  216. bankAccountName: data[i].bankAccountName,
  217. bankAccountNumber: data[i].bankAccountNumber,
  218. payees: data[i].payees,
  219. reviewers: data[i].reviewers,
  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. <List.Item
  231. onPress={() => {
  232. this.props.navigation.navigate('enterprise_see', {
  233. enterprise: data.item,
  234. });
  235. }}>
  236. <View style={{flex: 1}}>
  237. <View style={{alignItems: 'center'}}>
  238. <Text
  239. style={{
  240. fontSize: 18,
  241. fontFamily: 'PingFang-SC-Regular',
  242. color: '#333333',
  243. }}>
  244. {data.item.entName}
  245. </Text>
  246. </View>
  247. </View>
  248. </List.Item>
  249. </SwipeAction>
  250. );
  251. }