modal.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React, { Component } from 'react';
  2. import { Form, Select, Switch, Radio, Input, Modal, Icon } from 'antd';
  3. import { Codes, domains } from '../../utils/config';
  4. @Form.create()
  5. export default class CMSUserModalForm extends Component {
  6. handleModalOk = () => {
  7. const { form, onOk, modalType, item } = this.props;
  8. const { validateFields, getFieldsValue } = form;
  9. validateFields((errors) => {
  10. if (errors) return;
  11. const data = { ...getFieldsValue() };
  12. data.status ? data.status = Codes.CODE_NORMAL : data.status = Codes.CODE_DELETE;
  13. if (modalType === 'update') {
  14. data.id = item.id;
  15. }
  16. onOk(data);
  17. });
  18. }
  19. render() {
  20. const { item, merchantList, onOk, form, modalType, ...modalProps } = this.props;
  21. const { getFieldDecorator } = form;
  22. const modalOpts = { ...modalProps, onOk: this.handleModalOk };
  23. const formItemLayout = {
  24. labelCol: { span: 6 },
  25. wrapperCol: { span: 15 },
  26. };
  27. return (
  28. <Modal {...modalOpts}>
  29. <Form layout="horizontal">
  30. <Form.Item label="选择厂商" hasFeedback {...formItemLayout}>
  31. {getFieldDecorator('merchantId', {
  32. rules: [{ required: true, type: 'string', message: '该项为必选项!' }],
  33. initialValue: item.merchantId,
  34. })(
  35. <Select
  36. showSearch
  37. allowClear
  38. placeholder="请选择"
  39. optionFilterProp="children"
  40. filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
  41. >
  42. {merchantList.map(selItem => <Select.Option value={selItem.id} key={selItem.id}>{`${selItem.code}/${selItem.name}`}</Select.Option>)}
  43. </Select>
  44. )}
  45. </Form.Item>
  46. <Form.Item label="用户名称:" hasFeedback {...formItemLayout}>
  47. {getFieldDecorator('name', {
  48. rules: [{ required: true, type: 'string', message: '用户名为必填项!' }],
  49. initialValue: item.name,
  50. })(<Input placeholder="请输入" />)}
  51. </Form.Item>
  52. {modalType === 'create' ? (
  53. <Form.Item label="用户密码:" hasFeedback {...formItemLayout}>
  54. {getFieldDecorator('password', {
  55. rules: [{ required: true, type: 'string', message: '密码为必填项!' }],
  56. initialValue: item.password,
  57. })(<Input placeholder="请输入" />)}
  58. </Form.Item>
  59. ) : (
  60. <Form.Item label="用户密码:" hasFeedback {...formItemLayout}>
  61. {getFieldDecorator('password', {
  62. initialValue: item.password,
  63. })(<Input placeholder="修改密码时填写" />)}
  64. </Form.Item>
  65. )}
  66. <Form.Item label="用户昵称:" hasFeedback {...formItemLayout}>
  67. {getFieldDecorator('nickName', {
  68. initialValue: item.nickName,
  69. })(<Input />)}
  70. </Form.Item>
  71. <Form.Item label="用户性别:" {...formItemLayout}>
  72. {getFieldDecorator('gender', {
  73. initialValue: item.gender || 'MALE',
  74. })(
  75. <Radio.Group>
  76. <Radio value="MALE" key="MALE">男</Radio>
  77. <Radio value="FEMALE" key="FEMALE">女</Radio>
  78. </Radio.Group>
  79. )}
  80. </Form.Item>
  81. <Form.Item label="出生日期:" hasFeedback {...formItemLayout}>
  82. {getFieldDecorator('birthday', {
  83. initialValue: item.birthday,
  84. })(<Input />)}
  85. </Form.Item>
  86. <Form.Item label="电话:" hasFeedback {...formItemLayout}>
  87. {getFieldDecorator('mobile', {
  88. initialValue: item.mobile,
  89. })(<Input />)}
  90. </Form.Item>
  91. <Form.Item label="邮箱:" hasFeedback {...formItemLayout}>
  92. {getFieldDecorator('mail', {
  93. initialValue: item.mail,
  94. })(<Input />)}
  95. </Form.Item>
  96. <Form.Item label="QQ:" hasFeedback {...formItemLayout}>
  97. {getFieldDecorator('qq', {
  98. initialValue: item.qq,
  99. })(<Input />)}
  100. </Form.Item>
  101. <Form.Item label="微信:" hasFeedback {...formItemLayout}>
  102. {getFieldDecorator('weChat', {
  103. initialValue: item.weChat,
  104. })(<Input />)}
  105. </Form.Item>
  106. <Form.Item label="账号状态:" {...formItemLayout}>
  107. {getFieldDecorator('status', {
  108. valuePropsName: 'checked',
  109. })(<Switch defaultChecked={item.status === Codes.CODE_NORMAL} checkedChildren="使用中" unCheckedChildren="禁用中" />)}
  110. </Form.Item>
  111. </Form>
  112. </Modal>
  113. );
  114. }
  115. }