invoice_head.js 13 KB

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