
import dictApi from "@/api/dictApi.js";
async function loadDict(name){
    var data = []
    var res = await dictApi.findDict({
        name
    }).catch(err=>{
        console.error(err)
        return data
    })
    if(res&&res.status==200){
        res.detailModelList.forEach(v => {
            data.push({
                text: v.dictValue,
                model: {
                    id: v.dictCode,
                }
            })
        });
    }
    return data
}

async function getOrgInfoList(){
    var data = []
    var res = await safetyAndOpennessApi.getOrgInfoList({
        page: 1,
        size: 999,
        filters: "del=1" 
    }).catch(err=>{
        console.error(err)
        return data
    })
    if(res&&res.status==200){
        res.detailModelList.forEach(v => {
            data.push({
                label: v.name,
                value: v.code
            })
        });
    }
    return data
}

async function getBaseTeamList(){
    var data = []
    var res = await serviceApi.getBaseTeamList({
        page: 1,
        size: 999,
        filters: "del=1" 
        // orgCode
    }).catch(err=>{
        console.error(err)
        return data
    })
    if(res&&res.status==200){
        res.detailModelList.forEach(v => {
            data.push({
                label: v.name,
                value: v.id
            })
        });
    }
    return data
}

async function getSystemDictEntryList(type){
    var data = []
    var res = await serviceApi.getSystemDictEntryList({
        page: 1,
        size: 999,
        filters: "dictCode=" + type
    }).catch(err=>{
        console.error(err)
        return data
    })
    if(res&&res.status==200){
        res.detailModelList.forEach(v => {
            data.push({
                label: v.value,
                value: v.code
            })
        });
    }
    return data
}



export default function(config){
    return new Promise((resolve, reject)=>{
        switch(config.type){
            case 'archiveStatus': ;
            case 'archiveType': ;
            case 'blood': ;
            case 'marriage_status': ;
            case 'national': ;
            case 'serviceType': ;
            case 'feeType': ;
            case 'drugStoreOpenControl': ;

            

            case 'isEffect': ;
            case 'drugStoreStatus': resolve(loadDict(config.type)); return;

            case 'service_item': resolve(getSystemDictEntryList(config.type)); return;
            case 'orgList': resolve(getOrgInfoList()); return;
            case 'baseTeamList': resolve(getBaseTeamList()); return;
        }
    })
}