import React, {Component} from 'react'; import { View, FlatList, Text, ActivityIndicator, RefreshControl, TouchableOpacity, Image, } from 'react-native'; import { DatePicker, List, Provider, InputItem, SwipeAction, Drawer, } from '@ant-design/react-native'; import public_css from '../../source/css/public_css'; import moment from 'moment'; import {RetrieveData} from '../../data/storage'; import {GetDataPost} from '../../data/encryption'; import {ShowToast} from '../../components/rootToast/root_toast'; import invoice_head_css from './invoice_head_css'; let pageNo = 1; //当前第几页 let totalPage = 5; //总的页数 export default class invoice_head extends Component { constructor(props) { super(props); this.props.navigation.dangerouslyGetParent().setOptions({ tabBarVisible: false, }); this.state = { isShowSearch: false, clickNum: 0, customerName: '', customerEntTaxId: '', customerMobile: '', belongEntTaxId: '', entName: '', createTimeEnd: undefined, createTimeBegin: undefined, listData: [], status: 0, showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中 isLoading: false, isOpen: false, }; } render() { let draw = ( this.beginTimeChange(time)} format="YYYY-MM-DD"> 开始时间 this.endTimeChange(time)} format="YYYY-MM-DD"> 结束时间 { this.setState({ customerName: value, }); }} placeholder="请输入要查询的客户方名称"> 客户方名称: { this.setState({ customerEntTaxId: value, }); }} placeholder="请输入要查询的客户方税号"> 客户方税号: { this.setState({ customerMobile: value, }); }} placeholder="请输入要查询的客户方手机号"> 客户方手机号: { this.searchDataEmpty(); }}> 全部清除 this.initData()}> 查询 ); return ( (this.drawer = el)} onOpenChange={open => this.openStatus(open)} drawerBackgroundColor="#ccc" drawerWidth={300}> this.renderItem(item)} refreshControl={ { this.initData(); }} /> } ListFooterComponent={this._renderFooter.bind(this)} onEndReached={this._onEndReached.bind(this)} onEndReachedThreshold={0.1} /> ); } //判断是否点击了查询 shouldComponentUpdate( nextProps: Readonly

, nextState: Readonly, nextContext: any, ): boolean { if (nextProps.route.params != undefined) { if (nextProps.route.params.isShow) { if (this.state.clickNum === 0) { this.setState({ isShowSearch: true, }); this.drawer.openDrawer(); this.props.navigation.setParams({ isShow: false, }); return true; } } } return true; } //查询菜单开关状态 openStatus = open => { if (open) { } else { // this.props.children.setClickNum(); } }; //获取查询开始时间 beginTimeChange = time => { this.setState({ createTimeBegin: time, }); }; //获取查询结束时间 endTimeChange = time => { this.setState({ createTimeEnd: time, }); }; //清空查询数据 searchDataEmpty = () => { this.setState({ customerName: '', customerEntTaxId: '', customerMobile: '', createTimeEnd: undefined, createTimeBegin: undefined, }); }; //数据初始化 initData = () => { this.setState({ listData: [], isLoading: false, showFoot: 0, status: 0, }); pageNo = 1; this.getInvoiceHeads(); }; //上拉加载 _onEndReached() { if (this.state.showFoot === 0) { if (pageNo >= totalPage) { this.setState({showFoot: 1}); return; } else { pageNo++; this.setState({showFoot: 2}); //获取数据 this.getInvoiceHeads(); } } } //列表尾部显示 _renderFooter = () => { if (this.state.showFoot === 1) { return ( 没有更多数据了 ); } else if (this.state.showFoot === 2) { return ( 正在加载更多数据... ); } else if (this.state.showFoot === 0) { return ( ); } }; //页面加载完成后加载数据 componentDidMount(): void { this.getInvoiceHeads(); } //页面销毁 componentWillUnmount(): void { this.setState({ listData: [], isLoading: false, showFoot: 0, status: 0, }); pageNo = 1; } //获取抬头列表数据 getInvoiceHeads = async () => { let beginTime = ''; let endTime = ''; if (this.state.createTimeBegin != undefined) { beginTime = moment(this.state.createTimeBegin).format('YYYY-MM-DD'); beginTime = beginTime + ' 00:00:00'; } if (this.state.createTimeEnd != undefined) { endTime = moment(this.state.createTimeEnd).format('YYYY-MM-DD'); endTime = endTime + ' 23:59:59'; } let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { account = account.substring(1, account.length - 1); token = token.substring(1, token.length - 1); const url = '/sys/taitou/todo/findPage'; GetDataPost( url, token, { mobile: account, reqChannel: 3, pageNum: pageNo, pageSize: 10, createTimeEnd: endTime, createTimeBegin: beginTime, customerName: this.state.customerName, customerEntTaxId: this.state.customerEntTaxId, customerMobile: this.state.customerMobile, belongEntTaxId: '', }, false, 2, ).then(res => { totalPage = res.data.pages; this.setList(res.data.records); }); } }; //设置抬头列表 setList = data => { let listDatas = data.map((_, i) => ({ key: data[i].recordId, customerName: data[i].customerName, customerEntTaxId: data[i].customerEntTaxId, address: data[i].address, contactPhone: data[i].contactPhone, bankName: data[i].bankName, bankAccountNo: data[i].bankAccountNo, customerEmail: data[i].customerEmail, customerMobile: data[i].customerMobile, remark: data[i].remark, belongEntTaxId: data[i].belongEntTaxId, entName: data[i].entName, })); let list = this.state.listData.concat(listDatas); this.setState({ listData: list, showFoot: 0, }); }; //显示发票抬头列表 renderItem = data => ( this.props.navigation.navigate('invoice_head_product_list', data.item) }> {data.item.customerName} 企业税号: {data.item.customerEntTaxId} 联系电话: {data.item.contactPhone} 开户银行: {data.item.bankName} 银行账号: {data.item.bankAccountNo} 地址: {data.item.address} 备注: {data.item.remark} ); //左滑显示删除按钮 right = data => [ { text: '删除', onPress: () => { this.deleteData(data.item); }, style: {backgroundColor: 'red', color: 'white'}, }, ]; //删除发票抬头信息 deleteData = async data => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (account && token) { account = account.substring(1, account.length - 1); token = token.substring(1, token.length - 1); const url = '/sys/taitou/todo/delete'; GetDataPost( url, token, { mobile: account, reqChannel: 3, delList: [ { recordId: data.key, belongEntTaxId: data.belongEntTaxId, }, ], }, false, 1, ) .then(res => { if (res) { if (res.code === 0) { ShowToast('删除成功'); this.initData(); } else { ShowToast('删除失败'); } } else { ShowToast('删除失败'); } }) .catch(err => { ShowToast('删除失败'); }); } }; }