/**
 * Created by zhouhuan on 2017/11/2.
 */
import React from 'react';
import { createForm } from 'rc-form';
import { View, ScrollView } from 'react-native';
import { Button, List, InputItem } from 'antd-mobile';
import { connect } from 'react-redux';
import { createAction } from '../../../utils';

@connect(({ peopleInfo }) => ({ peopleInfo }))
class PeopleDetailInfo extends React.Component {
  componentDidMount() {
    const { id } = this.props.navigation.state.params;
    this.props.dispatch(createAction('peopleInfo/getPeopleDetail')(id));
  }
  onEdit =() => {
    this.props.dispatch(createAction('peopleInfo/setStatus')(true));
  };
  onSubmit = () => {
    this.props.form.validateFields({ force: true }, (error, value) => {
      if (!error) {
        this.props.dispatch(createAction('peopleInfo/updateDSRDetail')({ id: this.props.peopleInfo.peopleID, singularData: value }));
      } else {
        console.log('Validation failed');
      }
    });
  };
  onEditBack = () => {
    this.props.dispatch(createAction('peopleInfo/onEBack')('clear'));
  };
  render() {
    const { detailData, editable, disabled } = this.props.peopleInfo;
    console.log(this.props.peopleInfo);
    const { getFieldProps } = this.props.form;
    return (
      <ScrollView>
        <List>
          <InputItem
            {...getFieldProps('xingMing', {
              initialValue: detailData.xingMing,
              rules: [
                { required: true, message: '不允许为空' },
              ],
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            姓名
          </InputItem>
          <InputItem
            {...getFieldProps('identityCard', {
              initialValue: detailData.identityCard,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            证件号码
          </InputItem>
          <InputItem
            {...getFieldProps('birthday', {
              initialValue: detailData.birthday,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            出生日期
          </InputItem>
          <InputItem
            {...getFieldProps('guoJi', {
              initialValue: detailData.guoJi,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            国籍
          </InputItem>
          <InputItem
            {...getFieldProps('minZu', {
              initialValue: detailData.minZu,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            民族
          </InputItem>
          <InputItem
            {...getFieldProps('lianXiDianHua', {
              initialValue: detailData.lianXiDianHua,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            联系电话
          </InputItem>
          <InputItem
            {...getFieldProps('lianXiDiZhi', {
              initialValue: detailData.lianXiDiZhi,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            联系地址
          </InputItem>
          <InputItem
            {...getFieldProps('yuHuZhuGuanXi', {
              initialValue: detailData.yuHuZhuGuanXi,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            与户主关系
          </InputItem>
          <InputItem
            {...getFieldProps('zhengZhiMianMao', {
              initialValue: detailData.zhengZhiMianMao,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            政治面貌
          </InputItem>
          <InputItem
            {...getFieldProps('hunYinZhuangKuang', {
              initialValue: detailData.hunYinZhuangKuang,
            })}
            clear
            placeholder=""
            editable={editable}
            ref={(el) => { this.customFocusInst = el; }}
          >
            婚姻状况
          </InputItem>
          <List.Item>
            <View style={{ flexDirection: 'row' }}>
              <Button style={{ marginRight: 8 }} type="primary" onClick={this.onEdit}>编辑</Button>
              <Button style={{ marginRight: 8 }} onClick={this.onSubmit} disabled={disabled}>保存</Button>
              <Button onClick={this.onEditBack}>返回</Button>
            </View>
          </List.Item>
        </List>
      </ScrollView>
    );
  }
}
export default createForm()(PeopleDetailInfo);
