UHFDeliver.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. View,
  5. Text,
  6. ScrollView,
  7. Alert,
  8. DeviceEventEmitter
  9. } from 'react-native';
  10. import {WhiteSpace, List, InputItem, Provider, Toast} from '@ant-design/react-native';
  11. import {connect} from 'react-redux'
  12. import {Button} from "../../components";
  13. import ReadUHF from "../../utils/ReadUHF";
  14. @connect(home => ({...home}))
  15. class UHFDeliver extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. notes: '',
  20. distributor: '',
  21. distributor_name: '',
  22. type: this.props.navigation.state.params.type,
  23. no: '',
  24. total: 0,
  25. isStart: true,
  26. productDatas: [],
  27. };
  28. }
  29. componentDidMount() {
  30. ReadUHF.changeFlag(1)
  31. DeviceEventEmitter.addListener('MsgFromAndroid', this._addProduct);
  32. DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
  33. }
  34. componentWillUnmount() {
  35. ReadUHF.stopRead()
  36. }
  37. _addProduct = (start_no) => {
  38. // 防止重复扫描
  39. let {productDatas} = this.state;
  40. const product_index = productDatas.indexOf(start_no)
  41. if (product_index < 0) {
  42. productDatas.push(start_no)
  43. this.setState({total: productDatas.length, productDatas})
  44. }
  45. }
  46. _onSave = () => {
  47. const type = this.props.navigation.state.params.type
  48. if (this.state.distributor == '') {
  49. Alert.alert('提示', "请选择经销商!");
  50. return
  51. }
  52. if (this.state.productDatas.length == 0) {
  53. Alert.alert('提示', "请添加产品!");
  54. return
  55. }
  56. const save_data = {
  57. "distributor": this.state.distributor,
  58. "notes": this.state.notes,
  59. "details": JSON.stringify(this.state.productDatas),
  60. "save_type": 'UHF',
  61. }
  62. if (type == 'Deliver') {
  63. this.props.dispatch({
  64. type: 'home/deliverSave',
  65. payload: save_data,
  66. callback: (data) => {
  67. if (data.msg) {
  68. Alert.alert('提示', data.msg);
  69. }
  70. this.props.navigation.goBack();
  71. },
  72. });
  73. } else {
  74. this.props.dispatch({
  75. type: 'home/returnSave',
  76. payload: save_data,
  77. callback: (data) => {
  78. if (data.msg) {
  79. Alert.alert('提示', data.msg);
  80. }
  81. this.props.navigation.goBack();
  82. },
  83. });
  84. }
  85. }
  86. _start = () => {
  87. let {isStart} = this.state;
  88. ReadUHF.doRead()
  89. this.setState({isStart: !isStart})
  90. }
  91. onKeyDown = () => {
  92. let {isStart} = this.state;
  93. this.setState({isStart: !isStart})
  94. }
  95. render() {
  96. let {isStart} = this.state;
  97. const start_text = isStart ? '开始识别' : '停止识别'
  98. return (
  99. <View style={{flex: 1}}>
  100. <Provider>
  101. <ScrollView style={{flex: 1}}>
  102. <WhiteSpace/>
  103. <List>
  104. <List.Item extra={this.state.distributor_name} arrow="horizontal"
  105. multipleLine={true} wrap={true}
  106. onPress={() => this.props.navigation.navigate('SearchDistributor',
  107. {
  108. callback: (data) => this.setState({
  109. distributor_name: data.name,
  110. distributor: data.id
  111. })
  112. }
  113. )}><Text style={styles.redText}>经销商</Text></List.Item>
  114. <InputItem
  115. clear
  116. placeholder="请输入"
  117. value={this.state.notes}
  118. onChange={value => {
  119. this.setState({
  120. notes: value,
  121. });
  122. }}
  123. ><Text style={{fontSize: 17, color: '#333'}}>备注</Text>
  124. </InputItem>
  125. </List>
  126. {this.state.productDatas.map((item, index) => (
  127. <View key={index} style={styles.cellContainer}>
  128. <View style={styles.rowPadding3}>
  129. <View style={styles.left}>
  130. <Text style={styles.blackText}>鞋子</Text>
  131. </View>
  132. <Text style={styles.blackText}>数量:1</Text>
  133. </View>
  134. <View style={styles.rowPadding3}>
  135. <View style={styles.left}>
  136. <Text style={styles.blackText}>编号:{item}</Text>
  137. </View>
  138. </View>
  139. </View>
  140. ))}
  141. </ScrollView>
  142. </Provider>
  143. <View style={{
  144. backgroundColor: '#eee', height: 20, justifyContent: 'flex-end',
  145. flexDirection: 'row', paddingRight: 10
  146. }}>
  147. <Text style={{fontSize: 14, textAlignVertical: 'center'}}>总数量:{this.state.total}</Text></View>
  148. <View style={{flexDirection: 'row', height: 40}}>
  149. <Button onPress={() => this._start()}
  150. textStyle={{color: 'white'}}
  151. style={{
  152. flex: 1,
  153. borderRadius: 0,
  154. borderWidth: 0,
  155. backgroundColor: isStart ? '#0099FF' : 'red',
  156. color: '#fff'
  157. }} title={start_text}/>
  158. <Button onPress={() => Alert.alert(
  159. '提示',
  160. '确定要保存吗?',
  161. [
  162. {text: '确定', onPress: () => this._onSave()},
  163. {text: '取消'},
  164. ]
  165. )} textStyle={{color: 'white'}} style={{
  166. flex: 1,
  167. borderRadius: 0,
  168. borderWidth: 0,
  169. backgroundColor: '#7DBEFF',
  170. color: '#fff'
  171. }} title='保存'/>
  172. </View>
  173. </View>
  174. );
  175. }
  176. }
  177. const styles = StyleSheet.create({
  178. input: {
  179. borderBottomWidth: 1,
  180. borderBottomColor: '#eee',
  181. marginBottom: 15
  182. },
  183. redText: {
  184. color: 'red',
  185. fontSize: 15,
  186. },
  187. cellContainer: {
  188. paddingVertical: 5,
  189. paddingHorizontal: 5,
  190. borderBottomWidth: 1,
  191. borderColor: '#eee',
  192. marginHorizontal: 5,
  193. overflow: 'hidden'
  194. },
  195. rowPadding3: {
  196. flexDirection: 'row',
  197. padding: 3,
  198. },
  199. left: {
  200. flex: 3,
  201. flexDirection: 'row',
  202. },
  203. blackText: {
  204. color: '#333',
  205. fontSize: 14,
  206. },
  207. })
  208. export default UHFDeliver;