123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- import React, {Component} from 'react';
- import {
- View,
- Text,
- FlatList,
- RefreshControl,
- Alert,
- SafeAreaView,
- Image,
- StyleSheet,
- Dimensions,
- PixelRatio,
- } from 'react-native';
- import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
- import {RetrieveData} from '../../data/storage';
- import {RequestNetwork} from '../../data/encryption';
- import public_css from '../../source/css/public_css';
- import {Footer} from '../../components/listPage/pagination';
- import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
- import {ToastShow} from '../../components/toast/toast';
- let pageNo = 1; //当前页码
- let totalPage = 5; //总的页数
- let pageSize = 10; //每页数量
- export default class invoice_select_customer extends Component {
- constructor(props) {
- super(props);
- this.state = {
- listData: [],
- customerName: '',
- showFoot: 0, // 控制foot, 0:无数据 1:加载中 2 :上拉加载
- isLoading: false,
- };
- }
- render() {
- return (
- <SafeAreaView style={public_css.body}>
- <View
- style={{
- // width: Dimensions.get('window').width,
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: '#ffffff',
- height: 50,
- }}>
- <SearchBar
- placeholder="搜索"
- value={this.state.customerName}
- onCancel={() => this.searchClear()}
- onChange={(value) => this.searchData(value)}
- showCancelButton={false}
- style={{borderRadius: 15}}
- />
- </View>
- <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={() => Footer(this.state.showFoot)}
- // onEndReached={this._onEndReached.bind(this)}
- // onEndReachedThreshold={0.1}
- />
- </SafeAreaView>
- );
- }
- //页面渲染完成后加载
- async componentDidMount(): void {
- pageNo = 1;
- this.setState({
- listData: [],
- customerName: '',
- showFoot: 1,
- });
- await this.getCustomerData();
- }
- //搜索
- searchData = async (text) => {
- pageNo = 1;
- this.setState({
- listData: [],
- customerName: text,
- showFoot: 0,
- });
- await this.getCustomerData();
- };
- //初始化数据
- initData = async () => {
- pageNo = 1;
- this.setState({
- listData: [],
- customerName: '',
- showFoot: 1,
- isLoading: true,
- });
- await this.getCustomerData();
- };
- //清空搜索栏
- searchClear = async () => {
- await this.initData();
- };
- //获得客户信息
- getCustomerData = async () => {
- let token = await RetrieveData('token');
- let company = JSON.parse(await RetrieveData('company'));
- if (token) {
- const url = '/sys/customer/customerSearch';
- let res = await RequestNetwork(
- url,
- token,
- {
- customerName: this.state.customerName,
- entTaxId: company.entTaxId,
- reqChannel: 3,
- },
- false,
- 2,
- );
- if (res) {
- console.log(res);
- if (res.code === 0) {
- totalPage = res.data.pages;
- this.setList(res.data);
- } else {
- this.setState({
- showFoot: 0,
- });
- await this.abnormalMessage(res);
- }
- }
- }
- };
- //设置客户信息列表
- setList = (data) => {
- let listDatas = data.map((_, i) => ({
- key: data[i].customerId,
- customerName: data[i].customerName,
- entTaxId: data[i].customerEntTaxId,
- contactPhone: data[i].contactPhone,
- address: data[i].address,
- bankName: data[i].bankName,
- bankAccount: data[i].bankAccountNumber,
- customerMobile: data[i].customerMobile,
- email: data[i].email,
- }));
- let list = this.state.listData.concat(listDatas);
- if (list.length > 0) {
- this.setState({
- showFoot: 2,
- isLoading: false,
- listData: list,
- });
- } else {
- this.setState({
- showFoot: 0,
- isLoading: false,
- listData: list,
- });
- }
- };
- //加载列表数据
- renderItem = (data) => (
- <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
- <List.Item
- style={{backgroundColor: '#F7F7F7'}}
- onPress={() => {
- this.props.route.params.selectCustomer(data.item);
- this.props.navigation.goBack();
- }}>
- <View style={{backgroundColor: '#ffffff'}}>
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- margin: 5,
- borderBottomWidth: 1,
- borderBottomColor: '#E5E5E5',
- height: 50,
- }}>
- <View
- style={{
- borderWidth: 2,
- borderColor: '#2A67FE',
- height: 18,
- borderRadius: 3,
- }}
- />
- <View style={{marginLeft: 5, marginRight: 5, flex: 1}}>
- <Text
- style={{
- fontSize: 18,
- color: '#4B4B4B',
- fontWeight: 'bold',
- }}
- numberOfLines={1}
- ellipsizeMode={'tail'}>
- {data.item.customerName}
- </Text>
- </View>
- {data.item.customerType === 1 ? (
- <View
- style={{
- borderWidth: 1,
- borderColor: '#2A67FE',
- borderRadius: 6,
- width: 40,
- height: 20,
- }}>
- <Text
- style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>
- 个人
- </Text>
- </View>
- ) : (
- <View
- style={{
- borderWidth: 1,
- borderColor: '#2A67FE',
- borderRadius: 6,
- width: 40,
- height: 20,
- }}>
- <Text
- style={{color: '#2A67FE', fontSize: 13, textAlign: 'center'}}>
- 企业
- </Text>
- </View>
- )}
- </View>
- <View style={{margin: 10}}>
- <Text style={{color: '#808080', fontSize: 15}}>
- 企业税号:{data.item.entTaxId}
- </Text>
- </View>
- <View
- style={{
- flexDirection: 'row',
- height: 32,
- backgroundColor: '#F5F7FC',
- marginLeft: 10,
- marginRight: 10,
- }}>
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- flex: 1,
- marginLeft: 5,
- }}>
- {data.item.customerMobile === '' ? (
- <Text
- style={{
- fontSize: 14,
- color: '#808080',
- }}>
- 联系电话:暂未填写
- </Text>
- ) : (
- <Text
- style={{
- fontSize: 14,
- color: '#808080',
- }}>
- 联系电话:
- {data.item.customerMobile}
- </Text>
- )}
- </View>
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- margin: 5,
- flex: 1,
- }}>
- {data.item.email === '' ? (
- <Text
- style={{
- fontSize: 14,
- color: '#808080',
- }}>
- 邮箱:暂未填写
- </Text>
- ) : (
- <Text
- style={{
- fontSize: 14,
- color: '#808080',
- }}
- numberOfLines={1}
- ellipsizeMode={'tail'}>
- 邮箱:
- {data.item.email}
- </Text>
- )}
- </View>
- </View>
- <View style={{height: 10}} />
- </View>
- </List.Item>
- </SwipeAction>
- );
- //列表上拉加载
- _onEndReached = async () => {
- if (this.state.showFoot === 2) {
- if (pageNo >= totalPage) {
- this.setState({showFoot: 0});
- return;
- } else {
- pageNo++;
- this.setState({showFoot: 1});
- await this.getCustomerData();
- }
- }
- };
- // 处理网络请求数据
- 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);
- }
- };
- }
- const styles = StyleSheet.create({
- buttonView: {
- alignItems: 'center',
- backgroundColor: '#ffffff',
- },
- //通用按钮样式
- button: {
- marginTop: 5,
- width: Dimensions.get('window').width * 0.8,
- height: 34,
- borderRadius: 10,
- backgroundColor: '#1874CD',
- justifyContent: 'center',
- alignItems: 'center',
- },
- //通用按钮样式
- buttonText: {
- // fontSize: 22,
- textAlign: 'center',
- color: 'white',
- },
- inputView: {
- // flex: 1,
- padding: 5,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'center',
- display: 'flex',
- },
- view: {
- flexDirection: 'row',
- height: 34,
- width: Dimensions.get('window').width * 0.8,
- },
- //通用textInput样式
- text: {
- lineHeight: 34,
- fontSize: 14,
- },
- //通用textInput样式
- lineTopBottom: {
- borderBottomWidth: 3 / PixelRatio.get(),
- borderColor: 'rgb(208,208,208)',
- justifyContent: 'center',
- alignItems: 'center',
- },
- textInputStyle: {
- flex: 5,
- marginRight: 10,
- marginLeft: 20,
- fontSize: 14,
- marginTop: 4,
- },
- footer: {
- flexDirection: 'row',
- height: 24,
- justifyContent: 'center',
- alignItems: 'center',
- marginBottom: 10,
- },
- });
|