|
|
@@ -1,43 +1,16 @@
|
|
|
-import React, { useEffect } from 'react';
|
|
|
-import { Modal, Form, Input, Select, InputNumber, DatePicker, Checkbox } from 'antd';
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
+import { Modal, Form, Input, Select, InputNumber, DatePicker, Checkbox, Upload, message } from 'antd';
|
|
|
+import { UploadOutlined } from '@ant-design/icons';
|
|
|
import { Member } from '../../types/member';
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
-interface MemberModalProps {
|
|
|
- visible: boolean;
|
|
|
- onOk: (member: Member) => void;
|
|
|
- onCancel: () => void;
|
|
|
- initialValues: Member | null;
|
|
|
-}
|
|
|
-
|
|
|
-const { Option } = Select;
|
|
|
-
|
|
|
-// 预设的服侍岗位选项
|
|
|
-const defaultServicePositions = [
|
|
|
- '主日学老师',
|
|
|
- '敬拜团成员',
|
|
|
- '招待同工',
|
|
|
- '音控同工',
|
|
|
- '祷告团队',
|
|
|
- '探访同工',
|
|
|
- '小组长',
|
|
|
-];
|
|
|
+// ... 其他代码保持不变
|
|
|
|
|
|
const MemberModal: React.FC<MemberModalProps> = ({ visible, onOk, onCancel, initialValues }) => {
|
|
|
const [form] = Form.useForm();
|
|
|
+ const [facePhoto, setFacePhoto] = useState<string | undefined>(initialValues?.facePhoto);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (visible && initialValues) {
|
|
|
- const values = {
|
|
|
- ...initialValues,
|
|
|
- birthDate: initialValues.birthDate ? dayjs(initialValues.birthDate) : null,
|
|
|
- baptismDate: initialValues.baptismDate ? dayjs(initialValues.baptismDate) : null,
|
|
|
- };
|
|
|
- form.setFieldsValue(values);
|
|
|
- } else {
|
|
|
- form.resetFields();
|
|
|
- }
|
|
|
- }, [visible, initialValues, form]);
|
|
|
+ // ... 其他代码保持不变
|
|
|
|
|
|
const handleOk = () => {
|
|
|
form.validateFields().then(values => {
|
|
|
@@ -45,12 +18,26 @@ const MemberModal: React.FC<MemberModalProps> = ({ visible, onOk, onCancel, init
|
|
|
...values,
|
|
|
birthDate: values.birthDate ? values.birthDate.format('YYYY-MM-DD') : null,
|
|
|
baptismDate: values.baptismDate ? values.baptismDate.format('YYYY-MM-DD') : null,
|
|
|
+ facePhoto: facePhoto,
|
|
|
};
|
|
|
onOk(member as Member);
|
|
|
form.resetFields();
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const handleFacePhotoUpload = (info: any) => {
|
|
|
+ if (info.file.status === 'done') {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = (e) => {
|
|
|
+ setFacePhoto(e.target?.result as string);
|
|
|
+ message.success(`${info.file.name} 文件上传成功`);
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(info.file.originFileObj);
|
|
|
+ } else if (info.file.status === 'error') {
|
|
|
+ message.error(`${info.file.name} 文件上传失败`);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<Modal
|
|
|
title={initialValues ? "编辑会友" : "添加会友"}
|
|
|
@@ -60,58 +47,28 @@ const MemberModal: React.FC<MemberModalProps> = ({ visible, onOk, onCancel, init
|
|
|
width={800}
|
|
|
>
|
|
|
<Form form={form} layout="vertical">
|
|
|
- <Form.Item name="id" hidden><Input /></Form.Item>
|
|
|
- <Form.Item name="name" label="姓名" rules={[{ required: true, message: '请输入姓名' }]}>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="idNumber" label="身份证号" rules={[{ required: true, message: '请输入身份证号' }]}>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="phone" label="手机号" rules={[{ required: true, message: '请输入手机号' }]}>
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="gender" label="性别" rules={[{ required: true, message: '请选择性别' }]}>
|
|
|
- <Select>
|
|
|
- <Option value="男">男</Option>
|
|
|
- <Option value="女">女</Option>
|
|
|
- <Option value="其他">其他</Option>
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="age" label="年龄" rules={[{ required: true, message: '请输入年龄' }]}>
|
|
|
- <InputNumber min={0} max={150} />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="birthDate" label="出生日期" rules={[{ required: true, message: '请选择出生日期' }]}>
|
|
|
- <DatePicker />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="maritalStatus" label="婚姻状态" rules={[{ required: true, message: '请选择婚姻状态' }]}>
|
|
|
- <Select>
|
|
|
- <Option value="未婚">未婚</Option>
|
|
|
- <Option value="已婚">已婚</Option>
|
|
|
- <Option value="离异">离异</Option>
|
|
|
- <Option value="丧偶">丧偶</Option>
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="address" label="联系地址" rules={[{ required: true, message: '请输入联系地址' }]}>
|
|
|
- <Input.TextArea />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="workplace" label="工作单位">
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="groupLeader" label="小组组长">
|
|
|
- <Input />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="isBaptized" label="是否受洗" valuePropName="checked">
|
|
|
- <Checkbox />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="baptismDate" label="受洗日期">
|
|
|
- <DatePicker />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item name="servicePositions" label="服侍岗位">
|
|
|
- <Select mode="tags" style={{ width: '100%' }} placeholder="请选择或输入服侍岗位">
|
|
|
- {defaultServicePositions.map(position => (
|
|
|
- <Option key={position} value={position}>{position}</Option>
|
|
|
- ))}
|
|
|
- </Select>
|
|
|
+ {/* ... 其他表单项保持不变 */}
|
|
|
+
|
|
|
+ <Form.Item name="facePhoto" label="人脸照片">
|
|
|
+ <Upload
|
|
|
+ name="facePhoto"
|
|
|
+ listType="picture"
|
|
|
+ maxCount={1}
|
|
|
+ beforeUpload={(file) => {
|
|
|
+ const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
|
|
|
+ if (!isJpgOrPng) {
|
|
|
+ message.error('只能上传 JPG/PNG 文件!');
|
|
|
+ }
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
+ if (!isLt2M) {
|
|
|
+ message.error('图片必须小于 2MB!');
|
|
|
+ }
|
|
|
+ return isJpgOrPng && isLt2M;
|
|
|
+ }}
|
|
|
+ onChange={handleFacePhotoUpload}
|
|
|
+ >
|
|
|
+ <Button icon={<UploadOutlined />}>上传人脸照片</Button>
|
|
|
+ </Upload>
|
|
|
</Form.Item>
|
|
|
</Form>
|
|
|
</Modal>
|