Search.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. View,
  5. Text,
  6. DeviceEventEmitter, TextInput,
  7. } from 'react-native';
  8. import {SearchBar, List,} from '@ant-design/react-native';
  9. import ReadUHF from "../../utils/ReadUHF";
  10. import {connect} from 'react-redux'
  11. import {Button} from "../../components";
  12. @connect(home => ({...home}))
  13. class SearchHome extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. value: '',
  18. no: '',
  19. searchData: {},
  20. searchState: 0,
  21. };
  22. }
  23. componentDidMount() {
  24. ReadUHF.changeFlag(0)
  25. DeviceEventEmitter.addListener('MsgFromAndroid', this._onSearch);
  26. }
  27. componentWillUnmount() {
  28. ReadUHF.stopRead()
  29. }
  30. componentWillUnmount() {
  31. this.props.dispatch({
  32. type: 'home/clear'
  33. });
  34. }
  35. _onSearch = (value) => {
  36. this.props.dispatch({
  37. type: 'home/search',
  38. payload: {
  39. cross_code: value,
  40. },
  41. callback: (data) => {
  42. if (data.searchState === 1) {
  43. this.setState({searchData: data.searchData, searchState: data.searchState, value: value, no: '',})
  44. } else {
  45. this.setState({
  46. searchData: data.searchData,
  47. searchState: data.searchState,
  48. value: value,
  49. no: value,
  50. })
  51. }
  52. }
  53. })
  54. this.setState({no: value,})
  55. }
  56. _cancel = () => {
  57. this.props.dispatch({
  58. type: 'home/clear'
  59. });
  60. this.setState({value: ''});
  61. };
  62. _start = () => {
  63. ReadUHF.doRead()
  64. }
  65. render() {
  66. const {searchData, searchState,} = this.state;
  67. return (
  68. <View style={{flex: 1}}>
  69. {/*搜索*/}
  70. <View style={{borderBottomWidth: 5, borderBottomColor: '#eee'}}>
  71. <TextInput placeholder="请输入防窜货号" style={styles.input}
  72. value={this.state.no}
  73. autoFocus={true}
  74. onChangeText={value => this._onSearch(value)}>
  75. </TextInput>
  76. </View>
  77. <View style={searchState == 2 ? {padding: 10} : styles.hide}>
  78. <Text>未查询到该编码 {this.state.value} </Text>
  79. </View>
  80. <View style={searchState == 1 ? {} : styles.hide}>
  81. <List>
  82. <List.Item extra={this.state.value}>编码</List.Item>
  83. <List.Item extra={searchData.product_name}>产品</List.Item>
  84. <List.Item extra={searchData.distributor_name}>分销商</List.Item>
  85. <List.Item extra={searchData.create_time}>出库时间</List.Item>
  86. <List.Item extra={searchData.create_user_text}>出库人</List.Item>
  87. <List.Item extra={searchData.check_time}>审核时间</List.Item>
  88. <List.Item extra={searchData.check_user_text}>审核人</List.Item>
  89. </List>
  90. </View>
  91. <Button onPress={() => this._start()}
  92. textStyle={{color: 'white'}}
  93. style={{
  94. marginTop: 30,
  95. borderRadius: 0,
  96. borderWidth: 0,
  97. backgroundColor: '#0099FF',
  98. color: '#fff'
  99. }} title="开始识别"/>
  100. </View>
  101. );
  102. }
  103. }
  104. const styles = StyleSheet.create({
  105. hide: {
  106. display: 'none',
  107. },
  108. })
  109. export default SearchHome;