import axios from '@utils/ajax';
import { pushAllDataList,didPushParamChange } from '@utils/tools';
import { initHistory } from '@store/actions/historyTemplates';
import Notify from '@commonComp/Notify';
import store from '@store';
import { billing } from '@store/async-actions/pushMessage';

export const initItemList = (item) => {
  let baseList = store.getState();
  let state = baseList.patInfo.message;
  const param = {
      "hospitalId": state.hospitalId,
      "patientId": state.patientId,
      "disName":item&&item.name?item.name : 'dis',
      "disType":item?1:0,
      "current": 1,
      "size": 9999
    }
    return axios.json('/inquiryInfo/hisInquirys',param);
};
export const getHistempDetail = (item) => {
  const param = {
      "inquiryId": item.id
    }
    return (dispatch) => {
        axios.json('/inquiryInfo/getInquiryDetail',param).then((res)=>{
            const data =res.data;
            if(data.code == 0){
                let tmpData = data.data
                pushAllDataList(item.sign,'push',tmpData,'history')       //引用
                if(didPushParamChange()) {
                  dispatch(billing());
                }
            }else{
                Notify.error(data.msg);
            }
        })
    }
};

export function setInitHistory(data){
  return (dispatch) => {
    dispatch(initHistory(data));
  }
}
