service_provider_list.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 service_provider_css from './service_provider_css';
  15. let pageNo = 1; //当前第几页
  16. let totalPage = 5; //总的页数
  17. export default class service_provider_list extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.props.navigation.dangerouslyGetParent().setOptions({
  21. tabBarVisible: false,
  22. });
  23. this.state = {
  24. listData: [],
  25. search_data: '',
  26. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  27. isLoading: false,
  28. };
  29. }
  30. render() {
  31. return (
  32. <View style={{flex: 1, backgroundColor: '#ffffff'}}>
  33. <View
  34. style={{
  35. width: Dimensions.get('window').width,
  36. alignItems: 'center',
  37. justifyContent: 'center',
  38. backgroundColor: '#ffffff',
  39. height: 50,
  40. }}>
  41. <SearchBar
  42. placeholder="搜索"
  43. value={this.state.search_data}
  44. // onSubmit={value => Alert.alert(value)}
  45. onCancel={() => this.searchClear()}
  46. onChange={(value) => this.searchData(value)}
  47. showCancelButton={false}
  48. style={{borderRadius: 15}}
  49. />
  50. </View>
  51. <View style={service_provider_css.container}>
  52. <FlatList
  53. data={this.state.listData}
  54. renderItem={(item) => this.renderItem(item)}
  55. refreshControl={
  56. <RefreshControl
  57. title={'加载中...'}
  58. colors={['#B7B7B7']} //此颜色无效
  59. tintColor={'#B7B7B7'}
  60. titleColor={'#B7B7B7'} //只有ios有效
  61. refreshing={this.state.isLoading}
  62. onRefresh={() => {
  63. this.initData();
  64. }}
  65. />
  66. }
  67. ListFooterComponent={this._renderFooter.bind(this)}
  68. onEndReached={this._onEndReached.bind(this)}
  69. onEndReachedThreshold={0.1}
  70. />
  71. </View>
  72. </View>
  73. );
  74. }
  75. //搜索数据
  76. searchData = (value) => {
  77. this.setState({
  78. search_data: value,
  79. });
  80. this.timer = setTimeout(() => {
  81. this.initData();
  82. }, 1000);
  83. };
  84. //清空搜索
  85. searchClear = () => {
  86. this.setState({
  87. search_data: '',
  88. });
  89. this.initData();
  90. };
  91. //数据初始化
  92. initData = () => {
  93. this.setState({
  94. listData: [],
  95. isLoading: false,
  96. showFoot: 0,
  97. });
  98. pageNo = 1;
  99. this.getServiceData();
  100. };
  101. //上拉加载
  102. _onEndReached() {
  103. if (this.state.showFoot === 0) {
  104. if (pageNo >= totalPage) {
  105. this.setState({showFoot: 1});
  106. return;
  107. } else {
  108. pageNo++;
  109. this.setState({showFoot: 2});
  110. //获取数据
  111. this.getServiceData();
  112. }
  113. }
  114. }
  115. //显示list尾部
  116. _renderFooter() {
  117. if (this.state.showFoot === 1) {
  118. return (
  119. <View
  120. style={{
  121. height: 30,
  122. alignItems: 'center',
  123. justifyContent: 'flex-start',
  124. }}>
  125. <Text
  126. style={{
  127. color: '#999999',
  128. fontSize: 14,
  129. marginTop: 5,
  130. marginBottom: 5,
  131. }}>
  132. 没有更多数据了
  133. </Text>
  134. </View>
  135. );
  136. } else if (this.state.showFoot === 2) {
  137. return (
  138. <View style={service_provider_css.footer}>
  139. <ActivityIndicator />
  140. <Text>正在加载更多数据...</Text>
  141. </View>
  142. );
  143. } else if (this.state.showFoot === 0) {
  144. return (
  145. <View style={service_provider_css.footer}>
  146. <Text />
  147. </View>
  148. );
  149. }
  150. }
  151. //显示页面加载
  152. componentDidMount(): void {
  153. this.getServiceData();
  154. //收到监听
  155. this.listener = DeviceEventEmitter.addListener('刷新用户列表', (data) => {
  156. //收到监听后想做的事情
  157. this.initData();
  158. });
  159. }
  160. //关闭页面加载
  161. componentWillUnmount(): void {
  162. pageNo = 1;
  163. this.timer && clearTimeout(this.timer);
  164. //移除监听
  165. if (this.listener) {
  166. this.listener.remove();
  167. }
  168. }
  169. //获取服务商列表
  170. getServiceData = async () => {
  171. let account = await RetrieveData('account');
  172. let token = await RetrieveData('token');
  173. if (token && account) {
  174. account = account.substring(1, account.length - 1);
  175. token = token.substring(1, token.length - 1);
  176. const url = 'https://app.taxbk.cn:9443/auth/isp/info/findPage';
  177. let response = await GetDataPost(
  178. url,
  179. token,
  180. {
  181. pageNum: pageNo,
  182. pageSize: 10,
  183. name: this.state.search_data,
  184. },
  185. false,
  186. 2,
  187. );
  188. if (response) {
  189. if (response.code == 0) {
  190. totalPage = response.data.pages;
  191. this.setList(response.data.records);
  192. }
  193. }
  194. }
  195. };
  196. //设置客户数据列表
  197. setList = (data) => {
  198. let listDatas = data.map((_, i) => ({
  199. key: data[i].ispId,
  200. name: data[i].name,
  201. contactPhone: data[i].contactPhone,
  202. contactName: data[i].contactName,
  203. address: data[i].address,
  204. joinDate: data[i].joinDate,
  205. }));
  206. let list = this.state.listData.concat(listDatas);
  207. this.setState({
  208. listData: list,
  209. showFoot: 0,
  210. });
  211. };
  212. //加载客户列表数据
  213. renderItem = (data) => (
  214. <SwipeAction
  215. autoClose
  216. style={{backgroundColor: 'transparent'}}
  217. right={this.right(data)}>
  218. <List.Item
  219. onPress={() => {
  220. this.props.navigation.navigate('service_provider', {
  221. service: data.item,
  222. });
  223. }}>
  224. <View style={{flex: 1}}>
  225. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  226. <View style={{flex: 1, alignItems: 'center'}}>
  227. <Text
  228. style={{
  229. fontSize: 18,
  230. fontFamily: 'PingFang-SC-Regular',
  231. color: '#333333',
  232. }}>
  233. {data.item.name}
  234. </Text>
  235. </View>
  236. <View style={{flex: 1, alignItems: 'center'}}>
  237. <Text
  238. style={{
  239. fontSize: 18,
  240. fontFamily: 'PingFang-SC-Regular',
  241. color: '#333333',
  242. }}>
  243. {data.item.contactPhone}
  244. </Text>
  245. </View>
  246. </View>
  247. </View>
  248. </List.Item>
  249. </SwipeAction>
  250. );
  251. //显示侧滑按钮
  252. right = (data) => [
  253. {
  254. text: '编辑',
  255. onPress: () =>
  256. this.props.navigation.navigate('personnel_edit', {
  257. personnel: data.item,
  258. }),
  259. style: {backgroundColor: 'orange', color: 'white'},
  260. },
  261. {
  262. text: '删除',
  263. onPress: () => {
  264. this.deleteData(data.item);
  265. },
  266. style: {backgroundColor: 'red', color: 'white'},
  267. },
  268. ];
  269. }