invoice_head_list.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. FlatList,
  5. Text,
  6. ActivityIndicator,
  7. RefreshControl,
  8. TouchableOpacity,
  9. Image, Alert,
  10. } from "react-native";
  11. import {
  12. DatePicker,
  13. List,
  14. Provider,
  15. InputItem,
  16. SwipeAction,
  17. Drawer,
  18. WingBlank,
  19. } from "@ant-design/react-native";
  20. import public_css from '../../source/css/public_css';
  21. import moment from 'moment';
  22. import {RetrieveData} from '../../data/storage';
  23. import {RequestNetwork} from '../../data/encryption';
  24. import invoice_head_css from './invoice_head_css';
  25. import { ToastShow } from "../../components/toast/toast";
  26. import { CleanAll } from "../../components/abnormalMessage/abnormal_message";
  27. let pageNo = 1; //当前第几页
  28. let totalPage = 5; //总的页数
  29. export default class invoice_head_list extends Component {
  30. constructor(props) {
  31. super(props);
  32. this.props.navigation.dangerouslyGetParent().setOptions({
  33. tabBarVisible: false,
  34. });
  35. this.state = {
  36. isShowSearch: false,
  37. clickNum: 0,
  38. customerName: '',
  39. customerEntTaxId: '',
  40. customerMobile: '',
  41. belongEntTaxId: '',
  42. entName: '',
  43. createTimeEnd: undefined,
  44. createTimeBegin: undefined,
  45. listData: [],
  46. status: 0,
  47. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  48. isLoading: false,
  49. isOpen: false,
  50. };
  51. }
  52. render() {
  53. let draw = (
  54. <View style={public_css.body}>
  55. <View style={{flex: 1}}>
  56. <View>
  57. <List>
  58. <DatePicker
  59. value={this.state.createTimeBegin}
  60. mode="date"
  61. defaultDate={new Date()}
  62. minDate={new Date(2020, 0, 1)}
  63. maxDate={new Date(2030, 11, 3)}
  64. onChange={(time) => this.beginTimeChange(time)}
  65. format="YYYY-MM-DD">
  66. <List.Item arrow="horizontal">开始时间</List.Item>
  67. </DatePicker>
  68. </List>
  69. </View>
  70. <View>
  71. <List>
  72. <DatePicker
  73. value={this.state.createTimeEnd}
  74. mode="date"
  75. defaultDate={new Date()}
  76. minDate={this.state.createTimeBegin}
  77. maxDate={new Date(2030, 11, 3)}
  78. onChange={(time) => this.endTimeChange(time)}
  79. format="YYYY-MM-DD">
  80. <List.Item arrow="horizontal">结束时间</List.Item>
  81. </DatePicker>
  82. </List>
  83. </View>
  84. <InputItem
  85. clear
  86. value={this.state.customerName}
  87. onChange={(value) => {
  88. this.setState({
  89. customerName: value,
  90. });
  91. }}
  92. placeholder="请输入要查询的客户方名称">
  93. 客户方名称:
  94. </InputItem>
  95. <InputItem
  96. clear
  97. value={this.state.customerEntTaxId}
  98. onChange={(value) => {
  99. this.setState({
  100. customerEntTaxId: value,
  101. });
  102. }}
  103. placeholder="请输入要查询的客户方税号">
  104. 客户方税号:
  105. </InputItem>
  106. <InputItem
  107. clear
  108. value={this.state.customerMobile}
  109. onChange={(value) => {
  110. this.setState({
  111. customerMobile: value,
  112. });
  113. }}
  114. placeholder="请输入要查询的客户方手机号">
  115. 客户方手机号:
  116. </InputItem>
  117. </View>
  118. <View style={public_css.bottomStatus}>
  119. <TouchableOpacity
  120. style={[public_css.statusBtn, public_css.statusLBtn]}
  121. onPress={() => {
  122. this.searchDataEmpty();
  123. }}>
  124. <Image
  125. source={require('../../source/img/productImg/clear.png')}
  126. style={{width: 32, height: 32}}
  127. />
  128. <Text>全部清除</Text>
  129. </TouchableOpacity>
  130. <TouchableOpacity
  131. style={[public_css.statusBtn, public_css.statusRBtn]}
  132. onPress={() => this.initData()}>
  133. <Image
  134. source={require('../../source/img/productImg/confirm.png')}
  135. style={{width: 32, height: 32}}
  136. />
  137. <Text style={{color: '#fff'}}>查询</Text>
  138. </TouchableOpacity>
  139. </View>
  140. </View>
  141. );
  142. return (
  143. <View style={{flex: 1}}>
  144. <Provider>
  145. <Drawer
  146. sidebar={draw}
  147. position="right"
  148. open={false}
  149. drawerRef={(el) => (this.drawer = el)}
  150. onOpenChange={(open) => this.openStatus(open)}
  151. drawerBackgroundColor="#ccc"
  152. drawerWidth={300}>
  153. <View style={invoice_head_css.container}>
  154. <FlatList
  155. data={this.state.listData}
  156. renderItem={(item) => this.renderItem(item)}
  157. refreshControl={
  158. <RefreshControl
  159. title={'加载中...'}
  160. colors={['#B7B7B7']} //此颜色无效
  161. tintColor={'#B7B7B7'}
  162. titleColor={'#B7B7B7'} //只有ios有效
  163. refreshing={this.state.isLoading}
  164. onRefresh={() => {
  165. this.initData();
  166. }}
  167. />
  168. }
  169. ListFooterComponent={this._renderFooter.bind(this)}
  170. onEndReached={this._onEndReached.bind(this)}
  171. onEndReachedThreshold={0.1}
  172. />
  173. </View>
  174. </Drawer>
  175. </Provider>
  176. </View>
  177. );
  178. }
  179. //判断是否点击了查询
  180. shouldComponentUpdate(
  181. nextProps: Readonly<P>,
  182. nextState: Readonly<S>,
  183. nextContext: any,
  184. ): boolean {
  185. if (nextProps.route.params != undefined) {
  186. if (nextProps.route.params.isShow) {
  187. if (this.state.clickNum === 0) {
  188. this.setState({
  189. isShowSearch: true,
  190. });
  191. this.drawer.openDrawer();
  192. this.props.navigation.setParams({
  193. isShow: false,
  194. });
  195. return true;
  196. }
  197. }
  198. }
  199. return true;
  200. }
  201. //查询菜单开关状态
  202. openStatus = (open) => {
  203. if (open) {
  204. } else {
  205. // this.props.children.setClickNum();
  206. }
  207. };
  208. //获取查询开始时间
  209. beginTimeChange = (time) => {
  210. this.setState({
  211. createTimeBegin: time,
  212. });
  213. };
  214. //获取查询结束时间
  215. endTimeChange = (time) => {
  216. this.setState({
  217. createTimeEnd: time,
  218. });
  219. };
  220. //清空查询数据
  221. searchDataEmpty = () => {
  222. this.setState({
  223. customerName: '',
  224. customerEntTaxId: '',
  225. customerMobile: '',
  226. createTimeEnd: undefined,
  227. createTimeBegin: undefined,
  228. });
  229. };
  230. //数据初始化
  231. initData = () => {
  232. this.setState({
  233. listData: [],
  234. isLoading: false,
  235. showFoot: 0,
  236. status: 0,
  237. });
  238. pageNo = 1;
  239. this.getInvoiceHeads();
  240. };
  241. //上拉加载
  242. _onEndReached() {
  243. if (this.state.showFoot === 0) {
  244. if (pageNo >= totalPage) {
  245. this.setState({showFoot: 1});
  246. return;
  247. } else {
  248. pageNo++;
  249. this.setState({showFoot: 2});
  250. //获取数据
  251. this.getInvoiceHeads();
  252. }
  253. }
  254. }
  255. //列表尾部显示
  256. _renderFooter = () => {
  257. if (this.state.showFoot === 1) {
  258. return (
  259. <View
  260. style={{
  261. height: 30,
  262. alignItems: 'center',
  263. justifyContent: 'flex-start',
  264. }}>
  265. <Text
  266. style={{
  267. color: '#999999',
  268. fontSize: 14,
  269. marginTop: 5,
  270. marginBottom: 5,
  271. }}>
  272. 没有更多数据了
  273. </Text>
  274. </View>
  275. );
  276. } else if (this.state.showFoot === 2) {
  277. return (
  278. <View style={invoice_head_css.footer}>
  279. <ActivityIndicator />
  280. <Text>正在加载更多数据...</Text>
  281. </View>
  282. );
  283. } else if (this.state.showFoot === 0) {
  284. return (
  285. <View style={invoice_head_css.footer}>
  286. <Text />
  287. </View>
  288. );
  289. }
  290. };
  291. //页面加载完成后加载数据
  292. componentDidMount(): void {
  293. this.getInvoiceHeads();
  294. }
  295. // 清空数据重新加载
  296. cleanData = async () => {
  297. this.setState({
  298. listData: [],
  299. isLoading: false,
  300. showFoot: 0,
  301. status: 0,
  302. });
  303. pageNo = 1;
  304. await this.getInvoiceHeads();
  305. };
  306. //获取抬头列表数据
  307. getInvoiceHeads = async () => {
  308. let beginTime = '';
  309. let endTime = '';
  310. if (this.state.createTimeBegin != undefined) {
  311. beginTime = moment(this.state.createTimeBegin).format('YYYY-MM-DD');
  312. beginTime = beginTime + ' 00:00:00';
  313. }
  314. if (this.state.createTimeEnd != undefined) {
  315. endTime = moment(this.state.createTimeEnd).format('YYYY-MM-DD');
  316. endTime = endTime + ' 23:59:59';
  317. }
  318. let account = await RetrieveData('account');
  319. let token = await RetrieveData('token');
  320. let company = JSON.parse(await RetrieveData('company'));
  321. if (token && account) {
  322. const url = '/sys/taitou/todo/findPage';
  323. let res = await RequestNetwork(
  324. url,
  325. token,
  326. {
  327. mobile: account,
  328. reqChannel: 3,
  329. pageNum: pageNo,
  330. pageSize: 10,
  331. createTimeEnd: endTime,
  332. createTimeBegin: beginTime,
  333. customerName: this.state.customerName,
  334. customerEntTaxId: this.state.customerEntTaxId,
  335. customerMobile: this.state.customerMobile,
  336. belongEntTaxId: company.entTaxId,
  337. },
  338. false,
  339. 2,
  340. );
  341. if (res) {
  342. if (res.code === 0) {
  343. totalPage = res.data.pages;
  344. this.setList(res.data.records);
  345. } else {
  346. await this.abnormalMessage(res);
  347. }
  348. }
  349. }
  350. };
  351. //设置抬头列表
  352. setList = (data) => {
  353. let listDatas = data.map((_, i) => ({
  354. key: data[i].recordId,
  355. customerName: data[i].customerName,
  356. customerEntTaxId: data[i].customerEntTaxId,
  357. address: data[i].address,
  358. contactPhone: data[i].contactPhone,
  359. bankName: data[i].bankName,
  360. bankAccountNo: data[i].bankAccountNo,
  361. customerEmail: data[i].customerEmail,
  362. customerMobile: data[i].customerMobile,
  363. remark: data[i].remark,
  364. belongEntTaxId: data[i].belongEntTaxId,
  365. status: data[i].status,
  366. entName: data[i].entName,
  367. createTime: data[i].createTime,
  368. customerType: data[i].customerType,
  369. interactType: data[i].interactType,
  370. interactTypeDetail: data[i].interactTypeDetail,
  371. belongEntName: data[i].belongEntName,
  372. }));
  373. let list = this.state.listData.concat(listDatas);
  374. this.setState({
  375. listData: list,
  376. showFoot: 0,
  377. });
  378. };
  379. //显示发票抬头列表
  380. renderItem = (data) => (
  381. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  382. <List.Item style={{backgroundColor: '#F7F7F7'}}>
  383. <View style={{backgroundColor: '#ffffff'}}>
  384. <View style={{margin: 10}}>
  385. <Text
  386. style={{fontWeight: 'bold', fontSize: 16, color: '#050505'}}
  387. ellipsizeMode={'tail'}
  388. numberOfLines={1}>
  389. 发票抬头:{data.item.customerName}
  390. </Text>
  391. <Text style={{color: '#898989', marginTop: 5}}>
  392. 税号:{data.item.customerEntTaxId}
  393. </Text>
  394. </View>
  395. <WingBlank>
  396. <View style={{borderTopWidth: 1, borderColor: '#D9D9D9'}} />
  397. </WingBlank>
  398. <View style={{flexDirection: 'row', margin: 10}}>
  399. <View style={{flex: 1, justifyContent: 'center'}}>
  400. <Text>{data.item.createTime}</Text>
  401. </View>
  402. <View style={{flexDirection: 'row', flex: 1}}>
  403. <TouchableOpacity
  404. style={{
  405. flex: 1,
  406. borderWidth: 1,
  407. justifyContent: 'center',
  408. alignItems: 'center',
  409. borderColor: '#CCCCCC',
  410. borderRadius: 30,
  411. height: 30,
  412. }}
  413. onPress={() => {
  414. this.deleteData(data);
  415. }}>
  416. <Text style={{color: '#666666'}}>删除</Text>
  417. </TouchableOpacity>
  418. <TouchableOpacity
  419. style={{
  420. flex: 1,
  421. borderWidth: 1,
  422. justifyContent: 'center',
  423. alignItems: 'center',
  424. borderColor: '#2A67FE',
  425. borderRadius: 30,
  426. height: 30,
  427. marginLeft: 5,
  428. }}
  429. onPress={() => {
  430. this.props.navigation.navigate('invoice_head', {
  431. invoiceData: data,
  432. });
  433. }}>
  434. <Text style={{color: '#2A67FE'}}>点击开票</Text>
  435. </TouchableOpacity>
  436. </View>
  437. </View>
  438. </View>
  439. </List.Item>
  440. </SwipeAction>
  441. );
  442. //左滑显示删除按钮
  443. right = (data) => [
  444. {
  445. text: '删除',
  446. onPress: () => {
  447. this.deleteData(data.item);
  448. },
  449. style: {backgroundColor: 'red', color: 'white'},
  450. },
  451. ];
  452. //删除发票抬头信息
  453. deleteData = async (data) => {
  454. let company = JSON.parse(await RetrieveData('company'));
  455. let account = await RetrieveData('account');
  456. let token = await RetrieveData('token');
  457. if (account && token) {
  458. const url = '/sys/taitou/todo/delete';
  459. let res = await RequestNetwork(
  460. url,
  461. token,
  462. {
  463. mobile: account,
  464. reqChannel: 3,
  465. delList: [
  466. {
  467. recordId: data.item.key,
  468. belongEntTaxId: company.entTaxId,
  469. },
  470. ],
  471. },
  472. false,
  473. 1,
  474. );
  475. if (res) {
  476. if (res.code === 0) {
  477. ToastShow(1, '删除成功!');
  478. await this.cleanData();
  479. } else {
  480. ToastShow(1, res.msg);
  481. }
  482. }
  483. }
  484. };
  485. // 处理网络请求数据
  486. abnormalMessage = async (jason) => {
  487. if (jason.code === 401) {
  488. await Alert.alert(
  489. '登录失效',
  490. '登录状态已失效,请重新登录!',
  491. [
  492. {
  493. text: '确定',
  494. onPress: () => {
  495. CleanAll();
  496. this.props.navigation.popToTop();
  497. },
  498. },
  499. ],
  500. {cancelable: false},
  501. );
  502. }
  503. if (jason.code === 403) {
  504. Alert.alert(
  505. '权限',
  506. '暂无权限操作此模块!',
  507. [
  508. {
  509. text: '确定',
  510. onPress: () => {
  511. this.props.navigation.goBack();
  512. },
  513. },
  514. ],
  515. {cancelable: false},
  516. );
  517. }
  518. if (jason.code !== 401 && jason.code !== 403) {
  519. ToastShow(1, jason.msg);
  520. }
  521. };
  522. }