enterprise_list.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 {
  13. List,
  14. SearchBar,
  15. SwipeAction,
  16. WingBlank,
  17. } from '@ant-design/react-native';
  18. import {RetrieveData} from '../../../data/storage';
  19. import {RequestNetwork} from '../../../data/encryption';
  20. import enterprise_css from './enterprise_css';
  21. let pageNo = 1; //当前第几页
  22. let totalPage = 5; //总的页数
  23. export default class enterprise_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. <View style={{flex: 1, backgroundColor: '#ffffff'}}>
  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={enterprise_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.2}
  76. />
  77. </View>
  78. </View>
  79. );
  80. }
  81. //搜索数据
  82. searchData = (value) => {
  83. this.setState({
  84. search_data: value,
  85. });
  86. this.timer = setTimeout(() => {
  87. this.initData();
  88. }, 1000);
  89. };
  90. //清空搜索
  91. searchClear = () => {
  92. this.setState({
  93. search_data: '',
  94. });
  95. this.initData();
  96. };
  97. //数据初始化
  98. initData = () => {
  99. this.setState({
  100. listData: [],
  101. isLoading: false,
  102. showFoot: 0,
  103. });
  104. pageNo = 1;
  105. this.getCustomerData();
  106. };
  107. //上拉加载
  108. _onEndReached = () => {
  109. if (this.state.showFoot === 0) {
  110. if (pageNo >= totalPage) {
  111. this.setState({showFoot: 1});
  112. return;
  113. } else {
  114. pageNo++;
  115. this.setState({showFoot: 2});
  116. //获取数据
  117. this.getCustomerData();
  118. }
  119. }
  120. };
  121. //显示list尾部
  122. _renderFooter() {
  123. if (this.state.showFoot === 1) {
  124. return (
  125. <View
  126. style={{
  127. height: 30,
  128. alignItems: 'center',
  129. justifyContent: 'flex-start',
  130. }}>
  131. <Text
  132. style={{
  133. color: '#999999',
  134. fontSize: 14,
  135. marginTop: 5,
  136. marginBottom: 5,
  137. }}>
  138. 没有更多数据了
  139. </Text>
  140. </View>
  141. );
  142. } else if (this.state.showFoot === 2) {
  143. return (
  144. <View style={enterprise_css.footer}>
  145. <ActivityIndicator />
  146. <Text>正在加载更多数据...</Text>
  147. </View>
  148. );
  149. } else if (this.state.showFoot === 0) {
  150. return (
  151. <View style={enterprise_css.footer}>
  152. <Text />
  153. </View>
  154. );
  155. }
  156. }
  157. //显示页面加载
  158. componentDidMount(): void {
  159. this.getCustomerData();
  160. //收到监听
  161. this.listener = DeviceEventEmitter.addListener('企业信息刷新', (data) => {
  162. //收到监听后想做的事情
  163. this.initData();
  164. });
  165. }
  166. //关闭页面加载
  167. componentWillUnmount(): void {
  168. pageNo = 1;
  169. this.timer && clearTimeout(this.timer);
  170. //移除监听
  171. if (this.listener) {
  172. this.listener.remove();
  173. }
  174. }
  175. //获取客户数据
  176. getCustomerData = async () => {
  177. let account = await RetrieveData('account');
  178. let token = await RetrieveData('token');
  179. if (token && account) {
  180. const url = '/sys/entInfo/findPageByMobile';
  181. let res = await RequestNetwork(
  182. url,
  183. token,
  184. {
  185. userMobile: account,
  186. reqChannel: 3,
  187. pageNum: pageNo,
  188. pageSize: 10,
  189. entName: this.state.search_data,
  190. },
  191. false,
  192. 2,
  193. );
  194. if (res) {
  195. console.log(res);
  196. if (res.code === 0) {
  197. totalPage = res.data.pages;
  198. this.setList(res.data.records);
  199. }
  200. }
  201. }
  202. };
  203. //设置客户数据列表
  204. setList = (data) => {
  205. let listDatas = data.map((_, i) => ({
  206. key: data[i].entInfoId,
  207. entTaxId: data[i].entTaxId,
  208. entName: data[i].entName,
  209. entShortName: data[i].entShortName,
  210. entType: data[i].entType,
  211. entAddress: data[i].entAddress,
  212. entContactPerson: data[i].entContactPerson,
  213. entTaxOfficeCode: data[i].entTaxOfficeCode,
  214. entTaxOfficeName: data[i].entTaxOfficeName,
  215. serviceStatus: data[i].serviceStatus,
  216. availableTaxes: data[i].availableTaxes,
  217. entPhone: data[i].entPhone,
  218. bankName: data[i].bankName,
  219. bankAccountNumber: data[i].bankAccountNumber,
  220. payees: data[i].payees,
  221. reviewers: data[i].reviewers,
  222. drawers: data[i].drawers,
  223. defaultTaxCode: data[i].defaultTaxCode,
  224. defaultItemName: data[i].defaultItemName,
  225. defaultTaxRate: data[i].defaultTaxRate,
  226. defaultInvoiceDevice: data[i].defaultInvoiceDevice,
  227. isvPlatform: data[i].isvPlatform,
  228. businessLicenseImg: data[i].businessLicenseImg,
  229. entLogo: data[i].entLogo,
  230. authProtocol: data[i].authProtocol,
  231. ispId: data[i].ispId,
  232. createBy: data[i].createBy,
  233. createTime: data[i].createTime,
  234. lastUpdateBy: data[i].lastUpdateBy,
  235. lastUpdateTime: data[i].lastUpdateTime,
  236. hasConfirm: data[i].hasConfirm,
  237. bwCloudInfo: data[i].bwCloudInfo,
  238. defaultDeviceInfo: data[i].defaultDeviceInfo,
  239. }));
  240. let list = this.state.listData.concat(listDatas);
  241. this.setState({
  242. listData: list,
  243. showFoot: 0,
  244. });
  245. };
  246. //加载客户列表数据
  247. renderItem = (data) => (
  248. <SwipeAction
  249. autoClose
  250. style={{backgroundColor: 'transparent'}}>
  251. <List.Item
  252. style={{backgroundColor: '#F7F7F7'}}
  253. onPress={() => {
  254. this.props.navigation.navigate('enterprise_edit', {
  255. enterprise: data.item,
  256. });
  257. }}>
  258. <View style={{backgroundColor: '#ffffff'}}>
  259. <View
  260. style={{
  261. flexDirection: 'row',
  262. alignItems: 'center',
  263. margin: 5,
  264. borderBottomWidth: 1,
  265. borderBottomColor: '#E5E5E5',
  266. height: 50,
  267. }}>
  268. <View
  269. style={{
  270. borderWidth: 2,
  271. borderColor: '#2A67FE',
  272. height: 18,
  273. borderRadius: 3,
  274. }}
  275. />
  276. <View style={{marginLeft: 5, marginRight: 5, flex: 1}}>
  277. <Text
  278. style={{
  279. fontSize: 18,
  280. color: '#4B4B4B',
  281. fontWeight: 'bold',
  282. }}
  283. numberOfLines={1}
  284. ellipsizeMode={'tail'}>
  285. {data.item.entName}
  286. </Text>
  287. </View>
  288. <View
  289. style={{
  290. borderWidth: 1,
  291. borderColor: '#2A67FE',
  292. borderRadius: 6,
  293. width: 40,
  294. height: 20,
  295. }}>
  296. <Text
  297. style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>
  298. 企业
  299. </Text>
  300. </View>
  301. </View>
  302. <View style={{margin: 10}}>
  303. <Text style={{color: '#808080', fontSize: 15}}>
  304. 企业税号:{data.item.entTaxId}
  305. </Text>
  306. </View>
  307. <View
  308. style={{
  309. flexDirection: 'row',
  310. height: 32,
  311. backgroundColor: '#F5F7FC',
  312. marginLeft: 10,
  313. marginRight: 10,
  314. }}>
  315. <View
  316. style={{
  317. flexDirection: 'row',
  318. alignItems: 'center',
  319. flex: 1,
  320. marginLeft: 5,
  321. }}>
  322. {data.item.entPhone === '' ? (
  323. <Text
  324. style={{
  325. fontSize: 13,
  326. color: '#808080',
  327. }}>
  328. 联系电话:暂未填写
  329. </Text>
  330. ) : (
  331. <Text
  332. style={{
  333. fontSize: 13,
  334. color: '#808080',
  335. }}>
  336. 联系电话:
  337. {data.item.entPhone}
  338. </Text>
  339. )}
  340. </View>
  341. <View
  342. style={{
  343. flexDirection: 'row',
  344. alignItems: 'center',
  345. margin: 5,
  346. flex: 1,
  347. }}>
  348. <Text
  349. style={{
  350. fontSize: 13,
  351. color: '#808080',
  352. }}>
  353. 邮箱:暂未填写
  354. </Text>
  355. </View>
  356. </View>
  357. <View style={{height: 10}} />
  358. </View>
  359. </List.Item>
  360. </SwipeAction>
  361. );
  362. }