import React, {Component} from 'react'; import { Image, Text, View, TouchableOpacity, DeviceEventEmitter, Alert, SafeAreaView, ScrollView, Linking, } from 'react-native'; import {WhiteSpace, WingBlank, List, Modal} from '@ant-design/react-native'; import personal_center_css from './personal_center_css'; import public_css from '../../source/css/public_css'; import { RetrieveData, ClearAll, IndividualStorageData, } from '../../data/storage'; import Spinner from 'react-native-loading-spinner-overlay'; import loading_css from '../../source/css/loading_css'; import {RequestNetwork} from '../../data/encryption'; import LinearGradient from 'react-native-linear-gradient'; import {GetMonthDate} from '../../utils/date'; import {ToastShow} from '../../components/toast/toast'; import FastImage from 'react-native-fast-image'; import { CleanAll } from "../../components/abnormalMessage/abnormal_message"; const Item = List.Item; export default class personal_center extends Component { constructor(props) { super(props); this.state = { userName: '', userType: '', spinner: false, user: '', loginText: '点击登录', infoText: '立即登陆体验完整功能', telPhone: 'tel:0871-63193319', headImage: '', sex: '', invoiceNumber: '——', companyNumber: '——', messageNumber: '——', lastLoginDate: '——', membershipStatus: '请登录查看您的会员状态', isShowText: '展开', isShow: false, productList: [], productNumber: 0, isShowMore: false, }; } render() { return ( {this.state.headImage === '' || this.state.headImage === null ? ( this.state.sex === 'F' ? ( ) : ( ) ) : ( )} {this.state.userName === '' ? ( this.props.navigation.navigate('login', { refresh: (type) => { this.refresh(type); }, }) }> {this.state.loginText} ) : ( {this.state.userName} )} {this.state.userName === '' ? ( {this.state.infoText} ) : ( this.getLandingStatus(1)}> {this.state.infoText} )} {this.state.invoiceNumber} 本月正数开具 {this.state.companyNumber} 绑定企业 {this.state.messageNumber} 短信剩余 {/**/} {/**/} {/* */} {/* {this.state.lastLoginDate}*/} {/* */} {/* 上次登录*/} {/**/} {/**/} {/* */} {/* */} {/* */} {/* 报税旗舰版*/} {/* */} {/* */} {/* */} {/* {*/} {/* this.getLandingStatus(3);*/} {/* }}>*/} {/* */} {/* 产品调整*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* {this.state.productList.map((item) => {*/} {/* return (*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* {item.title}*/} {/* {item.data}*/} {/* */} {/* */} {/* );*/} {/* })}*/} {/* */} {/* {this.state.isShowMore === true ? (*/} {/* */} {/* {*/} {/* this.showProductInfo();*/} {/* }}>*/} {/* */} {/* {this.state.isShowText}*/} {/* */} {/* {this.state.isShow === true ? (*/} {/* */} {/* ) : (*/} {/* */} {/* )}*/} {/* */} {/* */} {/* ) : (*/} {/* */} {/* )}*/} {/**/} { this.getLandingStatus(2); }}> 绑定企业 { this.contactService(); }}> 联系客服 { this.props.navigation.navigate('about'); }}> 关于 { this.props.navigation.navigate('set', { refresh: (type) => { this.refresh(type); }, }); }}> 设置 ); } //页面加载获取信息 async componentDidMount(): void { await this.getSignIn(); // 收到监听 this.listener = DeviceEventEmitter.addListener( 'updateLoginInfo', message => { // 收到监听后想做的事情 // 监听 this.refresh(message); }, ); // 收到监听 this.listenerPersonal = DeviceEventEmitter.addListener( 'updatePersonal', (message) => { // 收到监听后想做的事情 // 监听 this.refresh(message); }, ); } componentWillUnmount() { // 移除监听 if (this.listener) { this.listener.remove(); } if (this.listenerPersonal) { this.listenerPersonal.remove(); } } refresh = async (type) => { if (type) { await this.getSignIn(); } else { this.setState({ userName: '', userType: '', user: '', loginText: '点击登录', infoText: '立即登陆体验完整功能', headImage: '', sex: '', invoiceNumber: '——', companyNumber: '——', messageNumber: '——', lastLoginDate: '——', membershipStatus: '请登录查看您的会员状态', isShowText: '展开', isShow: false, productList: [], productNumber: 0, isShowMore: false, }); this.props.navigation.setOptions({ headerTitle: '会员中心', }); } }; //获取登录信息 getSignIn = async () => { let title = '会员中心'; let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); title = company.entName; } this.props.navigation.setOptions({ headerTitle: title, }); let userHeadImg = JSON.parse(await RetrieveData('userHeadImg')); let userName = await RetrieveData('userName'); let userType = await RetrieveData('usertype'); let token = await RetrieveData('token'); let account = await RetrieveData('account'); if (userName && userType && token && account) { this.setState({ userName: userName, userType: userType, infoText: '查看或编辑个人资料 >', membershipStatus: '您的服务到剩余日期:--天', }); await this.getUserInformation(account, token); await this.getCompanyList(); await this.getMessageNumber(); await this.getInvoiceNumber(); await this.getProductList(); } if (userHeadImg) { this.setState({ headImage: userHeadImg.headImage, sex: userHeadImg.sex, }); } else { this.setState({ headImage: '', sex: '', }); } }; //获取用户信息 getUserInformation = async (account, token) => { const url = '/auth/comm/user/personalInfo/find'; let response = await RequestNetwork( url, token, { mobile: account, }, false, 2, ); if (response) { if (response.code === 0) { console.log(response); await IndividualStorageData('userInfo', JSON.stringify(response.data)); this.setState({ user: response.data, }); } } }; //退出登录 signOut = async () => { this.setLoadingStatus(true); await ClearAll(); this.setLoadingStatus(false); DeviceEventEmitter.emit('updateCurMon', null); this.props.navigation.navigate('home_navigation'); }; // 联系客服 contactService = () => { Modal.alert('提示', '0871-63193319', [ { text: '取消', onPress: () => console.log('cancel'), style: 'cancel', }, { text: '确认', onPress: () => { Linking.canOpenURL(this.state.telPhone) .then((supported) => { if (!supported) { console.log('Can not handle tel: ' + this.state.telPhone); } else { return Linking.openURL(this.state.telPhone); } }) .catch((error) => console.log('tel error', error)); }, }, ]); }; //显示loading层 setLoadingStatus(isLoading) { this.setState({ spinner: isLoading, }); } //判断是否登录 getLandingStatus = async (type) => { const account = await RetrieveData('account'); if (account) { if (type === 1) { this.props.navigation.navigate('personal_information', { user: this.state.user, refresh: type => { this.refresh(type); }, }); } if (type === 2) { this.props.navigation.navigate('enterprise_list'); } if (type === 3) { this.props.navigation.navigate('service_handle'); } } else { this.props.navigation.navigate('login'); } }; //获取企业数据 getCompanyList = async () => { const entInfo = JSON.parse(await RetrieveData('company')); this.setState({entItem: entInfo}); const token = await RetrieveData('token'); const account = await RetrieveData('account'); if (token && account) { const url = '/auth/ent/user/findManageInfoByMobile'; let response = await RequestNetwork( url, token, { entUserMobile: account, pageNum: 1, pageSize: 10, }, false, 2, ); if (response) { if (response.code === 0) { this.setState({ companyNumber: response.data.total, }); } else { await this.abnormalMessage(response); } } } }; //获取短信数量 getMessageNumber = async () => { let company = JSON.parse(await RetrieveData('company')); let token = await RetrieveData('token'); if (token && company) { const url = '/marketing/ent/features/findPage'; let res = await RequestNetwork( url, token, { entTaxId: company.entTaxId, featureId: 'F0000001', featureName: '短信服务', pageNum: 1, pageSize: 10, }, false, 2, ); if (res) { if (res.code === 0) { res.data.records.map((item) => { if (item.featureId === 'F0000001') { this.setState({ messageNumber: parseFloat(item.surplus), }); } }); } else { await this.abnormalMessage(res); } } } }; //获取发票数量统计 getInvoiceNumber = async () => { let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); } const token = await RetrieveData('token'); const account = await RetrieveData('account'); if (token && company) { let date = GetMonthDate(); const url = '/sys/invoiceExt/reports'; let response = await RequestNetwork( url, token, { entTaxId: company.entTaxId, deviceType: company.defaultDeviceInfo.deviceType, taxDiscId: company.defaultDeviceInfo.taxDiscId, mobile: account, invoiceDateBegin: date.startDateTime, invoiceDateEnd: date.endDateTime, reqChannel: 3, }, false, 2, ); if (response) { if (response.code === 0) { this.setState({ invoiceNumber: response.data.blueInvoiceCnt, }); } else { await this.abnormalMessage(response); } } } }; // 产品信息展示状态变更 showProductInfo = () => { if (this.state.isShow) { this.setState({ isShow: false, isShowText: '展开', }); } else { this.setState({ isShow: true, isShowText: '收起', }); } }; //获取最近一次登录时间 getLastLoginDate = async () => { const account = await RetrieveData('account'); let token = await RetrieveData('token'); console.log(123); console.log(account); if (token) { const url = '/auth/log/findPage'; let res = await RequestNetwork( url, token, { mobile: account, opType: '用户登录', pageNum: 1, pageSize: 2, }, false, 2, ); if (res) { if (res.code === 0) { console.log('登录信息'); console.log(res); // res.data.records.map((item) => { // if (item.featureId === 'F0000001') { // this.messageNumber = parseFloat(item.surplus); // } // }); } else { await this.abnormalMessage(res); } } } }; // 获取已开通产品列表 getProductList = async () => { let company = await RetrieveData('company'); if (company) { company = JSON.parse(company); } let token = await RetrieveData('token'); if (token && company) { const url = '/marketing/ent/features/findPage'; let res = await RequestNetwork( url, token, { entTaxId: company.entTaxId, }, false, 2, ); if (res) { if (res.code === 0) { let isShow = false; if (res.data.total > 2) { isShow = true; } else { isShow = false; } let list = []; res.data.records.map((item) => { let title: ''; let data = ''; if (item.limitType === '1') { title = item.featureName + '到期时间'; data = item.endDate; } if (item.limitType === '2') { title = item.featureName + '剩余数量'; if (item.surplus) { data = parseInt(item.surplus).toString() + '条'; } else { data = 0; } } let productList = { title: title, data: data, img: item.featureImgUrl, }; list = list.concat(productList); }); this.setState({ productList: list, productNumber: res.data.total, isShowMore: isShow, }); } else { await this.abnormalMessage(res); } } } }; // 处理网络请求数据 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); } }; }