Commit fc315212 authored by 田翔's avatar 田翔

fix: 搜索地址代码优化

parent 954473c5
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "6.0.20", "version": "6.0.21",
"description": "6.0.20 手写签名支持电子签章", "description": "6.0.21 搜索地址代码优化",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
import React, { useState, useEffect, useCallback } from 'react' import React, { useState, useEffect, useCallback } from 'react'
import { Input, message, Popover } from 'antd' import { Input, AutoComplete, message, Popover, Select } from 'antd'
import { searchAdress } from '../../../../apis/process' import { searchAdress } from '../../../../apis/process'
import { debounce, lngmkt, isObject } from '../../../../utils/index' import { debounce, lngmkt, isObject } from '../../../../utils/index'
...@@ -19,19 +19,18 @@ const SearchLocation = (props) => { ...@@ -19,19 +19,18 @@ const SearchLocation = (props) => {
} }
} }
// const doSomeThing = useCallback(debounce(getAdress), [])
const onSearch = async (value) => { const onSearch = async (value) => {
getAdress(value) getAdress(value)
} }
const inputChange = (e) => { const handleSearch = (value) => {
onChange(e.target.value) onChange(value)
} }
const selectChange = (item) => { const onSelect = (value) => {
if (item.location) { let location = options.find(v => v.name === value)?.location
let array = item.location.split(',') if (location) {
let array = location.split(',')
let coord = lngmkt({ lng: array[0], lat: array[1] }) let coord = lngmkt({ lng: array[0], lat: array[1] })
if (coordSync) { if (coordSync) {
let paths = Object.keys(addons.formData) let paths = Object.keys(addons.formData)
...@@ -53,7 +52,7 @@ const SearchLocation = (props) => { ...@@ -53,7 +52,7 @@ const SearchLocation = (props) => {
} }
} }
} }
onChange(item.name) onChange(value)
} }
useEffect(() => { useEffect(() => {
...@@ -62,26 +61,20 @@ const SearchLocation = (props) => { ...@@ -62,26 +61,20 @@ const SearchLocation = (props) => {
} }
}, [presetValue]) }, [presetValue])
const content = (
<div>
{
(options || []).map((v, i) => <p key={i} onClick={() => selectChange(v)}><a>{v.name}</a></p>)
}
</div>
)
return ( return (
<div> <AutoComplete
<Popover content={content} title="地名选择" trigger="hover" placement="topLeft"> style={{ width: '100%' }}
<Input.Search options={(options || []).map(v => ({ label: v.name, value: v.name }))}
disabled={disabled} onSelect={onSelect}
placeholder={disabled ? (placeholder || '') : (placeholder || '请输入地址点击搜索或者回车')} onSearch={handleSearch}
value={value} >
onSearch={onSearch} <Input.Search
onChange={inputChange} value={value}
/> placeholder={disabled ? (placeholder || '') : (placeholder || '请输入地址点击搜索或者回车')}
</Popover> enterButton
</div> onSearch={onSearch}
/>
</AutoComplete>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment