import { http } from '@/common/utils/request'
import { Types } from './select'

// 获取下拉数据通用接口 
export const get_selectOptions = (type:string, propsParams:any={}, system:string='sec', Refresh=false) => {
    
    if(Types[type]){// 获取内部类型，如内部没找到类型，则找通用类型；
        let params = {
            ...propsParams,
            ...Types[type].params,
        };
        if(Refresh) Object.assign(params, {'[refresh_cache]':'Y'}) // 强制刷新
        return get_options_other(params, Types[type].url)
    }else{
        let sys = system;
        if(type.indexOf('.')>0){
            sys = type.split('.')[0]
            type = type.split('.')[1]
        }
        let params = {
            "[ProcedureName]": `pw_${sys}_common_query`,
            type,
            ...propsParams,
        };
        if(Refresh) Object.assign(params, {'[refresh_cache]':'Y'}) // 强制刷新
        return get_options_sys(params, sys)
    }
}

export const get_options_sys = async (data:any ,sys:string) => 
    http.get(`/${sys}/storeds`, data)

export const get_options_other = async (data:any ,url:string) => 
    http.get(url, data)


