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 (
Alert.alert(value)}
onCancel={() => this.searchClear()}
onChange={(value) => this.searchData(value)}
showCancelButton={false}
style={{borderRadius: 15}}
/>
this.renderItem(item)}
refreshControl={
{
this.initData();
}}
/>
}
ListFooterComponent={this._renderFooter.bind(this)}
onEndReached={this._onEndReached.bind(this)}
onEndReachedThreshold={0.1}
/>
{
this.props.navigation.navigate('customer_add_or_edit', {
companyId: null,
refresh: () => {
this.refresh();
},
});
}}
renderIcon={() => (
)}
/>
);
}
//搜索数据
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 (
没有更多数据了
);
} else if (this.state.showFoot === 2) {
return (
正在加载更多数据...
);
} else if (this.state.showFoot === 0) {
return (
);
}
}
//显示页面加载
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) => (
{
this.props.navigation.navigate('customer_add_or_edit', {
companyId: data.item.key,
refresh: () => {
this.refresh();
},
});
}}>
{data.item.customerName}
{data.item.customerType === 1 ? (
个人
) : (
企业
)}
企业税号:{data.item.entTaxId}
{data.item.customerMobile === '' ? (
联系电话:暂未填写
) : (
联系电话:
{data.item.customerMobile}
)}
{data.item.email === '' ? (
邮箱:暂未填写
) : (
邮箱:
{data.item.email}
)}
);
}