123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- import React, {Component} from 'react';
- import {
- View,
- Text, StyleSheet, ScrollView, StatusBar, DeviceEventEmitter, KeyboardAvoidingView, Platform,
- } from 'react-native';
- import {connect} from 'react-redux';
- import {
- Provider,
- Button,
- Toast,
- List,
- Picker,
- InputItem,
- } from '@ant-design/react-native';
- import RadioModal from '../../components/RadioModal';
- import ComponentsStyles from '../../components/ComponentsStyles';
- import CheckValid from '../../components/CheckValid';
- @connect(customer => ({...customer}))
- class ReportCustomerAdd extends Component {
- // 报备客户
- constructor(props) {
- super(props);
- this.state = {
- name: '',
- tel: '',
- gender: 2,
- village: '',
- address: '',
- source: '',
- project: [],
- notes: '',
- project_text: '请选择',
- CUSTOMER_SOURCE: [],
- };
- }
- componentDidMount() {
- this._fetchData();
- }
- _fetchData = () => {
- this.props.dispatch({
- type: 'customer/fetchReportDict',
- callback: (data) => {
- let CUSTOMER_SOURCE = [];
- data.source.map((item, index) => {
- CUSTOMER_SOURCE.push({
- value: item.id, label: item.name,
- });
- });
- this.setState({CUSTOMER_SOURCE});
- },
- });
- };
- onSave = () => {
- if (!this.state.name) {
- Toast.info('请填写姓名', 1);
- return;
- }
- if (!this.state.tel) {
- Toast.info('请填写手机号', 1);
- return;
- }
- if (!CheckValid(this.state.tel, 'tel')) {
- Toast.info('请填写正确的手机号', 1);
- return;
- }
- if (!this.state.village) {
- Toast.info('请填写小区', 1);
- return;
- }
- if (!this.state.address) {
- Toast.info('请填写地址', 1);
- return;
- }
- if (!this.state.source.length) {
- Toast.info('请选择来源', 1);
- return;
- }
- if (!this.state.project.length) {
- Toast.info('请选择项目', 1);
- return;
- }
- this.props.dispatch({
- type: 'customer/saveReportCustomer',
- payload: this.state,
- callback: () => {
- DeviceEventEmitter.emit('backRefesh');
- this.props.navigation.goBack();
- },
- });
- };
- onProjectPress = () => {
- this.props.navigation.navigate('SearchProject', {
- callback: this.setProject,
- checked_ids:this.state.project,
- checked_names:this.state.project_text,
- });
- };
- setProject = (ids, name) => {
- this.setState({project_text: name, project: ids});
- };
- render() {
- const {loading} = this.props.customer;
- const isIOS = Platform.OS === 'ios' ? true : false;
- return (
- <KeyboardAvoidingView behavior={'padding'} enabled={isIOS} style={{backgroundColor: '#fff', flex: 1}}>
- <StatusBar backgroundColor={'#fff'} barStyle='dark-content'/>
- <Provider>
- <ScrollView keyboardShouldPersistTaps={'handled'}>
- <List style={styles.listStyle}>
- <InputItem
- clear
- value={this.state.name}
- onChange={value => {
- this.setState({
- name: value,
- });
- }}
- placeholder="请输入客户姓名"
- >
- <Text style={ComponentsStyles.requiredText}>姓名</Text>
- </InputItem>
- <View style={ComponentsStyles.genderStyle}>
- <Text style={[ComponentsStyles.requiredText, {textAlignVertical: 'center'}]}>性别</Text>
- <RadioModal
- selectedValue={this.state.gender.toString()}
- onValueChange={id => this.setState({type: id})}
- style={ComponentsStyles.radioStyle}
- innerStyle={{
- width: 50,
- }}
- >
- <Text value="1">女</Text>
- <Text value="2">男</Text>
- </RadioModal>
- </View>
- <InputItem
- clear
- type={'number'}
- value={this.state.tel}
- onChange={value => {
- this.setState({
- tel: value,
- });
- }}
- placeholder="请输入电话"
- >
- <Text style={ComponentsStyles.requiredText}>电话</Text>
- </InputItem>
- <InputItem
- clear
- value={this.state.village}
- onChange={value => {
- this.setState({
- village: value,
- });
- }}
- placeholder="请输入小区"
- >
- <Text style={ComponentsStyles.requiredText}>小区</Text>
- </InputItem>
- <InputItem
- clear
- value={this.state.address}
- onChange={value => {
- this.setState({
- address: value,
- });
- }}
- placeholder="请输入地址"
- >
- <Text style={ComponentsStyles.requiredText}>地址</Text>
- </InputItem>
- <Picker
- data={this.state.CUSTOMER_SOURCE}
- cols={1}
- value={this.state.source}
- onChange={text => {
- this.setState({
- source: text,
- });
- }}
- >
- <List.Item arrow="horizontal">
- <Text style={ComponentsStyles.requiredText}>来源</Text>
- </List.Item>
- </Picker>
- <List.Item
- arrow="horizontal"
- extra={
- <Text
- style={{fontSize: 17, width: 200, textAlign: 'right'}}
- onPress={() => this.onProjectPress()}>
- {this.state.project_text}
- </Text>}
- >
- <Text style={ComponentsStyles.requiredText}>项目</Text>
- </List.Item>
- <InputItem
- clear
- value={this.state.notes}
- onChange={value => {
- this.setState({
- notes: value,
- });
- }}
- placeholder="请输入备注"
- >
- <Text style={ComponentsStyles.font15}>备注</Text>
- </InputItem>
- </List>
- </ScrollView>
- <Button
- onPress={this.onSave}
- type="primary"
- loading={loading}
- disabled={loading}
- style={ComponentsStyles.button}>保存</Button>
- </Provider>
- </KeyboardAvoidingView>
- );
- }
- }
- const styles = StyleSheet.create({
- listStyle: {
- marginTop: 5,
- },
- dateInput: {
- borderWidth: 0,
- alignItems: 'flex-end',
- },
- });
- export default ReportCustomerAdd;
|