import React, {Component} from 'react'; import { StyleSheet, View, Text, ScrollView, Alert, DeviceEventEmitter } from 'react-native'; import {WhiteSpace, List, InputItem, Provider, Toast} from '@ant-design/react-native'; import {connect} from 'react-redux' import {Button} from "../../components"; import ReadUHF from "../../utils/ReadUHF"; @connect(home => ({...home})) class UHFDeliver extends Component { constructor(props) { super(props); this.state = { notes: '', distributor: '', distributor_name: '', type: this.props.navigation.state.params.type, no: '', total: 0, isStart: true, productDatas: [], }; } componentDidMount() { ReadUHF.changeFlag(1) DeviceEventEmitter.addListener('MsgFromAndroid', this._addProduct); DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown); } componentWillUnmount() { ReadUHF.stopRead() } _addProduct = (start_no) => { // 防止重复扫描 let {productDatas} = this.state; const product_index = productDatas.indexOf(start_no) if (product_index < 0) { productDatas.push(start_no) this.setState({total: productDatas.length, productDatas}) } } _onSave = () => { const type = this.props.navigation.state.params.type if (this.state.distributor == '') { Alert.alert('提示', "请选择经销商!"); return } if (this.state.productDatas.length == 0) { Alert.alert('提示', "请添加产品!"); return } const save_data = { "distributor": this.state.distributor, "notes": this.state.notes, "details": JSON.stringify(this.state.productDatas), "save_type": 'UHF', } if (type == 'Deliver') { this.props.dispatch({ type: 'home/deliverSave', payload: save_data, callback: (data) => { if (data.msg) { Alert.alert('提示', data.msg); } this.props.navigation.goBack(); }, }); } else { this.props.dispatch({ type: 'home/returnSave', payload: save_data, callback: (data) => { if (data.msg) { Alert.alert('提示', data.msg); } this.props.navigation.goBack(); }, }); } } _start = () => { let {isStart} = this.state; ReadUHF.doRead() this.setState({isStart: !isStart}) } onKeyDown = () => { let {isStart} = this.state; this.setState({isStart: !isStart}) } render() { let {isStart} = this.state; const start_text = isStart ? '开始识别' : '停止识别' return ( this.props.navigation.navigate('SearchDistributor', { callback: (data) => this.setState({ distributor_name: data.name, distributor: data.id }) } )}>经销商 { this.setState({ notes: value, }); }} >备注 {this.state.productDatas.map((item, index) => ( 鞋子 数量:1 编号:{item} ))} 总数量:{this.state.total}