import { json } from "@utils/ajax"; import { GET_SEARCH_RESULT, SET_SEARCH_VALUE } from '@store/types/diagnosticSearch'; export const getSearchResult = (value) =>{ return (dispatch, getState) => { const state = getState(); const url = '/api/icss/retrieval/getTagInfos' const param={ type: 7, age: state.patInfo.message.patientAge, inputStr: value, sexType: state.patInfo.message.sex } if(value === state.diagnosticSearch.searchValue) { return } else { dispatch({ type: SET_SEARCH_VALUE, searchValue: value }) //如果搜索值为空,则直接将搜索结果设为空 if(value === '') { dispatch({ type: GET_SEARCH_RESULT, searchResult: [] }) return } json(url, param).then((data)=>{ const searchRes = data.data.data; const diagList = state.diagnosticList.diagnosticList; let searchResult = []; if(searchRes) { for(let i = 0; i < searchRes.length; i++) { let repeat = false; for (let j = 0; j < diagList.length; j++) { if(searchRes[i].questionId === diagList[j].id) { repeat = true; } } if(!repeat) { searchResult.push(searchRes[i]) } } dispatch({ type: GET_SEARCH_RESULT, searchResult: searchResult }) } else { dispatch({ type: GET_SEARCH_RESULT, searchResult: [] }) } }).catch((e)=>{ console.log(e) }) } } }