import {json} from '@utils/ajax';
import store from '@store';
import {getUrlArgObject} from '@utils/tools';
import { GET_PREC_LIST,SET_PREC_SHOW } from "../types/preIcss";
import config from '@config/index';
import {Notify} from '@commonComp';

export const getPreMsg = (sign) => {
    let baseList = store.getState().patInfo.message;
    json('/api/prec/inquiryInfo/hisInquirysForIcss', {
        "isHaveDetail":1,
        "hospitalCode": baseList.hospitalCode,
        "dayLimit":config.preIcss.deadline===-1?undefined:config.preIcss.deadline,
        "patientIdNo": baseList.patientIdentityNum?baseList.patientIdentityNum:baseList.patientIdNo,
        "patientName": baseList.patientName
    },true).then((res) => {
        const data = res.data;
        if (data.code == 0) {
            let result = data.data;
            if(result.length > 0){
                !sign&&store.dispatch({type:SET_PREC_SHOW})
            }else{
                sign&&store.dispatch({type:SET_PREC_SHOW})
                !sign&&Notify.info('暂无预问诊信息');
            }
            store.dispatch({type:GET_PREC_LIST,preData:result});
        } else {
            // console.log(res)
        }
    })
}

export const tellPred = () => {
    let baseData = store.getState();
    let baseList = baseData.homePage.item;
    let idcon = baseData.patInfo.message;
    const inCode = config.preIcss.recordIdVal===-1?getUrlArgObject("recordId"):config.preIcss.recordIdVal;
    json('/api/prec/inquiryInfo/inquiryQuoteForIcss', {
        "hospitalCode": idcon.hospitalCode,
        "hospitalId": idcon.hospitalId,
        "hospitalName":idcon.hospitalName,
        "inquiryCode":idcon.recordId,
        "patientCode": idcon.patientCode,
        "patientIdentityNum":idcon.patientIdentityNum||null,
        "doctorCode":idcon.doctorCode,
        "doctorId": idcon.doctorId,
        "doctorName":idcon.doctorName,
        "hospitalDeptCode":idcon.hospitalDeptCode,
        "hospitalDeptId": idcon.hospitalDeptId,
        "hospitalDeptName":idcon.hospitalDeptName,
        "inquiryId": baseList.id,
        "patientId": idcon.patientId,
        "patientIdNo":idcon.patientIdNo,
        "patientName":idcon.patientName,
        "patientPhone":idcon.patientPhone||null,
        "patientSex": idcon.patientSex=='男'?1:idcon.patientSex=='女'?2:3,
        "patientBirthday": idcon.birthday
    },true).then((res) => {
        getPreMsg(1)
    })
}
