DSRInfoDetailScreen.js 4.8 KB
Newer Older
吴强's avatar
吴强 committed
1 2 3 4 5 6
/**
 * Created by zhouhuan on 2017/10/30.
 */
import React from 'react';
import { createForm } from 'rc-form';
import { View, ScrollView } from 'react-native';
7
import { List, InputItem, Toast, WhiteSpace, WingBlank } from 'antd-mobile';
吴强's avatar
吴强 committed
8
import Icon from 'react-native-vector-icons/FontAwesome';
吴强's avatar
吴强 committed
9 10 11 12 13 14 15 16 17 18
import { connect } from 'react-redux';
import { createAction } from '../../../utils';

@connect(({ DSRInfoDetail }) => ({ DSRInfoDetail }))
class DSRInfoDetailScreen extends React.Component {
  componentDidMount() {
    const { id } = this.props.navigation.state.params;
    this.props.dispatch(createAction('DSRInfoDetail/getDSRInfoDetail')(id));
  }
  onEdit =() => {
吴强's avatar
吴强 committed
19
    // this.props.dispatch(createAction('DSRInfoDetail/setEnable')(true));
20
    this.props.navigation.navigate('CameraPhoto', { pID: this.props.navigation.state.params });
吴强's avatar
吴强 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  };
  onSubmit = () => {
    this.props.form.validateFields({ force: true }, (error, value) => {
      if (!error) {
        this.props.dispatch(createAction('DSRInfoDetail/updateDSRInfoDetail')({ id: this.props.DSRInfoDetail.DSRID, singularData: value }));
      } else {
        Toast.show('Validation failed');
      }
    });
  };
  validateNoNull = (rule, value, callback) => {
    if (value) {
      callback();
    } else {
      callback(new Error('At least four charactors for account'));
    }
  };
  render() {
    const { singularData, metas, enableEdit } = this.props.DSRInfoDetail;
    const { getFieldProps } = this.props.form;
吴强's avatar
吴强 committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    if (this.props.DSRInfoDetail.enableEdit === true) {
      return (
        <ScrollView>
          <WhiteSpace />
          <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
            <Icon.Button
              name="id-card"
              backgroundColor="#08BBF9"
              onPress={() => {
                this.props.dispatch({ type: 'DSRInfoDetail/DuKa' });
              }}
            >
              读卡
            </Icon.Button>
          </View>
          <WhiteSpace />
          <List>
            {
              metas.map((m) => {
                if (m.required === true) {
                  return (
                    <InputItem
                      {...getFieldProps(m.key, {
                        initialValue: singularData[m.key],
                        rules: [
                          { required: true, message: '不允许为空' },
                          { validator: this.validateNoNull },
                        ],
                      })}
                      clear
                      placeholder="请输入"
                      editable={enableEdit}
                      ref={(el) => {
                        this.customFocusInst = el;
                      }}
                    >
                      姓名
                    </InputItem>
                  );
                } else {
                  return (
                    <InputItem
                      {...getFieldProps(m.key, {
                        initialValue: singularData[m.key],
                      })}
                      clear
                      placeholder="请输入"
                      editable={enableEdit}
                      ref={(el) => {
                        this.customFocusInst = el;
                      }}
                    >
                      {m.label}
                    </InputItem>
                  );
                }
              })}
            {[1].map(() => {
              return (
                <List.Item>
                  <View style={{ flexDirection: 'row', justifyContent: 'center' }}>
                    <Icon.Button
                      name="save"
                      backgroundColor="#08BBF9"
                      onPress={this.onSubmit}
                    >
                      保存
                    </Icon.Button>
                  </View>
                </List.Item>
              );
            })
            }
          </List>
        </ScrollView>
      );
    } else {
      return (
        <ScrollView>
          <WhiteSpace />
          <WhiteSpace />
122 123
          <WingBlank>
            <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
124
              <Icon.Button
吴强's avatar
吴强 committed
125 126 127 128
                name="edit"
                backgroundColor="#08BBF9"
                onPress={this.onEdit}
              >
129 130
                资料上传
              </Icon.Button>
131 132 133 134
            </View>
            <WhiteSpace />
            <List>
              {
吴强's avatar
吴强 committed
135 136 137 138 139
              metas.map((m) => {
                  return (
                    <List.Item
                      key={m.key}
                      extra={singularData[m.key]}
140
                      wrap
吴强's avatar
吴强 committed
141 142 143 144
                    >
                      {m.label}
                    </List.Item>
                  );
145 146 147 148
                })
              }
            </List>
          </WingBlank>
吴强's avatar
吴强 committed
149 150 151
        </ScrollView>
      );
    }
吴强's avatar
吴强 committed
152 153 154 155
  }
}

export default createForm()(DSRInfoDetailScreen);