123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- 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 personnel_css from './personnel_css';
- import {ShowToast} from '../../components/rootToast/root_toast';
- let pageNo = 1; //当前第几页
- let totalPage = 5; //总的页数
- export default class personnel_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 :显示加载中
- user_type: 1,
- isLoading: false,
- };
- }
- render() {
- return (
- <View style={{flex: 1, backgroundColor: '#ffffff'}}>
- <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={personnel_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>
- </View>
- );
- }
- //搜索数据
- 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.getPersonnelData();
- };
- //上拉加载
- _onEndReached() {
- if (this.state.showFoot === 0) {
- if (pageNo >= totalPage) {
- this.setState({showFoot: 1});
- return;
- } else {
- pageNo++;
- this.setState({showFoot: 2});
- //获取数据
- this.getPersonnelData();
- }
- }
- }
- //显示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={personnel_css.footer}>
- <ActivityIndicator />
- <Text>正在加载更多数据...</Text>
- </View>
- );
- } else if (this.state.showFoot === 0) {
- return (
- <View style={personnel_css.footer}>
- <Text />
- </View>
- );
- }
- }
- //显示页面加载
- componentDidMount(): void {
- this.getPersonnelData();
- this.getUserType();
- //收到监听
- this.listener = DeviceEventEmitter.addListener('刷新用户列表', (data) => {
- //收到监听后想做的事情
- this.initData();
- });
- }
- //获取用户类型
- getUserType = async () => {
- let userType = await RetrieveData('usertype');
- userType = userType.substring(1, userType.length - 1);
- this.setState({
- user_type: userType,
- });
- };
- //关闭页面加载
- componentWillUnmount(): void {
- pageNo = 1;
- this.timer && clearTimeout(this.timer);
- //移除监听
- if (this.listener) {
- this.listener.remove();
- }
- }
- //获取用户数据
- getPersonnelData = 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/comm/user/findChildUsers';
- let response = await GetDataPost(
- url,
- token,
- {
- currentUserMobile: account,
- reqChannel: 3,
- 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].id,
- name: data[i].name,
- mobile: data[i].mobile,
- status: data[i].status,
- deptId: data[i].deptId,
- userType: data[i].userType,
- manageUserId: data[i].manageUserId,
- deptName: data[i].deptName,
- }));
- let list = this.state.listData.concat(listDatas);
- this.setState({
- listData: list,
- showFoot: 0,
- });
- };
- //加载客户列表数据
- renderItem = (data) => (
- <SwipeAction
- autoClose
- style={{backgroundColor: 'transparent'}}
- right={this.right(data)}>
- <List.Item
- onPress={() => {
- // this.props.navigation.navigate('enterprise_see', {
- // enterprise: data.item,
- // });
- }}>
- <View style={{flex: 1}}>
- <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
- <View style={{flex: 1, alignItems: 'center'}}>
- <Text
- style={{
- fontSize: 18,
- fontFamily: 'PingFang-SC-Regular',
- color: '#333333',
- }}>
- {data.item.name}
- </Text>
- </View>
- <View style={{flex: 1, alignItems: 'center'}}>
- <Text
- style={{
- fontSize: 18,
- fontFamily: 'PingFang-SC-Regular',
- color: '#333333',
- }}>
- {data.item.mobile}
- </Text>
- </View>
- </View>
- </View>
- </List.Item>
- </SwipeAction>
- );
- //显示侧滑按钮
- 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'},
- },
- ];
- //提交数据
- submitData = () => {
- //服务商
- if (this.state.user_type == 2) {
- this.deletedIspUser();
- }
- //运营商
- if (this.state.user_type == 3) {
- this.deletedAuthUser();
- }
- };
- //删除服务商用户
- deletedIspUser = 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/user/delete';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: '',
- currentUserMobile: account,
- reqChannel: 3,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code == 0) {
- ShowToast('删除成功!');
- } else {
- ShowToast('删除失败!');
- }
- }
- }
- };
- //删除运营商用户
- deletedAuthUser = 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/oper/user/delete';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: '',
- currentUserMobile: account,
- reqChannel: 3,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code == 0) {
- ShowToast('删除成功!');
- } else {
- ShowToast('删除失败!');
- }
- }
- }
- };
- }
|