import React, {Component} from 'react';
import {
View,
Text,
Dimensions,
FlatList,
RefreshControl,
ActivityIndicator,
DeviceEventEmitter,
} from 'react-native';
import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
import {RetrieveData} from '../../data/storage';
import {GetDataPost} from '../../data/encryption';
import service_provider_css from './service_provider_css';
let pageNo = 1; //当前第几页
let totalPage = 5; //总的页数
export default class service_provider_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}
/>
);
}
//搜索数据
searchData = (value) => {
this.setState({
search_data: value,
});
this.timer = setTimeout(() => {
this.initData();
}, 1000);
};
//清空搜索
searchClear = () => {
this.setState({
search_data: '',
});
this.initData();
};
//数据初始化
initData = () => {
this.setState({
listData: [],
isLoading: false,
showFoot: 0,
});
pageNo = 1;
this.getServiceData();
};
//上拉加载
_onEndReached() {
if (this.state.showFoot === 0) {
if (pageNo >= totalPage) {
this.setState({showFoot: 1});
return;
} else {
pageNo++;
this.setState({showFoot: 2});
//获取数据
this.getServiceData();
}
}
}
//显示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.getServiceData();
//收到监听
this.listener = DeviceEventEmitter.addListener('刷新用户列表', (data) => {
//收到监听后想做的事情
this.initData();
});
}
//关闭页面加载
componentWillUnmount(): void {
pageNo = 1;
this.timer && clearTimeout(this.timer);
//移除监听
if (this.listener) {
this.listener.remove();
}
}
//获取服务商列表
getServiceData = async () => {
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 = 'https://app.taxbk.cn:9443/auth/isp/info/findPage';
let response = await GetDataPost(
url,
token,
{
pageNum: pageNo,
pageSize: 10,
name: this.state.search_data,
},
false,
2,
);
if (response) {
if (response.code == 0) {
totalPage = response.data.pages;
this.setList(response.data.records);
}
}
}
};
//设置客户数据列表
setList = (data) => {
let listDatas = data.map((_, i) => ({
key: data[i].ispId,
name: data[i].name,
contactPhone: data[i].contactPhone,
contactName: data[i].contactName,
address: data[i].address,
joinDate: data[i].joinDate,
}));
let list = this.state.listData.concat(listDatas);
this.setState({
listData: list,
showFoot: 0,
});
};
//加载客户列表数据
renderItem = (data) => (
{
this.props.navigation.navigate('service_provider', {
service: data.item,
});
}}>
{data.item.name}
{data.item.contactPhone}
);
//显示侧滑按钮
right = (data) => [
{
text: '编辑',
onPress: () =>
this.props.navigation.navigate('personnel_edit', {
personnel: data.item,
}),
style: {backgroundColor: 'orange', color: 'white'},
},
{
text: '删除',
onPress: () => {
this.deleteData(data.item);
},
style: {backgroundColor: 'red', color: 'white'},
},
];
}