BirdNETM | b0f7153 | 2025-05-26 17:37:33 +0800 | [diff] [blame] | 1 | import { Modal, Form, Input, InputNumber, Select } from 'antd'; |
| 2 | import React from 'react'; |
| 3 | import { useIntl } from 'umi'; |
| 4 | import { RewardItem } from '../data'; |
| 5 | export type FormValueType = { |
| 6 | rewardId?: number; |
| 7 | title?: string; |
| 8 | description?: string; |
| 9 | amount?: number; |
| 10 | status?: string; |
| 11 | remark?: string; |
| 12 | } & Partial<RewardItem>; |
| 13 | |
| 14 | export type UpdateFormProps = { |
| 15 | onCancel: (flag?: boolean, formVals?: FormValueType) => void; |
| 16 | onSubmit: (values: FormValueType) => Promise<void>; |
| 17 | open: boolean; |
| 18 | values: Partial<RewardItem>; |
| 19 | statusOptions: any; |
| 20 | readOnly?: boolean; |
| 21 | }; |
| 22 | |
| 23 | const UpdateForm: React.FC<UpdateFormProps> = (props) => { |
| 24 | const [form] = Form.useForm(); |
| 25 | |
| 26 | const { statusOptions } = props; |
| 27 | |
| 28 | const intl = useIntl(); |
| 29 | |
| 30 | React.useEffect(() => { |
| 31 | form.resetFields(); |
| 32 | form.setFieldsValue({ |
| 33 | rewardId: props.values.rewardId, |
| 34 | title: props.values.title, |
| 35 | description: props.values.description, |
| 36 | amount: props.values.amount, |
| 37 | status: props.values.status, |
| 38 | remark: props.values.remark, |
| 39 | }); |
| 40 | }, [form, props]); |
| 41 | |
| 42 | const handleOk = () => { |
| 43 | form.submit(); |
| 44 | }; |
| 45 | const handleCancel = () => { |
| 46 | props.onCancel(); |
| 47 | form.resetFields(); |
| 48 | }; |
| 49 | const handleFinish = async (values: FormValueType) => { |
| 50 | props.onSubmit(values); |
| 51 | }; |
| 52 | |
| 53 | return ( |
| 54 | <Modal |
| 55 | width={640} |
| 56 | title={props.readOnly ? '查看悬赏' : (props.values.rewardId ? '编辑悬赏' : '新增悬赏')} |
| 57 | open={props.open} |
| 58 | onOk={handleOk} |
| 59 | footer={props.readOnly ? null : undefined} |
| 60 | onCancel={handleCancel} |
| 61 | > |
| 62 | <Form |
| 63 | form={form} |
| 64 | onFinish={handleFinish} |
| 65 | initialValues={props.values} |
| 66 | labelCol={{ span: 6 }} |
| 67 | wrapperCol={{ span: 18 }} |
| 68 | > |
| 69 | <Form.Item name="rewardId" hidden={true}> |
| 70 | <Input /> |
| 71 | </Form.Item> |
| 72 | <Form.Item |
| 73 | name="title" |
| 74 | label="悬赏标题" |
| 75 | rules={[{ required: true, message: '请输入悬赏标题!' }]} |
| 76 | > |
| 77 | <Input placeholder="请输入悬赏标题" disabled={props.readOnly} /> |
| 78 | </Form.Item> |
| 79 | <Form.Item |
| 80 | name="description" |
| 81 | label="悬赏描述" |
| 82 | rules={[{ required: true, message: '请输入悬赏描述!' }]} |
| 83 | > |
| 84 | <Input.TextArea rows={4} placeholder="请输入悬赏描述" disabled={props.readOnly} /> |
| 85 | </Form.Item> |
| 86 | <Form.Item |
| 87 | name="amount" |
BirdNETM | 11aacb9 | 2025-06-07 23:17:03 +0800 | [diff] [blame] | 88 | label="悬赏积分" |
| 89 | rules={[{ required: true, message: '请输入悬赏积分!' }]} |
BirdNETM | b0f7153 | 2025-05-26 17:37:33 +0800 | [diff] [blame] | 90 | > |
| 91 | <InputNumber |
| 92 | style={{ width: '100%' }} |
| 93 | min={0} |
| 94 | precision={2} |
| 95 | placeholder="请输入悬赏金额" |
| 96 | disabled={props.readOnly} |
| 97 | /> |
| 98 | </Form.Item> |
| 99 | {/* <Form.Item |
| 100 | name="status" |
| 101 | label="悬赏状态" |
| 102 | > |
| 103 | <Select |
| 104 | placeholder="请选择悬赏状态" |
| 105 | options={statusOptions.map((item: any) => ({ |
| 106 | value: item.dictValue, |
| 107 | label: item.dictLabel, |
| 108 | }))} |
| 109 | /> |
| 110 | </Form.Item> */} |
| 111 | <Form.Item |
| 112 | name="remark" |
| 113 | label="备注" |
| 114 | > |
| 115 | <Input.TextArea rows={2} placeholder="请输入备注" disabled={props.readOnly} /> |
| 116 | </Form.Item> |
| 117 | </Form> |
| 118 | </Modal> |
| 119 | ); |
| 120 | }; |
| 121 | |
| 122 | export default UpdateForm; |