import axios from '@utils/ajax';
import store from '@store';
import { searchList } from '../actions/assistCheck';
import {  Notify } from '@commonComp';
import { formatFormParmas } from '@utils/tools';

export const getSearchList = (val) => {
    if(val.trim() == ''){
        const data = [];
        return (dispatch) => dispatch(searchList(data,''));
    }
    let baseList = store.getState();
    let sex = baseList.patInfo.message.patientSex;
    return (dispatch) => {
        axios.json('/demo/retrieval/index',{
            "age": formatFormParmas('patientAge',baseList.patInfo.patInfoData),
            "inputStr": val.trim(),
            "sex": formatFormParmas('patientSex',baseList.patInfo.patInfoData),
            "type": '3',
            "hospitalId":baseList.homePage.curHos.hosId
        })
        .then((res)=>{
            if(res.data.code==0){
                const data = res.data.data;let curDate=[];
                let arr = data.pacsNames||[];
                    for (var key in arr) {
                        let obj = {}
                        obj['uniqueName'] = arr[key];
                        obj['detailName'] = arr[key];
                        obj['name'] = arr[key];
                        curDate.push(obj)
                    }
                dispatch(searchList(curDate,val.trim()));
            }else{
                Notify.error(res.data.msg)
            }
        })
    }
};
