import React, { PureComponent } from 'react'; import { Card, Form, Table, Input, Button, Radio, Icon, Switch } from 'antd'; import { connect } from 'dva'; import { routerRedux } from 'dva/router'; import FooterToolbar from '../../../components/FooterToolbar'; import {renderAvatar, renderGender, renderStatus, boolToStatus, statusToBool} from '../../../utils/utils'; import styles from './CmsUserCreate.less'; const genders = [{ title: '男', value: 'MALE', }, { title: '女', value: 'FEMALE', }]; const fieldLabels = { nickName: '用户昵称', gender: '用户性别', birthday: '出生日期', mobile: '电话', mail: '邮箱', qq: 'QQ号码', weChat: '微信号码', password: '用户密码', confirm: '确认密码', status: '账号状态', }; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 6 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 14 }, md: { span: 12 }, }, }; function cmsUserDataFormatter(item) { const { qq, name, mail, weChat, mobile, status, gender, avatar, birthday, nickName, merchantName, } = item; return [{ key: 1, field: '用户头像', text: renderAvatar(avatar, nickName), }, { key: 2, field: '用户名称', text: name, }, { key: 3, field: '用户昵称', text: nickName, }, { key: 4, field: '出生日期', text: birthday, }, { key: 5, field: '用户性别', text: renderGender(gender), }, { key: 6, field: '所属商户', text: merchantName, }, { key: 7, field: '联系电话', text: mobile, }, { key: 8, field: 'QQ号码', text: qq, }, { key: 9, field: '微信', text: weChat, }, { key: 10, field: '邮箱', text: mail, }, { key: 11, field: '账号状态', text: renderStatus(status), }]; } @Form.create() @connect(({ loading, cmsUser }) => ({ cmsUser, submitting: loading.models.cmsUser, })) export default class CmsUserEditPage extends PureComponent { state = { currentItem: {}, passwordEdit: false, }; componentWillMount() { this.setState({ currentItem: this.props.location.state.currentItem, }); } checkPassword = (rule, value, callback) => { if (value && value !== this.props.form.getFieldValue('password')) { callback('两次输入的密码不一致'); } else if (!value) { callback('请再次输入密码进行确认'); } else { callback(); } }; handlePasswordEdit = () => { this.setState({ passwordEdit: true, }); }; handlePasswordSave = () => { this.props.form.validateFieldsAndScroll((error) => { if (!error) { this.setState({ passwordEdit: false, }); } }); }; handlePageSubmit = () => { this.props.form.validateFieldsAndScroll((error, values) => { const { currentItem, passwordEdit } = this.state; const { id } = currentItem; const { status, ...restProps } = values; restProps.status = boolToStatus(status); restProps.id = id; if (!error && !passwordEdit) { this.props.dispatch({ type: 'cmsUser/updateCmsUserItem', payload: restProps, states: this.props.location.state, }); } }); }; handlePageBack = () => { this.props.dispatch(routerRedux.push({ pathname: '/system/cms-user/list', state: this.props.location.state, })); }; render() { const { form, submitting } = this.props; const { currentItem, passwordEdit } = this.state; const { getFieldDecorator } = form; const { qq, mail, gender, weChat, status, birthday, nickName, mobile, } = currentItem; const campusColumns = [{ title: '字段名', key: 1, dataIndex: 'field', width: '15%', }, { title: '字段值', key: 2, dataIndex: 'text', width: '85%', }]; return (