DeliverAdd.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React, {Component} from 'react';
  2. import {View, Text, StyleSheet, Dimensions, Alert} from 'react-native';
  3. import {connect} from 'react-redux'
  4. import {createAction} from '../../utils/'
  5. import {Button, List, InputItem, Toast, WhiteSpace, Picker, Provider} from "@ant-design/react-native";
  6. @connect(home => ({...home}))
  7. class DeliverAdd extends Component {
  8. constructor(props) {
  9. super(props);
  10. let data = {}
  11. if (this.props.navigation.state.params.data) {
  12. data = this.props.navigation.state.params.data
  13. }
  14. this.state = {
  15. no: data.no,
  16. count: data.count,
  17. name: data.name,
  18. cross_code: data.cross_code,
  19. product_id: data.product_id,
  20. };
  21. }
  22. componentDidMount() {
  23. //this._fetchSelect();
  24. if(this.state.no) {
  25. this._searchNo(this.state.no)
  26. }
  27. }
  28. componentWillUnmount() {
  29. this.props.dispatch({
  30. type: 'home/clear'
  31. });
  32. }
  33. onSave = () => {
  34. if (!this.state.no) {
  35. Toast.info('请输入防窜货号', 1)
  36. return
  37. }
  38. if (!this.state.product_id) {
  39. Toast.info('未查询到防窜货号', 1)
  40. return
  41. }
  42. if (this.state.count == '' || this.state.count == null) {
  43. Toast.info('请填写数量', 1)
  44. return
  45. }
  46. const {goBack, state} = this.props.navigation;
  47. //在页面返回,卸载时,将上个页面的方法取到,并回传参数,这样回传的参数会重走render方法
  48. state.params.callback(this.state);
  49. goBack();
  50. //this.props.dispatch(createAction('part_new/editParts')(this.state))
  51. }
  52. _searchNo = (value) => {
  53. if (value) {
  54. this.props.dispatch(createAction('home/fetchProductData')({cross_code: value}))
  55. this.setState({no: value})
  56. } else {
  57. Toast.info("请输入防窜货号!", 1)
  58. }
  59. }
  60. render() {
  61. const {searchProductData} = this.props.home;
  62. this.state.name = searchProductData.name
  63. this.state.cross_code = searchProductData.cross_code
  64. this.state.product_id = searchProductData.id
  65. return (
  66. <Provider>
  67. <WhiteSpace/>
  68. <List>
  69. <InputItem
  70. clear
  71. // extra={<Button onPress={this._searchNo}
  72. // type="primary"
  73. // size="small"
  74. // >查询</Button>}
  75. value={this.state.no}
  76. onChange={value => this._searchNo(value)}
  77. ><Text style={styles.redText}>防窜货号</Text></InputItem>
  78. <InputItem
  79. clear
  80. type={"number"}
  81. value={this.state.count}
  82. onChange={value => {
  83. this.setState({
  84. count: value,
  85. });
  86. }}
  87. ><Text style={styles.redText}>数量</Text></InputItem>
  88. <List.Item extra={this.state.name} style={styles.text}>产品名称</List.Item>
  89. <List.Item>
  90. <Button
  91. type="primary"
  92. loading={false}
  93. onPress={this.onSave}
  94. >保存</Button>
  95. </List.Item>
  96. </List>
  97. </Provider>
  98. )
  99. }
  100. }
  101. const styles = StyleSheet.create({
  102. text: {
  103. color: '#333'
  104. },
  105. redText: {
  106. color: 'red',
  107. fontSize: 16,
  108. },
  109. })
  110. export default DeliverAdd