|  |  | 
 |  |  | import React, { useState, useEffect } from 'react'; | 
 |  |  | import { useCreateContext, useTranslate } from 'react-admin' | 
 |  |  | import { useCreateContext, useTranslate, useRecordContext } from 'react-admin' | 
 |  |  | import { MenuItem, Select, FormControl, InputLabel, Typography } from '@mui/material'; | 
 |  |  | import request from '@/utils/request'; | 
 |  |  | import * as Common from '@/utils/common'; | 
 |  |  | import { useFormContext } from 'react-hook-form'; | 
 |  |  |  | 
 |  |  | const TreeSelectInput = ({ resource, label, source = 'parentId', value, isTranslate = false, ...rest }) => { | 
 |  |  | const TreeSelectInput = ({ resource, required, onChange, label, source = 'parentId', value, isTranslate = false, ...rest }) => { | 
 |  |  |     const translate = useTranslate(); | 
 |  |  |     const { setValue } = useFormContext(); | 
 |  |  |     const form = useFormContext(); | 
 |  |  |     const [filter, setFilter] = React.useState(""); | 
 |  |  |     const [treeData, setTreeData] = React.useState([]); | 
 |  |  |  | 
 |  |  |     const [proxyVal, setProxyVal] = React.useState(''); | 
 |  |  |  | 
 |  |  |     const record = useRecordContext() | 
 |  |  |     const val = value || record?.[source]; | 
 |  |  |  | 
 |  |  |     useEffect(() => { | 
 |  |  |         const http = async (resource) => { | 
 |  |  | 
 |  |  |             }); | 
 |  |  |             if (res?.data?.code === 200) { | 
 |  |  |                 setTreeData(Common.flattenTree(res.data.data)); | 
 |  |  |                 setProxyVal(value); | 
 |  |  |                 setProxyVal(val); | 
 |  |  |             } else { | 
 |  |  |                 notify(res.data.msg); | 
 |  |  |             } | 
 |  |  | 
 |  |  |     const handleChange = (event) => { | 
 |  |  |         const val = event.target.value; | 
 |  |  |         setProxyVal(val); | 
 |  |  |         setValue(source, val, { | 
 |  |  |         form?.setValue(source, val, { | 
 |  |  |             shouldValidate: true, | 
 |  |  |             shouldDirty: true, | 
 |  |  |         }); | 
 |  |  |         onChange(event) | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     return ( | 
 |  |  |         <FormControl fullWidth> | 
 |  |  |         <FormControl fullWidth required={required}> | 
 |  |  |             <InputLabel>{translate(label)}</InputLabel> | 
 |  |  |             <Select | 
 |  |  |                 value={proxyVal || ''} |