| | |
| | | import { history, useAccess, useParams } from '@umijs/max'; |
| | | import { PlusOutlined } from '@ant-design/icons'; |
| | | import { Button, Form, Input, Select, Upload, message } from 'antd'; |
| | | import { Button, Form, Image, Input, Select, Upload, message } from 'antd'; |
| | | import React, { useEffect, useState } from 'react'; |
| | | import RegionCascader from '@/components/RegionCascader'; |
| | | import { getClinicDetail, getProvincialAgentOptions, updateClinic, uploadClinicImage } from './service'; |
| | |
| | | const access = useAccess(); const params = useParams<{ id: string }>(); |
| | | const [form] = Form.useForm<FormValues>(); const [loading, setLoading] = useState(false); |
| | | const [agentOptions, setAgentOptions] = useState<{ label: string; value: number }[]>([]); |
| | | const [avatar, setAvatar] = useState(''); |
| | | const [businessLicenseUrl, setBusinessLicenseUrl] = useState(''); |
| | | const [uploadingAvatar, setUploadingAvatar] = useState(false); |
| | | const [uploadingLicense, setUploadingLicense] = useState(false); |
| | | useEffect(() => { |
| | | if (!access['member:clinic:edit']) { history.replace('/Welcome'); return; } |
| | | getProvincialAgentOptions().then((response) => setAgentOptions((response.data?.list || []).map((item: any) => ({ label: item.agentName, value: item.id })))); |
| | | if (params.id) getClinicDetail(params.id).then((response) => form.setFieldsValue(response.data || {})); |
| | | if (params.id) getClinicDetail(params.id).then((response) => { const data = response.data || {}; form.setFieldsValue(data); setAvatar(data.avatar || ''); setBusinessLicenseUrl(data.businessLicenseUrl || ''); }); |
| | | }, [params.id]); |
| | | const submit = async () => { |
| | | const values = await form.validateFields(); if (!params.id) return; setLoading(true); |
| | |
| | | }; |
| | | return <div className="clinic-edit-page"><div className="clinic-edit-panel"><h2>编辑诊所</h2> |
| | | <Form form={form} labelCol={{ span: 4 }} wrapperCol={{ span: 10 }}> |
| | | <Form.Item shouldUpdate noStyle>{() => <div style={{ marginBottom: 20 }}><div className="clinic-edit-upload" /></div>}</Form.Item> |
| | | <Form.Item name="avatar" label="头像"><Input placeholder="请输入头像地址" /></Form.Item> |
| | | <Form.Item label="头像" className="clinic-edit-upload-item"> |
| | | <Form.Item name="avatar" rules={[{ required: true, message: "请上传头像" }]} hidden><Input /></Form.Item> |
| | | <Upload accept="image/*" showUploadList={false} customRequest={async (options) => { |
| | | setUploadingAvatar(true); |
| | | try { const response = await uploadClinicImage(options.file as File); const url = response.data?.url || response.data; if (!url) throw new Error("upload failed"); setAvatar(url); form.setFieldsValue({ avatar: url }); options.onSuccess?.(response); } catch (error) { message.error("头像上传失败"); options.onError?.(error as Error); } finally { setUploadingAvatar(false); } |
| | | }}> |
| | | <div className="clinic-edit-upload clinic-edit-upload--avatar">{uploadingAvatar ? <span>上传中...</span> : avatar ? <Image src={avatar} width={104} height={104} preview={false} /> : <div><PlusOutlined /><span>上传头像</span></div>}</div> |
| | | </Upload> |
| | | </Form.Item> |
| | | |
| | | <Form.Item name="name" label="诊所名称"><Input maxLength={100} placeholder="请输入诊所名称" /></Form.Item> |
| | | <Form.Item name="loginAccount" label="登录账号"><Input maxLength={50} placeholder="请输入登录账号" /></Form.Item> |
| | | <Form.Item name="regionCodes" label="诊所地址"><RegionCascader placeholder="请选择省/市/区" /></Form.Item> |
| | | <Form.Item name="address" label="详细地址"><Input maxLength={255} placeholder="请输入详细地址" /></Form.Item> |
| | | <Form.Item label="营业执照" shouldUpdate>{() => <Upload accept="image/*" showUploadList={false} beforeUpload={async (file) => { const response = await uploadClinicImage(file); form.setFieldValue("businessLicenseUrl", response.data?.url || response.data); return false; }}><div className="clinic-edit-upload clinic-edit-upload--license">{form.getFieldValue("businessLicenseUrl") ? <img src={form.getFieldValue("businessLicenseUrl")} alt="营业执照" /> : <div><PlusOutlined /><span>上传营业执照</span></div>}</div></Upload>}</Form.Item> |
| | | <Form.Item label="营业执照" className="clinic-edit-upload-item"> |
| | | <Form.Item name="businessLicenseUrl" rules={[{ required: true, message: "请上传营业执照" }]} hidden><Input /></Form.Item> |
| | | <Upload accept="image/*" showUploadList={false} customRequest={async (options) => { |
| | | setUploadingLicense(true); |
| | | try { const response = await uploadClinicImage(options.file as File); const url = response.data?.url || response.data; if (!url) throw new Error("upload failed"); setBusinessLicenseUrl(url); form.setFieldsValue({ businessLicenseUrl: url }); options.onSuccess?.(response); } catch (error) { message.error("营业执照上传失败"); options.onError?.(error as Error); } finally { setUploadingLicense(false); } |
| | | }}> |
| | | <div className="clinic-edit-upload clinic-edit-upload--license">{uploadingLicense ? <span>上传中...</span> : businessLicenseUrl ? <Image src={businessLicenseUrl} width={208} height={128} preview={false} /> : <div><PlusOutlined /><span>上传营业执照</span></div>}</div> |
| | | </Upload> |
| | | </Form.Item> |
| | | <Form.Item name="status" label="状态"><Select options={[{ label: "启用", value: 1 }, { label: "禁用", value: 0 }]} placeholder="请选择状态" /></Form.Item> |
| | | <Form.Item name="agentId" label="所属省区代理"><Select allowClear showSearch optionFilterProp="label" options={agentOptions} placeholder="请选择省区代理" /></Form.Item> |
| | | <Form.Item name="bankName" label="银行名称"><Input maxLength={100} placeholder="请输入银行名称" /></Form.Item> |
| | | <Form.Item name="accountHolder" label="账号名称"><Input maxLength={50} placeholder="请输入账号名称" /></Form.Item> |
| | | <Form.Item name="accountNumber" label="账号"><Input maxLength={30} placeholder="请输入账号" /></Form.Item> |
| | | <Form.Item name="branchName" label="支行名称"><Input maxLength={100} placeholder="请输入支行名称" /></Form.Item> |
| | | <Form.Item name="agentId" label="所属省区代理"><Select allowClear showSearch optionFilterProp="label" options={agentOptions} placeholder="请选择省区代理" /></Form.Item> |
| | | |
| | | <Form.Item wrapperCol={{ offset: 4 }}><Button onClick={() => history.back()}>取消</Button><Button type="primary" loading={loading} onClick={submit} style={{ marginLeft: 8 }}>保存</Button></Form.Item> |
| | | </Form></div></div>; |
| | | }; |
| | | export default ClinicManagePage; |
| | | export default ClinicManagePage; |