diagnosticSearch.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { json } from "@utils/ajax";
  2. import { GET_SEARCH_RESULT, SET_SEARCH_VALUE } from '@store/types/diagnosticSearch';
  3. export const getSearchResult = (value) =>{
  4. return (dispatch, getState) => {
  5. const state = getState();
  6. const url = '/api/icss/retrieval/getTagInfos'
  7. const param={
  8. type: 7,
  9. age: state.patInfo.message.patientAge,
  10. inputStr: value,
  11. sexType: state.patInfo.message.sex
  12. }
  13. if(value === state.diagnosticSearch.searchValue) {
  14. return
  15. } else {
  16. dispatch({
  17. type: SET_SEARCH_VALUE,
  18. searchValue: value
  19. })
  20. //如果搜索值为空,则直接将搜索结果设为空
  21. if(value === '') {
  22. dispatch({
  23. type: GET_SEARCH_RESULT,
  24. searchResult: []
  25. })
  26. return
  27. }
  28. json(url, param).then((data)=>{
  29. const searchRes = data.data.data;
  30. const diagList = state.diagnosticList.diagnosticList;
  31. let searchResult = [];
  32. if(searchRes) {
  33. for(let i = 0; i < searchRes.length; i++) {
  34. let repeat = false;
  35. for (let j = 0; j < diagList.length; j++) {
  36. if(searchRes[i].questionId === diagList[j].id) {
  37. repeat = true;
  38. }
  39. }
  40. if(!repeat) {
  41. searchResult.push(searchRes[i])
  42. }
  43. }
  44. dispatch({
  45. type: GET_SEARCH_RESULT,
  46. searchResult: searchResult
  47. })
  48. } else {
  49. dispatch({
  50. type: GET_SEARCH_RESULT,
  51. searchResult: []
  52. })
  53. }
  54. }).catch((e)=>{
  55. console.log(e)
  56. })
  57. }
  58. }
  59. }