123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- import React, {Component} from 'react';
- import {
- View,
- Image,
- Text,
- Dimensions,
- FlatList,
- RefreshControl,
- ActivityIndicator,
- DeviceEventEmitter,
- SafeAreaView,
- } from 'react-native';
- import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
- import ActionButton from 'react-native-action-button';
- import Icon from 'react-native-vector-icons/Ionicons';
- import {RetrieveData} from '../../../data/storage';
- import {RequestNetwork} from '../../../data/encryption';
- import customer_css from './customer_css';
- import public_css from '../../../source/css/public_css';
- import { ToastShow } from "../../../components/toast/toast";
- let pageNo = 1; //当前第几页
- let totalPage = 5; //总的页数
- export default class customer_list extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- this.state = {
- listData: [],
- search_data: '',
- showFoot: 0, // 控制foot, 0:隐藏footer 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.search_data}
- // onSubmit={value => Alert.alert(value)}
- onCancel={() => this.searchClear()}
- onChange={(value) => this.searchData(value)}
- showCancelButton={false}
- style={{borderRadius: 15}}
- />
- </View>
- <View style={customer_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>
- <ActionButton
- buttonColor="rgba(50,100,235,1)"
- onPress={() => {
- this.props.navigation.navigate('customer_add_or_edit', {
- companyId: null,
- refresh: () => {
- this.refresh();
- },
- });
- }}
- renderIcon={() => (
- <Icon name="md-add-outline" style={customer_css.actionButtonIcon} />
- )}
- />
- </SafeAreaView>
- );
- }
- //搜索数据
- searchData = (value) => {
- this.setState({
- search_data: value,
- });
- this.timer = setTimeout(() => {
- this.initData();
- }, 1000);
- };
- //清空搜索
- searchClear = () => {
- this.setState({
- search_data: '',
- });
- this.initData();
- };
- //数据初始化
- initData = async () => {
- this.setState({
- listData: [],
- isLoading: false,
- showFoot: 0,
- });
- pageNo = 1;
- await this.getCustomerData();
- };
- //上拉加载
- _onEndReached() {
- if (this.state.showFoot === 0) {
- if (pageNo >= totalPage) {
- this.setState({showFoot: 1});
- return;
- } else {
- pageNo++;
- this.setState({showFoot: 2});
- //获取数据
- this.getCustomerData();
- }
- }
- }
- //显示list尾部
- _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={customer_css.footer}>
- <ActivityIndicator />
- <Text>正在加载更多数据...</Text>
- </View>
- );
- } else if (this.state.showFoot === 0) {
- return (
- <View style={customer_css.footer}>
- <Text />
- </View>
- );
- }
- }
- //显示页面加载
- componentDidMount(): void {
- this.getCustomerData();
- //收到监听
- // this.listener = DeviceEventEmitter.addListener('刷新列表', (message) => {
- // //收到监听后想做的事情
- // this.initData();
- // });
- }
- // 刷新列表
- refresh = () => {
- this.initData();
- };
- //关闭页面加载
- componentWillUnmount(): void {
- pageNo = 1;
- this.timer && clearTimeout(this.timer);
- //移除监听
- if (this.listener) {
- this.listener.remove();
- }
- }
- //获取客户数据
- getCustomerData = async () => {
- let account = await RetrieveData('account');
- let token = await RetrieveData('token');
- let company = JSON.parse(await RetrieveData('company'));
- if (token && account) {
- const url = '/sys/customer/findPage';
- let res = await RequestNetwork(
- url,
- token,
- {
- mobile: account,
- entTaxId: company.entTaxId,
- reqChannel: 3,
- pageNum: pageNo,
- pageSize: 10,
- customerName: this.state.search_data,
- },
- false,
- 2,
- );
- if (res) {
- if (res.code === 0) {
- totalPage = res.data.pages;
- this.setList(res.data.records);
- }
- }
- }
- };
- //设置客户数据列表
- setList = (data) => {
- console.log(data);
- let listDatas = data.map((_, i) => ({
- key: data[i].customerId,
- customerName: data[i].customerName,
- entTaxId: data[i].entTaxId,
- customerMobile: data[i].customerMobile,
- manageUserId: data[i].manageUserId,
- customerType: data[i].customerType,
- email: data[i].email,
- }));
- 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'}}
- onPress={() => {
- this.props.navigation.navigate('customer_add_or_edit', {
- companyId: data.item.key,
- refresh: () => {
- this.refresh();
- },
- });
- }}>
- <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>
- );
- }
|