import { json } from "@utils/ajax";
import { GET_SEARCH_RESULT } from '@store/types/diagnosticSearch';


export const getSearchList = (val) => {
    if(val.trim() == ''){
        const data = [];
        return (dispatch) =>  dispatch({
            type: GET_SEARCH_RESULT,
            searchResult: []
        })
    }
   
    return (dispatch, getState) => {
        const state = getState();
        const diagnosticList = state.diagnosticList.diagnosticList
        let noIds = []
        for(let i = 0; i < diagnosticList.length; i++) {
            noIds.push(diagnosticList[i].id)
        }
        json('/retrieval/getTagInfos',{
            type:'7',
            age:state.patInfo.message.patientAge,
            inputStr:val,
            sexType: state.patInfo.message.sex,
            inputIds: noIds
        })
        .then((res)=>{
            const data = res.data.data;
            dispatch({
                type: GET_SEARCH_RESULT,
                searchResult: data
            })
        })
    }
};

