123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- import React, {Component} from 'react';
- import {FlatList, Alert, SafeAreaView, DeviceEventEmitter} from 'react-native';
- import {SwipeAction, Radio} from '@ant-design/react-native';
- import {RetrieveData, IndividualStorageData} from '../../../data/storage';
- import {RequestNetwork} from '../../../data/encryption';
- import Spinner from 'react-native-loading-spinner-overlay';
- import loading_css from '../../../source/css/loading_css';
- import public_css from '../../../source/css/public_css';
- import {CleanAll} from '../../../components/abnormalMessage/abnormal_message';
- import {ToastShow} from '../../../components/toast/toast';
- const RadioItem = Radio.RadioItem;
- export default class device extends Component {
- constructor(props) {
- super(props);
- this.state = {
- listData: [],
- status: 0,
- isLoading: false,
- loadingText: 'loading',
- entTaxId: '',
- companyName: '',
- deviceKey: '',
- };
- }
- render() {
- return (
- <SafeAreaView style={public_css.body}>
- <FlatList
- data={this.state.listData}
- renderItem={(item) => this.renderItem(item)}
- />
- </SafeAreaView>
- );
- }
- //页面加载完成后加载数据
- async componentDidMount() {
- let deviceKey = this.props.route.params.deviceKey;
- console.log(deviceKey);
- this.setState({
- deviceKey: deviceKey,
- });
- await this.getDeviceList();
- }
- //搜索
- searchData = async (text) => {
- this.setState({
- listData: [],
- companyName: text,
- showFoot: 0,
- pageNo: 1,
- });
- await this.getCompanyList();
- };
- //数据初始化
- initData = () => {
- this.setState({
- listData: [],
- isLoading: false,
- showFoot: 0,
- status: 0,
- pageNo: 1,
- companyName: '',
- });
- this.getCompanyList();
- };
- //列表上拉加载
- onEndReached = async () => {
- if (this.state.showFoot === 2) {
- if (this.state.pageNo >= this.state.totalPage) {
- this.setState({showFoot: 0});
- return;
- } else {
- this.setState({showFoot: 1, pageNo: this.state.pageNo + 1});
- await this.getCompanyList();
- }
- }
- };
- //获取数据
- getDeviceList = async () => {
- let company = await RetrieveData('company');
- if (company) {
- company = JSON.parse(company);
- }
- const token = await RetrieveData('token');
- if (token && company) {
- const url = '/sys/entDevice/findDevices';
- let response = await RequestNetwork(
- url,
- token,
- {
- entTaxId: company.entTaxId,
- },
- false,
- 2,
- );
- if (response) {
- if (response.code === 0) {
- this.setList(response.data);
- } else {
- await this.abnormalMessage(response);
- }
- }
- }
- };
- //设置设备列表
- setList = (data) => {
- let listData = data.map((_, i) => ({
- deviceType: data[i].deviceType,
- taxDiscId: data[i].taxDiscId,
- deviceLabel: data[i].deviceLabel,
- deviceId: data[i].deviceId,
- deviceKey: data[i].deviceKey,
- entTaxId: data[i].entTaxId,
- }));
- let list = this.state.listData.concat(listData);
- this.setState({
- showFoot: 0,
- isLoading: false,
- listData: list,
- });
- };
- //切换设备信息
- onChange = async (value) => {
- console.log(value);
- this.props.route.params.getDeviceInfo(value.item);
- this.props.navigation.goBack();
- };
- //显示发票抬头列表
- renderItem = (data) => (
- <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
- <RadioItem
- key={data.item.deviceId}
- checked={data.item.deviceKey === this.state.deviceKey}
- onChange={async (event) => {
- if (event.target.checked) {
- await this.onChange(data);
- }
- }}>
- {data.item.deviceLabel}
- </RadioItem>
- </SwipeAction>
- );
- // 设置load层是否显示
- setLoadingStatus = (isLoading) => {
- this.setState({
- spinner: isLoading,
- });
- };
- // 处理网络请求数据
- 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);
- }
- };
- }
|