123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- import React, {Component} from 'react';
- import {
- View,
- FlatList,
- Text,
- ActivityIndicator,
- RefreshControl,
- TouchableOpacity,
- Image, Alert,
- } from "react-native";
- import {
- DatePicker,
- List,
- Provider,
- InputItem,
- SwipeAction,
- Drawer,
- WingBlank,
- } from "@ant-design/react-native";
- import public_css from '../../source/css/public_css';
- import moment from 'moment';
- import {RetrieveData} from '../../data/storage';
- import {RequestNetwork} from '../../data/encryption';
- import invoice_head_css from './invoice_head_css';
- import { ToastShow } from "../../components/toast/toast";
- import { CleanAll } from "../../components/abnormalMessage/abnormal_message";
- let pageNo = 1; //当前第几页
- let totalPage = 5; //总的页数
- export default class invoice_head_list 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 = (
- <View style={public_css.body}>
- <View style={{flex: 1}}>
- <View>
- <List>
- <DatePicker
- value={this.state.createTimeBegin}
- mode="date"
- defaultDate={new Date()}
- minDate={new Date(2020, 0, 1)}
- maxDate={new Date(2030, 11, 3)}
- onChange={(time) => this.beginTimeChange(time)}
- format="YYYY-MM-DD">
- <List.Item arrow="horizontal">开始时间</List.Item>
- </DatePicker>
- </List>
- </View>
- <View>
- <List>
- <DatePicker
- value={this.state.createTimeEnd}
- mode="date"
- defaultDate={new Date()}
- minDate={this.state.createTimeBegin}
- maxDate={new Date(2030, 11, 3)}
- onChange={(time) => this.endTimeChange(time)}
- format="YYYY-MM-DD">
- <List.Item arrow="horizontal">结束时间</List.Item>
- </DatePicker>
- </List>
- </View>
- <InputItem
- clear
- value={this.state.customerName}
- onChange={(value) => {
- this.setState({
- customerName: value,
- });
- }}
- placeholder="请输入要查询的客户方名称">
- 客户方名称:
- </InputItem>
- <InputItem
- clear
- value={this.state.customerEntTaxId}
- onChange={(value) => {
- this.setState({
- customerEntTaxId: value,
- });
- }}
- placeholder="请输入要查询的客户方税号">
- 客户方税号:
- </InputItem>
- <InputItem
- clear
- value={this.state.customerMobile}
- onChange={(value) => {
- this.setState({
- customerMobile: value,
- });
- }}
- placeholder="请输入要查询的客户方手机号">
- 客户方手机号:
- </InputItem>
- </View>
- <View style={public_css.bottomStatus}>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusLBtn]}
- onPress={() => {
- this.searchDataEmpty();
- }}>
- <Image
- source={require('../../source/img/productImg/clear.png')}
- style={{width: 32, height: 32}}
- />
- <Text>全部清除</Text>
- </TouchableOpacity>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusRBtn]}
- onPress={() => this.initData()}>
- <Image
- source={require('../../source/img/productImg/confirm.png')}
- style={{width: 32, height: 32}}
- />
- <Text style={{color: '#fff'}}>查询</Text>
- </TouchableOpacity>
- </View>
- </View>
- );
- return (
- <View style={{flex: 1}}>
- <Provider>
- <Drawer
- sidebar={draw}
- position="right"
- open={false}
- drawerRef={(el) => (this.drawer = el)}
- onOpenChange={(open) => this.openStatus(open)}
- drawerBackgroundColor="#ccc"
- drawerWidth={300}>
- <View style={invoice_head_css.container}>
- <FlatList
- data={this.state.listData}
- renderItem={(item) => this.renderItem(item)}
- refreshControl={
- <RefreshControl
- title={'加载中...'}
- colors={['#B7B7B7']} //此颜色无效
- tintColor={'#B7B7B7'}
- titleColor={'#B7B7B7'} //只有ios有效
- refreshing={this.state.isLoading}
- onRefresh={() => {
- this.initData();
- }}
- />
- }
- ListFooterComponent={this._renderFooter.bind(this)}
- onEndReached={this._onEndReached.bind(this)}
- onEndReachedThreshold={0.1}
- />
- </View>
- </Drawer>
- </Provider>
- </View>
- );
- }
- //判断是否点击了查询
- shouldComponentUpdate(
- nextProps: Readonly<P>,
- nextState: Readonly<S>,
- 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 (
- <View
- style={{
- height: 30,
- alignItems: 'center',
- justifyContent: 'flex-start',
- }}>
- <Text
- style={{
- color: '#999999',
- fontSize: 14,
- marginTop: 5,
- marginBottom: 5,
- }}>
- 没有更多数据了
- </Text>
- </View>
- );
- } else if (this.state.showFoot === 2) {
- return (
- <View style={invoice_head_css.footer}>
- <ActivityIndicator />
- <Text>正在加载更多数据...</Text>
- </View>
- );
- } else if (this.state.showFoot === 0) {
- return (
- <View style={invoice_head_css.footer}>
- <Text />
- </View>
- );
- }
- };
- //页面加载完成后加载数据
- componentDidMount(): void {
- this.getInvoiceHeads();
- }
- // 清空数据重新加载
- cleanData = async () => {
- this.setState({
- listData: [],
- isLoading: false,
- showFoot: 0,
- status: 0,
- });
- pageNo = 1;
- await this.getInvoiceHeads();
- };
- //获取抬头列表数据
- 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');
- let company = JSON.parse(await RetrieveData('company'));
- if (token && account) {
- const url = '/sys/taitou/todo/findPage';
- let res = await RequestNetwork(
- 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: company.entTaxId,
- },
- false,
- 2,
- );
- if (res) {
- if (res.code === 0) {
- totalPage = res.data.pages;
- this.setList(res.data.records);
- } else {
- await this.abnormalMessage(res);
- }
- }
- }
- };
- //设置抬头列表
- 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,
- status: data[i].status,
- entName: data[i].entName,
- createTime: data[i].createTime,
- customerType: data[i].customerType,
- interactType: data[i].interactType,
- interactTypeDetail: data[i].interactTypeDetail,
- belongEntName: data[i].belongEntName,
- }));
- let list = this.state.listData.concat(listDatas);
- this.setState({
- listData: list,
- showFoot: 0,
- });
- };
- //显示发票抬头列表
- renderItem = (data) => (
- <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
- <List.Item style={{backgroundColor: '#F7F7F7'}}>
- <View style={{backgroundColor: '#ffffff'}}>
- <View style={{margin: 10}}>
- <Text
- style={{fontWeight: 'bold', fontSize: 16, color: '#050505'}}
- ellipsizeMode={'tail'}
- numberOfLines={1}>
- 发票抬头:{data.item.customerName}
- </Text>
- <Text style={{color: '#898989', marginTop: 5}}>
- 税号:{data.item.customerEntTaxId}
- </Text>
- </View>
- <WingBlank>
- <View style={{borderTopWidth: 1, borderColor: '#D9D9D9'}} />
- </WingBlank>
- <View style={{flexDirection: 'row', margin: 10}}>
- <View style={{flex: 1, justifyContent: 'center'}}>
- <Text>{data.item.createTime}</Text>
- </View>
- <View style={{flexDirection: 'row', flex: 1}}>
- <TouchableOpacity
- style={{
- flex: 1,
- borderWidth: 1,
- justifyContent: 'center',
- alignItems: 'center',
- borderColor: '#CCCCCC',
- borderRadius: 30,
- height: 30,
- }}
- onPress={() => {
- this.deleteData(data);
- }}>
- <Text style={{color: '#666666'}}>删除</Text>
- </TouchableOpacity>
- <TouchableOpacity
- style={{
- flex: 1,
- borderWidth: 1,
- justifyContent: 'center',
- alignItems: 'center',
- borderColor: '#2A67FE',
- borderRadius: 30,
- height: 30,
- marginLeft: 5,
- }}
- onPress={() => {
- this.props.navigation.navigate('invoice_head', {
- invoiceData: data,
- });
- }}>
- <Text style={{color: '#2A67FE'}}>点击开票</Text>
- </TouchableOpacity>
- </View>
- </View>
- </View>
- </List.Item>
- </SwipeAction>
- );
- //左滑显示删除按钮
- right = (data) => [
- {
- text: '删除',
- onPress: () => {
- this.deleteData(data.item);
- },
- style: {backgroundColor: 'red', color: 'white'},
- },
- ];
- //删除发票抬头信息
- deleteData = async (data) => {
- let company = JSON.parse(await RetrieveData('company'));
- let account = await RetrieveData('account');
- let token = await RetrieveData('token');
- if (account && token) {
- const url = '/sys/taitou/todo/delete';
- let res = await RequestNetwork(
- url,
- token,
- {
- mobile: account,
- reqChannel: 3,
- delList: [
- {
- recordId: data.item.key,
- belongEntTaxId: company.entTaxId,
- },
- ],
- },
- false,
- 1,
- );
- if (res) {
- if (res.code === 0) {
- ToastShow(1, '删除成功!');
- await this.cleanData();
- } else {
- ToastShow(1, res.msg);
- }
- }
- }
- };
- // 处理网络请求数据
- abnormalMessage = async (jason) => {
- if (jason.code === 401) {
- await Alert.alert(
- '登录失效',
- '登录状态已失效,请重新登录!',
- [
- {
- text: '确定',
- onPress: () => {
- CleanAll();
- this.props.navigation.popToTop();
- },
- },
- ],
- {cancelable: false},
- );
- }
- if (jason.code === 403) {
- Alert.alert(
- '权限',
- '暂无权限操作此模块!',
- [
- {
- text: '确定',
- onPress: () => {
- this.props.navigation.goBack();
- },
- },
- ],
- {cancelable: false},
- );
- }
- if (jason.code !== 401 && jason.code !== 403) {
- ToastShow(1, jason.msg);
- }
- };
- }
|