customer_list.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. SafeAreaView,
  12. } from 'react-native';
  13. import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
  14. import ActionButton from 'react-native-action-button';
  15. import Icon from 'react-native-vector-icons/Ionicons';
  16. import {RetrieveData} from '../../../data/storage';
  17. import {RequestNetwork} from '../../../data/encryption';
  18. import customer_css from './customer_css';
  19. import public_css from '../../../source/css/public_css';
  20. import { ToastShow } from "../../../components/toast/toast";
  21. let pageNo = 1; //当前第几页
  22. let totalPage = 5; //总的页数
  23. export default class customer_list extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.props.navigation.dangerouslyGetParent().setOptions({
  27. tabBarVisible: false,
  28. });
  29. this.state = {
  30. listData: [],
  31. search_data: '',
  32. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  33. isLoading: false,
  34. };
  35. }
  36. render() {
  37. return (
  38. <SafeAreaView style={public_css.body}>
  39. <View
  40. style={{
  41. width: Dimensions.get('window').width,
  42. alignItems: 'center',
  43. justifyContent: 'center',
  44. backgroundColor: '#ffffff',
  45. height: 50,
  46. }}>
  47. <SearchBar
  48. placeholder="搜索"
  49. value={this.state.search_data}
  50. // onSubmit={value => Alert.alert(value)}
  51. onCancel={() => this.searchClear()}
  52. onChange={(value) => this.searchData(value)}
  53. showCancelButton={false}
  54. style={{borderRadius: 15}}
  55. />
  56. </View>
  57. <View style={customer_css.container}>
  58. <FlatList
  59. data={this.state.listData}
  60. renderItem={(item) => this.renderItem(item)}
  61. refreshControl={
  62. <RefreshControl
  63. title={'加载中...'}
  64. colors={['#B7B7B7']} //此颜色无效
  65. tintColor={'#B7B7B7'}
  66. titleColor={'#B7B7B7'} //只有ios有效
  67. refreshing={this.state.isLoading}
  68. onRefresh={() => {
  69. this.initData();
  70. }}
  71. />
  72. }
  73. ListFooterComponent={this._renderFooter.bind(this)}
  74. onEndReached={this._onEndReached.bind(this)}
  75. onEndReachedThreshold={0.1}
  76. />
  77. </View>
  78. <ActionButton
  79. buttonColor="rgba(50,100,235,1)"
  80. onPress={() => {
  81. this.props.navigation.navigate('customer_add_or_edit', {
  82. companyId: null,
  83. refresh: () => {
  84. this.refresh();
  85. },
  86. });
  87. }}
  88. renderIcon={() => (
  89. <Icon name="md-add-outline" style={customer_css.actionButtonIcon} />
  90. )}
  91. />
  92. </SafeAreaView>
  93. );
  94. }
  95. //搜索数据
  96. searchData = (value) => {
  97. this.setState({
  98. search_data: value,
  99. });
  100. this.timer = setTimeout(() => {
  101. this.initData();
  102. }, 1000);
  103. };
  104. //清空搜索
  105. searchClear = () => {
  106. this.setState({
  107. search_data: '',
  108. });
  109. this.initData();
  110. };
  111. //数据初始化
  112. initData = async () => {
  113. this.setState({
  114. listData: [],
  115. isLoading: false,
  116. showFoot: 0,
  117. });
  118. pageNo = 1;
  119. await this.getCustomerData();
  120. };
  121. //上拉加载
  122. _onEndReached() {
  123. if (this.state.showFoot === 0) {
  124. if (pageNo >= totalPage) {
  125. this.setState({showFoot: 1});
  126. return;
  127. } else {
  128. pageNo++;
  129. this.setState({showFoot: 2});
  130. //获取数据
  131. this.getCustomerData();
  132. }
  133. }
  134. }
  135. //显示list尾部
  136. _renderFooter() {
  137. if (this.state.showFoot === 1) {
  138. return (
  139. <View
  140. style={{
  141. height: 30,
  142. alignItems: 'center',
  143. justifyContent: 'flex-start',
  144. }}>
  145. <Text
  146. style={{
  147. color: '#999999',
  148. fontSize: 14,
  149. marginTop: 5,
  150. marginBottom: 5,
  151. }}>
  152. 没有更多数据了
  153. </Text>
  154. </View>
  155. );
  156. } else if (this.state.showFoot === 2) {
  157. return (
  158. <View style={customer_css.footer}>
  159. <ActivityIndicator />
  160. <Text>正在加载更多数据...</Text>
  161. </View>
  162. );
  163. } else if (this.state.showFoot === 0) {
  164. return (
  165. <View style={customer_css.footer}>
  166. <Text />
  167. </View>
  168. );
  169. }
  170. }
  171. //显示页面加载
  172. componentDidMount(): void {
  173. this.getCustomerData();
  174. //收到监听
  175. // this.listener = DeviceEventEmitter.addListener('刷新列表', (message) => {
  176. // //收到监听后想做的事情
  177. // this.initData();
  178. // });
  179. }
  180. // 刷新列表
  181. refresh = () => {
  182. this.initData();
  183. };
  184. //关闭页面加载
  185. componentWillUnmount(): void {
  186. pageNo = 1;
  187. this.timer && clearTimeout(this.timer);
  188. //移除监听
  189. if (this.listener) {
  190. this.listener.remove();
  191. }
  192. }
  193. //获取客户数据
  194. getCustomerData = async () => {
  195. let account = await RetrieveData('account');
  196. let token = await RetrieveData('token');
  197. let company = JSON.parse(await RetrieveData('company'));
  198. if (token && account) {
  199. const url = '/sys/customer/findPage';
  200. let res = await RequestNetwork(
  201. url,
  202. token,
  203. {
  204. mobile: account,
  205. entTaxId: company.entTaxId,
  206. reqChannel: 3,
  207. pageNum: pageNo,
  208. pageSize: 10,
  209. customerName: this.state.search_data,
  210. },
  211. false,
  212. 2,
  213. );
  214. if (res) {
  215. if (res.code === 0) {
  216. totalPage = res.data.pages;
  217. this.setList(res.data.records);
  218. }
  219. }
  220. }
  221. };
  222. //设置客户数据列表
  223. setList = (data) => {
  224. console.log(data);
  225. let listDatas = data.map((_, i) => ({
  226. key: data[i].customerId,
  227. customerName: data[i].customerName,
  228. entTaxId: data[i].entTaxId,
  229. customerMobile: data[i].customerMobile,
  230. manageUserId: data[i].manageUserId,
  231. customerType: data[i].customerType,
  232. email: data[i].email,
  233. }));
  234. let list = this.state.listData.concat(listDatas);
  235. this.setState({
  236. listData: list,
  237. showFoot: 0,
  238. });
  239. };
  240. //加载客户列表数据
  241. renderItem = (data) => (
  242. <SwipeAction
  243. autoClose
  244. style={{backgroundColor: 'transparent'}}>
  245. <List.Item
  246. style={{backgroundColor: '#F7F7F7'}}
  247. onPress={() => {
  248. this.props.navigation.navigate('customer_add_or_edit', {
  249. companyId: data.item.key,
  250. refresh: () => {
  251. this.refresh();
  252. },
  253. });
  254. }}>
  255. <View style={{backgroundColor: '#ffffff'}}>
  256. <View style={{flexDirection: 'row', alignItems: 'center', margin: 5, borderBottomWidth: 1, borderBottomColor: '#E5E5E5', height: 50}}>
  257. <View style={{borderWidth: 2, borderColor: '#2A67FE', height: 18, borderRadius: 3}} />
  258. <View style={{marginLeft: 5, marginRight: 5, flex: 1}}>
  259. <Text
  260. style={{
  261. fontSize: 18,
  262. color: '#4B4B4B',
  263. fontWeight: 'bold',
  264. }}
  265. numberOfLines={1}
  266. ellipsizeMode={'tail'}>
  267. {data.item.customerName}
  268. </Text>
  269. </View>
  270. {data.item.customerType === 1 ? (
  271. <View style={{borderWidth: 1, borderColor: '#2A67FE', borderRadius: 6, width: 40, height: 20}}>
  272. <Text style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>个人</Text>
  273. </View>
  274. ) : (
  275. <View style={{borderWidth: 1, borderColor: '#2A67FE', borderRadius: 6, width: 40, height: 20}}>
  276. <Text style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>企业</Text>
  277. </View>
  278. )}
  279. </View>
  280. <View style={{margin: 10}}>
  281. <Text style={{color: '#808080', fontSize: 15}}>企业税号:{data.item.entTaxId}</Text>
  282. </View>
  283. <View style={{flexDirection: 'row', height: 32, backgroundColor: '#F5F7FC', marginLeft: 10, marginRight: 10}}>
  284. <View
  285. style={{
  286. flexDirection: 'row',
  287. alignItems: 'center',
  288. flex: 1,
  289. marginLeft: 5,
  290. }}>
  291. {data.item.customerMobile === '' ? (
  292. <Text
  293. style={{
  294. fontSize: 14,
  295. color: '#808080',
  296. }}>
  297. 联系电话:暂未填写
  298. </Text>
  299. ) : (
  300. <Text
  301. style={{
  302. fontSize: 14,
  303. color: '#808080',
  304. }}>
  305. 联系电话:
  306. {data.item.customerMobile}
  307. </Text>
  308. )}
  309. </View>
  310. <View
  311. style={{
  312. flexDirection: 'row',
  313. alignItems: 'center',
  314. margin: 5,
  315. flex: 1,
  316. }}>
  317. {data.item.email === '' ? (
  318. <Text
  319. style={{
  320. fontSize: 14,
  321. color: '#808080',
  322. }}>
  323. 邮箱:暂未填写
  324. </Text>
  325. ) : (
  326. <Text
  327. style={{
  328. fontSize: 14,
  329. color: '#808080',
  330. }}
  331. numberOfLines={1}
  332. ellipsizeMode={'tail'}>
  333. 邮箱:
  334. {data.item.email}
  335. </Text>
  336. )}
  337. </View>
  338. </View>
  339. <View style={{height: 10}} />
  340. </View>
  341. </List.Item>
  342. </SwipeAction>
  343. );
  344. }