|
@@ -5,37 +5,51 @@ import { Select } from 'antd';
|
|
|
import { SearchOutlined } from '@ant-design/icons';
|
|
|
import { useModel } from 'umi';
|
|
|
type mapResType = {
|
|
|
- text: string;
|
|
|
- value: string;
|
|
|
+ id: string;
|
|
|
+ localName: string;
|
|
|
+ [key: string]: any;
|
|
|
};
|
|
|
import { querySpace } from '@/services/ant-design-pro/environment';
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
type SearchInputProps = {
|
|
|
- onSearch: (s: string) => void;
|
|
|
+ callbackSearch: (s: any) => void;
|
|
|
mapList: API.MapInfo[];
|
|
|
};
|
|
|
-const SearchInput: React.FC<SearchInputProps> = ({ onSearch, mapList }) => {
|
|
|
+const SearchInput: React.FC<SearchInputProps> = ({ callbackSearch, mapList }) => {
|
|
|
const [matchData, setMatchData] = useState<mapResType[]>([]);
|
|
|
const [value, setValue] = useState<any>();
|
|
|
- // const { mapList } = useModel('map');
|
|
|
+ const { projectId } = useModel('spaceFunc');
|
|
|
+ const { changeSearchBuildId, changeSearchFloorId } = useModel('buildFloor');
|
|
|
|
|
|
//这是搜索 的下拉列表的显示
|
|
|
const handleSearch = (value: string) => {
|
|
|
//debugger;
|
|
|
if (value) {
|
|
|
- let data: mapResType[] = [];
|
|
|
- mapList.map((item, index) => {
|
|
|
- if ((item.localName || '').indexOf(value) > -1) {
|
|
|
- data.push({
|
|
|
- text: item.localName,
|
|
|
- value: item.localName,
|
|
|
- });
|
|
|
- }
|
|
|
+ // let data: mapResType[] = [];
|
|
|
+ // mapList.map((item, index) => {
|
|
|
+ // if ((item.localName || '').indexOf(value) > -1) {
|
|
|
+ // data.push({
|
|
|
+ // text: item.localName,
|
|
|
+ // value: item.localName,
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ var paramsObj = {
|
|
|
+ criteria: {
|
|
|
+ projectId: projectId,
|
|
|
+ localName: {
|
|
|
+ $like: `%${value}%`,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ querySpace(paramsObj).then((res) => {
|
|
|
+ var resContent = res.content || [];
|
|
|
+ console.log('setMatch', 'data');
|
|
|
+ setMatchData(resContent);
|
|
|
});
|
|
|
- setMatchData(data);
|
|
|
- //console.log('search', data);
|
|
|
} else {
|
|
|
setMatchData([]);
|
|
|
}
|
|
@@ -43,18 +57,28 @@ const SearchInput: React.FC<SearchInputProps> = ({ onSearch, mapList }) => {
|
|
|
|
|
|
//这是搜索的下拉列表的点击
|
|
|
const handleChange = (sel: string) => {
|
|
|
- //debugger;
|
|
|
+ debugger;
|
|
|
setValue(null); //清空输入的值
|
|
|
setMatchData([]); //清空搜索匹配列表
|
|
|
- onSearch(sel);
|
|
|
+ var filterItem = matchData.filter((item) => {
|
|
|
+ return item.id == sel;
|
|
|
+ });
|
|
|
+ var resItem = filterItem[0] || {};
|
|
|
+ callbackSearch(resItem);
|
|
|
+ //改变存储的搜索得到的buildingId floorId
|
|
|
+ changeSearchBuildId(resItem.buildingId);
|
|
|
+ changeSearchFloorId(resItem.floorId);
|
|
|
};
|
|
|
const handelInputKeyDown = (e) => {
|
|
|
// 如果点击回车的操作
|
|
|
//console.log('keydown', matchData);
|
|
|
if (e.code == 'Enter') {
|
|
|
- if (matchData.length == 1) {
|
|
|
- onSearch(matchData[0].text);
|
|
|
- }
|
|
|
+ //if (matchData.length == 1) {
|
|
|
+ var resItem = matchData[0] || {};
|
|
|
+ callbackSearch(resItem);
|
|
|
+ changeSearchBuildId(resItem.buildingId);
|
|
|
+ changeSearchFloorId(resItem.floorId);
|
|
|
+ //}
|
|
|
}
|
|
|
};
|
|
|
return (
|
|
@@ -82,9 +106,10 @@ const SearchInput: React.FC<SearchInputProps> = ({ onSearch, mapList }) => {
|
|
|
// />
|
|
|
// }
|
|
|
>
|
|
|
- {matchData.map(function (item, index) {
|
|
|
- return <Option key={item.value}>{item.text}</Option>;
|
|
|
- })}
|
|
|
+ {matchData.length > 1 &&
|
|
|
+ matchData.map(function (item, index) {
|
|
|
+ return <Option key={item.id}>{item.localName}</Option>;
|
|
|
+ })}
|
|
|
</Select>
|
|
|
</div>
|
|
|
);
|