|
|
@@ -0,0 +1,109 @@
|
|
|
+import { useModal } from '@/components/Modal'
|
|
|
+import consts from '@/consts'
|
|
|
+import { queryClient } from '@/services/customer'
|
|
|
+import { useDebounceFn } from 'ahooks'
|
|
|
+import { Input, Alert, Popover } from 'antd'
|
|
|
+import ClientDetail from '../ClientDetail'
|
|
|
+import { useState } from 'react'
|
|
|
+import { validateEnum } from '@/pages/Customer/Company/components/AddCompany/CompanyFormItem'
|
|
|
+
|
|
|
+const TelephoneFormItem = ({ value, onChange, validateFn }) => {
|
|
|
+ const { toggleDrawer, setDrawerProps } = useModal()
|
|
|
+ const [state, setState] = useState({
|
|
|
+ inputVal: value,
|
|
|
+ visible: false,
|
|
|
+ list: null
|
|
|
+ })
|
|
|
+ const triggerChange = changedValue => {
|
|
|
+ onChange?.(changedValue)
|
|
|
+ }
|
|
|
+
|
|
|
+ const queryList = async search => {
|
|
|
+ if (!search) return
|
|
|
+ const { code = -1, data } = await queryClient({ current: 1, pageSize: 20, search })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ const { client = [] } = data
|
|
|
+ setState({ ...state, list: client })
|
|
|
+ if (client?.length) {
|
|
|
+ validateFn(validateEnum.Warning)
|
|
|
+ } else {
|
|
|
+ validateFn(validateEnum.Success)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const { run: handleQueryList } = useDebounceFn(queryList, { wait: 600 })
|
|
|
+
|
|
|
+ const handleOnInputChange = async e => {
|
|
|
+ const val = e.target.value || ''
|
|
|
+ if (!val) {
|
|
|
+ setState({ ...state, inputVal: val, list: null, visible: false })
|
|
|
+ validateFn(validateEnum.Error)
|
|
|
+ } else {
|
|
|
+ setState({ ...state, inputVal: val })
|
|
|
+ validateFn(validateEnum.Validating)
|
|
|
+ handleQueryList(val)
|
|
|
+ }
|
|
|
+ triggerChange(val)
|
|
|
+ }
|
|
|
+
|
|
|
+ const showClientDrawer = id => {
|
|
|
+ setDrawerProps({
|
|
|
+ zIndex: 1004,
|
|
|
+ closable: true,
|
|
|
+ onClose: () => toggleDrawer(),
|
|
|
+ bodyStyle: {
|
|
|
+ height: '100vh'
|
|
|
+ },
|
|
|
+ children: <ClientDetail dataId={id} />
|
|
|
+ })
|
|
|
+ toggleDrawer(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ const { visible, list, inputVal } = state
|
|
|
+ return (
|
|
|
+ <Popover
|
|
|
+ zIndex={1003}
|
|
|
+ placement="bottom"
|
|
|
+ visible={list && list.length && visible}
|
|
|
+ onVisibleChange={e => setState({ ...state, visible: e })}
|
|
|
+ title={
|
|
|
+ <Alert
|
|
|
+ message="已存在相同手机号码,请确认是否继续添加"
|
|
|
+ type="warning"
|
|
|
+ style={{ padding: '5px', margin: '10px 0' }}
|
|
|
+ />
|
|
|
+ }
|
|
|
+ trigger="click"
|
|
|
+ content={
|
|
|
+ <ul className="list-none">
|
|
|
+ {list?.map(item => {
|
|
|
+ return (
|
|
|
+ <p key={item.id}>
|
|
|
+ <span
|
|
|
+ className="text-primary cursor-pointer hover:text-hex-967bbd"
|
|
|
+ onClick={() => showClientDrawer(item.id)}
|
|
|
+ >
|
|
|
+ {item.clientName}
|
|
|
+ </span>
|
|
|
+ <span className="mx-1">/</span>
|
|
|
+ <span>{item.districtName?.replaceAll(' / ', ',')}</span>
|
|
|
+ </p>
|
|
|
+ )
|
|
|
+ })}
|
|
|
+ </ul>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ type="text"
|
|
|
+ autoComplete="false"
|
|
|
+ value={inputVal}
|
|
|
+ placeholder="请输入手机号码"
|
|
|
+ onChange={handleOnInputChange}
|
|
|
+ className="company-input"
|
|
|
+ />
|
|
|
+ </Popover>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default TelephoneFormItem
|