import React, {Component} from 'react'; import {View, Text, StyleSheet, Dimensions, Alert} from 'react-native'; import {connect} from 'react-redux' import {createAction} from '../../utils/' import {Button, List, InputItem, Toast, WhiteSpace, Picker, Provider} from "@ant-design/react-native"; @connect(home => ({...home})) class DeliverAdd extends Component { constructor(props) { super(props); let data = {} if (this.props.navigation.state.params.data) { data = this.props.navigation.state.params.data } this.state = { no: data.no, count: data.count, name: data.name, cross_code: data.cross_code, product_id: data.product_id, }; } componentDidMount() { //this._fetchSelect(); if(this.state.no) { this._searchNo(this.state.no) } } componentWillUnmount() { this.props.dispatch({ type: 'home/clear' }); } onSave = () => { if (!this.state.no) { Toast.info('请输入防窜货号', 1) return } if (!this.state.product_id) { Toast.info('未查询到防窜货号', 1) return } if (this.state.count == '' || this.state.count == null) { Toast.info('请填写数量', 1) return } const {goBack, state} = this.props.navigation; //在页面返回,卸载时,将上个页面的方法取到,并回传参数,这样回传的参数会重走render方法 state.params.callback(this.state); goBack(); //this.props.dispatch(createAction('part_new/editParts')(this.state)) } _searchNo = (value) => { if (value) { this.props.dispatch(createAction('home/fetchProductData')({cross_code: value})) this.setState({no: value}) } else { Toast.info("请输入防窜货号!", 1) } } render() { const {searchProductData} = this.props.home; this.state.name = searchProductData.name this.state.cross_code = searchProductData.cross_code this.state.product_id = searchProductData.id return ( 查询} value={this.state.no} onChange={value => this._searchNo(value)} >防窜货号 { this.setState({ count: value, }); }} >数量 产品名称 ) } } const styles = StyleSheet.create({ text: { color: '#333' }, redText: { color: 'red', fontSize: 16, }, }) export default DeliverAdd