import { json } from "@utils/ajax";
import { SET_TREAT } from '@store/types/diagnosticList';
import { SET_DRUG_INFO, SET_TREATMENT, SET_RECOMMEND_BASIC } from '@store/types/treat';
import {getEMRParams} from  '@utils/tools';
const api={
    push:'/api/icss/push/pushInner',
    textPush:'/api/icss/push/pushText'
}

export const getTreatResult = (item) =>{
    return (dispatch, getState) => {
        const state = getState();
        let url = api.push;
        if(+state.typeConfig.confirmType===1){
            url=api.textPush;
        }

        const emrData = getEMRParams();
        // const params = {
        //     "age": emrData.age,
        //     "featureType": "8",
        //     "dis": emrData.dis,
        //     "diseaseId": emrData.diseaeId,
        //     "lis": emrData.lis,
        //     "other": emrData.other,
        //     "pacs": emrData.pacs,
        //     "sex": emrData.sex,
        //     "symptom": emrData.current||emrData.main,
        //     "vital": emrData.vital
        // };
        const diagnosticList = state.diagnosticList.diagnosticList;
        let diag = '';
        if(diagnosticList) {
            for (let i = 0; i < diagnosticList.length; i++ ) {
                if(i ===0 ) {
                    diag = diag + diagnosticList[i].name;
                } else {
                    diag = diag + ',' + diagnosticList[i].name;
                }
                
            }
        }
        const params = {
            "age": emrData.age,
            "featureType": "8",
            "diag": diag,
            "diseaseId":  item.id,
            "lis": emrData.lis,
            "other": emrData.other,
            "pacs": emrData.pacs,
            "sex": emrData.sex,
            "symptom": emrData.current||emrData.main,
            "vital": emrData.vital
        };
        
        json(url, params).then((data) =>{
                let treat;
                if(data.data.data) {
                     treat = data.data.data.treat || {}
                }
                if(treat) {
                    return dispatch({
                        type: SET_TREATMENT,
                        treatment: treat.treatment,
                        generalTreat: treat.commonTreatment,
                        surgeryTreat: treat.surgeryTreatment,
                    })
                }
                
            return
        }).catch((e) =>{
            console.log(e)
        })

        // const treatment = [
        //     {
        //         id:132,
        //         drugsName:"支气管扩张剂",
        //         showInfo:"1",
        //         medicitionsList:[
        //             {
        //                 id:137,
        //                 medicitionName:"多索茶碱",
        //                 rate:"0.94",
        //                 isShow:"1", //1展示，0不展示
        //                 forbidden:"0", //0:正常,1:慎用,2:禁忌
        //                 showInfo: "1",
        //                 selected: false
        //             },
        //             {
        //                 id:138,
        //                 medicitionName:"二羟丙茶碱",
        //                 rate:"0.92",
        //                 isShow:"1",
        //                 forbidden:"1",
        //                 showInfo:"0",
        //                 selected: false
        //             },
        //             {
        //                 id:4,
        //                 medicitionName:"二羟丙茶碱11",
        //                 rate:"0.50",
        //                 isShow:"0",
        //                 forbidden:"2",
        //                 showInfo:false,
        //                 selected: false
        //             }
        //         ]
        //     },
        //     {
        //         id:133,
        //         drugsName:"抗生素类(喹诺酮类)",
        //         showInfo: '0',
        //         medicitionsList:[
        //             {
        //                 id:139,
        //                 medicitionName:"左氧氟沙星",
        //                 rate:"0.50",
        //                 isShow:"1", //1展示，0不展示
        //                 forbidden:"0",
        //                 showInfo:'0',
        //                 selected: false
        //             },
        //             {
        //                 id:140,
        //                 medicitionName:"莫西沙星",
        //                 rate:"0.82",
        //                 isShow:"0",
        //                 forbidden:"2",
        //                 showInfo:"0",
        //                 selected: false
        //             }
        //         ]
        //     }
        // ];
        // const generalTreat = '<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 25px; padding: 10px; border: 0px !important;\">风湿性心脏病通常侵犯二尖瓣，其次是主动脉瓣。风湿性主动脉瓣关闭不全也常合并二尖瓣病变，临床称之为联合瓣膜病（combined valvular disease）。梅毒性主动脉炎可发展为梅毒性主动脉关闭不全或主动脉瘤。</p><p style=\"text-align: right;\">来源&nbsp;&nbsp;:&nbsp;&nbsp;中华眼科学:全3册（下）</p><p><br/></p>';
        // const surgeryTreat = '<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 25px; padding: 10px; border: 0px !important;\">风湿性心脏病通常侵犯二尖瓣，其次是主动脉瓣。风湿性主动脉瓣关闭不全也常合并二尖瓣病变，临床称之为联合瓣膜病（combined valvular disease）。梅毒性主动脉炎可发展为梅毒性主动脉关闭不全或主动脉瘤。</p><p style=\"text-align: right;\">来源&nbsp;&nbsp;:&nbsp;&nbsp;中华眼科学:全3册（下）</p><p><br/></p>';
    
        // return dispatch({
        //     type: SET_TREATMENT,
        //     treatment: treatment,
        //     generalTreat: generalTreat,
        //     surgeryTreat: surgeryTreat,
        // })
    }
    
} 
export const getInstroduce = (item)=>{
    // const instroduce = '<p>药品说明1</p><p>药品说明2</p><p>药品说明3</p>'

    return (dispatch, getState) =>{
        const url = '/api/icss/introduceInfo/getByQuestionId';
        const params = {
            questionId: item.id,
            type: 8,
            position: 5
        }
        json(url, params)
        .then((data)=>{
                if(data.data.data) {
                    dispatch({
                        type: SET_DRUG_INFO,
                        instroduce: data.data.data.introduceDetailList,
                        name: item.medicitionName
                    })
                } else {
                    dispatch({
                        type: SET_DRUG_INFO,
                        instroduce: [],
                        name: item.medicitionName
                    })
                }
                
        }).catch((e) => {
            console.log(e)
        })

    }

}

//其他推荐推荐依据不用展示
// export const getRecommendBasic = (item)=>{
    
//     return (dispatch, getState) =>{
//         const url = '/api/icss/introduceInfo/getByQuestionId';
//         const params = {
//             questionId: item.id,
//             type: 9,
//             position: 2
//         }
//         json(url, params)
//         .then((data)=>{
//             if (data.status === 200) {
//                 if(data.data.data) {
//                     dispatch({
//                         type: SET_RECOMMEND_BASIC,
//                         recommendBasic: data.data.data.introduceDetailList,
//                     })
//                 } else {
//                     dispatch({
//                         type: SET_RECOMMEND_BASIC,
//                         recommendBasic: [],
//                     })
//                 }
                
//             }
//         }).catch((e) => {
//             console.log(e)
//         })

//     }
// }