invoice_select_customer.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. FlatList,
  6. RefreshControl,
  7. Alert,
  8. SafeAreaView,
  9. Image,
  10. StyleSheet,
  11. Dimensions,
  12. PixelRatio,
  13. } from 'react-native';
  14. import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
  15. import {RetrieveData} from '../../data/storage';
  16. import {RequestNetwork} from '../../data/encryption';
  17. import public_css from '../../source/css/public_css';
  18. import {Footer} from '../../components/listPage/pagination';
  19. import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
  20. import {ToastShow} from '../../components/toast/toast';
  21. let pageNo = 1; //当前页码
  22. let totalPage = 5; //总的页数
  23. let pageSize = 10; //每页数量
  24. export default class invoice_select_customer extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. listData: [],
  29. customerName: '',
  30. showFoot: 0, // 控制foot, 0:无数据 1:加载中 2 :上拉加载
  31. isLoading: false,
  32. };
  33. }
  34. render() {
  35. return (
  36. <SafeAreaView style={public_css.body}>
  37. <View
  38. style={{
  39. // width: Dimensions.get('window').width,
  40. alignItems: 'center',
  41. justifyContent: 'center',
  42. backgroundColor: '#ffffff',
  43. height: 50,
  44. }}>
  45. <SearchBar
  46. placeholder="搜索"
  47. value={this.state.customerName}
  48. onCancel={() => this.searchClear()}
  49. onChange={(value) => this.searchData(value)}
  50. showCancelButton={false}
  51. style={{borderRadius: 15}}
  52. />
  53. </View>
  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={() => Footer(this.state.showFoot)}
  70. // onEndReached={this._onEndReached.bind(this)}
  71. // onEndReachedThreshold={0.1}
  72. />
  73. </SafeAreaView>
  74. );
  75. }
  76. //页面渲染完成后加载
  77. async componentDidMount(): void {
  78. pageNo = 1;
  79. this.setState({
  80. listData: [],
  81. customerName: '',
  82. showFoot: 1,
  83. });
  84. await this.getCustomerData();
  85. }
  86. //搜索
  87. searchData = async (text) => {
  88. pageNo = 1;
  89. this.setState({
  90. listData: [],
  91. customerName: text,
  92. showFoot: 0,
  93. });
  94. await this.getCustomerData();
  95. };
  96. //初始化数据
  97. initData = async () => {
  98. pageNo = 1;
  99. this.setState({
  100. listData: [],
  101. customerName: '',
  102. showFoot: 1,
  103. isLoading: true,
  104. });
  105. await this.getCustomerData();
  106. };
  107. //清空搜索栏
  108. searchClear = async () => {
  109. await this.initData();
  110. };
  111. //获得客户信息
  112. getCustomerData = async () => {
  113. let token = await RetrieveData('token');
  114. let company = JSON.parse(await RetrieveData('company'));
  115. if (token) {
  116. const url = '/sys/customer/customerSearch';
  117. let res = await RequestNetwork(
  118. url,
  119. token,
  120. {
  121. customerName: this.state.customerName,
  122. entTaxId: company.entTaxId,
  123. reqChannel: 3,
  124. },
  125. false,
  126. 2,
  127. );
  128. if (res) {
  129. console.log(res);
  130. if (res.code === 0) {
  131. totalPage = res.data.pages;
  132. this.setList(res.data);
  133. } else {
  134. this.setState({
  135. showFoot: 0,
  136. });
  137. await this.abnormalMessage(res);
  138. }
  139. }
  140. }
  141. };
  142. //设置客户信息列表
  143. setList = (data) => {
  144. let listDatas = data.map((_, i) => ({
  145. key: data[i].customerId,
  146. customerName: data[i].customerName,
  147. entTaxId: data[i].customerEntTaxId,
  148. contactPhone: data[i].contactPhone,
  149. address: data[i].address,
  150. bankName: data[i].bankName,
  151. bankAccount: data[i].bankAccountNumber,
  152. customerMobile: data[i].customerMobile,
  153. email: data[i].email,
  154. }));
  155. let list = this.state.listData.concat(listDatas);
  156. if (list.length > 0) {
  157. this.setState({
  158. showFoot: 2,
  159. isLoading: false,
  160. listData: list,
  161. });
  162. } else {
  163. this.setState({
  164. showFoot: 0,
  165. isLoading: false,
  166. listData: list,
  167. });
  168. }
  169. };
  170. //加载列表数据
  171. renderItem = (data) => (
  172. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  173. <List.Item
  174. style={{backgroundColor: '#F7F7F7'}}
  175. onPress={() => {
  176. this.props.route.params.selectCustomer(data.item);
  177. this.props.navigation.goBack();
  178. }}>
  179. <View style={{backgroundColor: '#ffffff'}}>
  180. <View
  181. style={{
  182. flexDirection: 'row',
  183. alignItems: 'center',
  184. margin: 5,
  185. borderBottomWidth: 1,
  186. borderBottomColor: '#E5E5E5',
  187. height: 50,
  188. }}>
  189. <View
  190. style={{
  191. borderWidth: 2,
  192. borderColor: '#2A67FE',
  193. height: 18,
  194. borderRadius: 3,
  195. }}
  196. />
  197. <View style={{marginLeft: 5, marginRight: 5, flex: 1}}>
  198. <Text
  199. style={{
  200. fontSize: 18,
  201. color: '#4B4B4B',
  202. fontWeight: 'bold',
  203. }}
  204. numberOfLines={1}
  205. ellipsizeMode={'tail'}>
  206. {data.item.customerName}
  207. </Text>
  208. </View>
  209. {data.item.customerType === 1 ? (
  210. <View
  211. style={{
  212. borderWidth: 1,
  213. borderColor: '#2A67FE',
  214. borderRadius: 6,
  215. width: 40,
  216. height: 20,
  217. }}>
  218. <Text
  219. style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>
  220. 个人
  221. </Text>
  222. </View>
  223. ) : (
  224. <View
  225. style={{
  226. borderWidth: 1,
  227. borderColor: '#2A67FE',
  228. borderRadius: 6,
  229. width: 40,
  230. height: 20,
  231. }}>
  232. <Text
  233. style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>
  234. 企业
  235. </Text>
  236. </View>
  237. )}
  238. </View>
  239. <View style={{margin: 10}}>
  240. <Text style={{color: '#808080', fontSize: 15}}>
  241. 企业税号:{data.item.entTaxId}
  242. </Text>
  243. </View>
  244. <View
  245. style={{
  246. flexDirection: 'row',
  247. height: 32,
  248. backgroundColor: '#F5F7FC',
  249. marginLeft: 10,
  250. marginRight: 10,
  251. }}>
  252. <View
  253. style={{
  254. flexDirection: 'row',
  255. alignItems: 'center',
  256. flex: 1,
  257. marginLeft: 5,
  258. }}>
  259. {data.item.customerMobile === '' ? (
  260. <Text
  261. style={{
  262. fontSize: 14,
  263. color: '#808080',
  264. }}>
  265. 联系电话:暂未填写
  266. </Text>
  267. ) : (
  268. <Text
  269. style={{
  270. fontSize: 14,
  271. color: '#808080',
  272. }}>
  273. 联系电话:
  274. {data.item.customerMobile}
  275. </Text>
  276. )}
  277. </View>
  278. <View
  279. style={{
  280. flexDirection: 'row',
  281. alignItems: 'center',
  282. margin: 5,
  283. flex: 1,
  284. }}>
  285. {data.item.email === '' ? (
  286. <Text
  287. style={{
  288. fontSize: 14,
  289. color: '#808080',
  290. }}>
  291. 邮箱:暂未填写
  292. </Text>
  293. ) : (
  294. <Text
  295. style={{
  296. fontSize: 14,
  297. color: '#808080',
  298. }}
  299. numberOfLines={1}
  300. ellipsizeMode={'tail'}>
  301. 邮箱:
  302. {data.item.email}
  303. </Text>
  304. )}
  305. </View>
  306. </View>
  307. <View style={{height: 10}} />
  308. </View>
  309. </List.Item>
  310. </SwipeAction>
  311. );
  312. //列表上拉加载
  313. _onEndReached = async () => {
  314. if (this.state.showFoot === 2) {
  315. if (pageNo >= totalPage) {
  316. this.setState({showFoot: 0});
  317. return;
  318. } else {
  319. pageNo++;
  320. this.setState({showFoot: 1});
  321. await this.getCustomerData();
  322. }
  323. }
  324. };
  325. // 处理网络请求数据
  326. abnormalMessage = async (jason) => {
  327. if (jason.code === 401) {
  328. await Alert.alert(
  329. '登录失效',
  330. '登录状态已失效,请重新登录!',
  331. [
  332. {
  333. text: '确定',
  334. onPress: () => {
  335. CleanAll();
  336. this.props.navigation.popToTop();
  337. },
  338. },
  339. ],
  340. {cancelable: false},
  341. );
  342. }
  343. if (jason.code === 403) {
  344. Alert.alert(
  345. '权限',
  346. '暂无权限操作此模块!',
  347. [
  348. {
  349. text: '确定',
  350. onPress: () => {
  351. this.props.navigation.goBack();
  352. },
  353. },
  354. ],
  355. {cancelable: false},
  356. );
  357. }
  358. if (jason.code !== 401 && jason.code !== 403) {
  359. ToastShow(1, jason.msg);
  360. }
  361. };
  362. }
  363. const styles = StyleSheet.create({
  364. buttonView: {
  365. alignItems: 'center',
  366. backgroundColor: '#ffffff',
  367. },
  368. //通用按钮样式
  369. button: {
  370. marginTop: 5,
  371. width: Dimensions.get('window').width * 0.8,
  372. height: 34,
  373. borderRadius: 10,
  374. backgroundColor: '#1874CD',
  375. justifyContent: 'center',
  376. alignItems: 'center',
  377. },
  378. //通用按钮样式
  379. buttonText: {
  380. // fontSize: 22,
  381. textAlign: 'center',
  382. color: 'white',
  383. },
  384. inputView: {
  385. // flex: 1,
  386. padding: 5,
  387. backgroundColor: '#fff',
  388. alignItems: 'center',
  389. justifyContent: 'center',
  390. display: 'flex',
  391. },
  392. view: {
  393. flexDirection: 'row',
  394. height: 34,
  395. width: Dimensions.get('window').width * 0.8,
  396. },
  397. //通用textInput样式
  398. text: {
  399. lineHeight: 34,
  400. fontSize: 14,
  401. },
  402. //通用textInput样式
  403. lineTopBottom: {
  404. borderBottomWidth: 3 / PixelRatio.get(),
  405. borderColor: 'rgb(208,208,208)',
  406. justifyContent: 'center',
  407. alignItems: 'center',
  408. },
  409. textInputStyle: {
  410. flex: 5,
  411. marginRight: 10,
  412. marginLeft: 20,
  413. fontSize: 14,
  414. marginTop: 4,
  415. },
  416. footer: {
  417. flexDirection: 'row',
  418. height: 24,
  419. justifyContent: 'center',
  420. alignItems: 'center',
  421. marginBottom: 10,
  422. },
  423. });